iOS: show unescaped filename in email

Displayed name in the email was using the escaped filename rather than the filename passed as the name parameter.
This commit is contained in:
chrisgarrity 2016-09-19 17:10:10 -04:00
parent e035b0f86e
commit 72b807726b
2 changed files with 28 additions and 29 deletions

View file

@ -201,13 +201,13 @@ NSMutableDictionary *mediastrings;
// Receive a .sjr file from inside the app. Send using native UI - Airdrop or Email // Receive a .sjr file from inside the app. Send using native UI - Airdrop or Email
+ (NSString*) sendSjrUsingShareDialog:(NSString *)fullname :(NSString*)emailSubject :(NSString*)emailBody :(int)shareType :(NSString*)contents { + (NSString*) sendSjrUsingShareDialog:(NSString *)fullname :(NSString*)emailSubject :(NSString*)emailBody :(int)shareType :(NSString*)contents {
NSString* extensionFormat = @"%@.sjr"; NSString* extensionFormat = @"%@.sjr";
#if PBS #if PBS
extensionFormat = @"%@.psjr"; extensionFormat = @"%@.psjr";
#endif #endif
NSString *filename = [NSString stringWithFormat:extensionFormat, fullname]; NSString *filename = [NSString stringWithFormat:extensionFormat, fullname];
NSURL *url = [self getDocumentPath:filename]; NSURL *url = [self getDocumentPath:filename];
NSData *plaindata = [IO decodeBase64:contents]; NSData *plaindata = [IO decodeBase64:contents];
@ -215,7 +215,7 @@ NSMutableDictionary *mediastrings;
if (ok) { if (ok) {
if (shareType == 0) { if (shareType == 0) {
[HTML showShareEmail:url withName:fullname withSubject:emailSubject withBody:emailBody]; [HTML showShareEmail:url withName:filename withSubject:emailSubject withBody:emailBody];
} else { } else {
[HTML showShareAirdrop:url]; [HTML showShareAirdrop:url];
} }
@ -247,7 +247,7 @@ NSMutableDictionary *mediastrings;
+ (NSString*)encodeBase64:(NSData*)theData { + (NSString*)encodeBase64:(NSData*)theData {
const uint8_t* input = (const uint8_t*)[theData bytes]; const uint8_t* input = (const uint8_t*)[theData bytes];
NSInteger length = [theData length]; NSInteger length = [theData length];
static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4]; NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
uint8_t* output = (uint8_t*)data.mutableBytes; uint8_t* output = (uint8_t*)data.mutableBytes;
NSInteger i; NSInteger i;
@ -269,7 +269,7 @@ NSMutableDictionary *mediastrings;
+ (NSData *) decodeBase64:(NSString *) string { + (NSData *) decodeBase64:(NSString *) string {
NSMutableData *mutableData = nil; NSMutableData *mutableData = nil;
if( string ) { if( string ) {
unsigned long ixtext = 0; unsigned long ixtext = 0;
unsigned long lentext = 0; unsigned long lentext = 0;
@ -280,18 +280,18 @@ NSMutableDictionary *mediastrings;
BOOL flendtext = NO; BOOL flendtext = NO;
NSData *base64Data = nil; NSData *base64Data = nil;
const unsigned char *base64Bytes = nil; const unsigned char *base64Bytes = nil;
// Convert the string to ASCII data. // Convert the string to ASCII data.
base64Data = [string dataUsingEncoding:NSASCIIStringEncoding]; base64Data = [string dataUsingEncoding:NSASCIIStringEncoding];
base64Bytes = [base64Data bytes]; base64Bytes = [base64Data bytes];
mutableData = [NSMutableData dataWithCapacity:[base64Data length]]; mutableData = [NSMutableData dataWithCapacity:[base64Data length]];
lentext = [base64Data length]; lentext = [base64Data length];
while( YES ) { while( YES ) {
if( ixtext >= lentext ) break; if( ixtext >= lentext ) break;
ch = base64Bytes[ixtext++]; ch = base64Bytes[ixtext++];
flignore = NO; flignore = NO;
if( ( ch >= 'A' ) && ( ch <= 'Z' ) ) ch = ch - 'A'; if( ( ch >= 'A' ) && ( ch <= 'Z' ) ) ch = ch - 'A';
else if( ( ch >= 'a' ) && ( ch <= 'z' ) ) ch = ch - 'a' + 26; else if( ( ch >= 'a' ) && ( ch <= 'z' ) ) ch = ch - 'a' + 26;
else if( ( ch >= '0' ) && ( ch <= '9' ) ) ch = ch - '0' + 52; else if( ( ch >= '0' ) && ( ch <= '9' ) ) ch = ch - '0' + 52;
@ -299,11 +299,11 @@ NSMutableDictionary *mediastrings;
else if( ch == '=' ) flendtext = YES; else if( ch == '=' ) flendtext = YES;
else if( ch == '/' ) ch = 63; else if( ch == '/' ) ch = 63;
else flignore = YES; else flignore = YES;
if( ! flignore ) { if( ! flignore ) {
short ctcharsinbuf = 3; short ctcharsinbuf = 3;
BOOL flbreak = NO; BOOL flbreak = NO;
if( flendtext ) { if( flendtext ) {
if( ! ixinbuf ) break; if( ! ixinbuf ) break;
if( ( ixinbuf == 1 ) || ( ixinbuf == 2 ) ) ctcharsinbuf = 1; if( ( ixinbuf == 1 ) || ( ixinbuf == 2 ) ) ctcharsinbuf = 1;
@ -311,26 +311,25 @@ NSMutableDictionary *mediastrings;
ixinbuf = 3; ixinbuf = 3;
flbreak = YES; flbreak = YES;
} }
inbuf [ixinbuf++] = ch; inbuf [ixinbuf++] = ch;
if( ixinbuf == 4 ) { if( ixinbuf == 4 ) {
ixinbuf = 0; ixinbuf = 0;
outbuf [0] = ( inbuf[0] << 2 ) | ( ( inbuf[1] & 0x30) >> 4 ); outbuf [0] = ( inbuf[0] << 2 ) | ( ( inbuf[1] & 0x30) >> 4 );
outbuf [1] = ( ( inbuf[1] & 0x0F ) << 4 ) | ( ( inbuf[2] & 0x3C ) >> 2 ); outbuf [1] = ( ( inbuf[1] & 0x0F ) << 4 ) | ( ( inbuf[2] & 0x3C ) >> 2 );
outbuf [2] = ( ( inbuf[2] & 0x03 ) << 6 ) | ( inbuf[3] & 0x3F ); outbuf [2] = ( ( inbuf[2] & 0x03 ) << 6 ) | ( inbuf[3] & 0x3F );
for( i = 0; i < ctcharsinbuf; i++ ) for( i = 0; i < ctcharsinbuf; i++ )
[mutableData appendBytes:&outbuf[i] length:1]; [mutableData appendBytes:&outbuf[i] length:1];
} }
if( flbreak ) break; if( flbreak ) break;
} }
} }
} }
return [mutableData copy]; return [mutableData copy];
} }
@end @end

View file

@ -118,7 +118,7 @@ JSContext *js;
js = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"]; js = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
js[@"tablet"] = self; js[@"tablet"] = self;
[self disableWebViewLongPressGestures:webView]; [self disableWebViewLongPressGestures:webView];
NSString *debugChoice =[[NSUserDefaults standardUserDefaults] stringForKey:@"debugstate"]; NSString *debugChoice =[[NSUserDefaults standardUserDefaults] stringForKey:@"debugstate"];
// Patch through app "advanced"->debug to allow users to display long-form errors // Patch through app "advanced"->debug to allow users to display long-form errors
@ -129,12 +129,12 @@ JSContext *js;
NSURL* screenName = webView.request.URL.filePathURL; NSURL* screenName = webView.request.URL.filePathURL;
NSString* screenString =[screenName absoluteString]; NSString* screenString =[screenName absoluteString];
NSArray<NSString*>* parts = [screenString componentsSeparatedByString:@"/"]; NSArray<NSString*>* parts = [screenString componentsSeparatedByString:@"/"];
// Track an Analytics pageview // Track an Analytics pageview
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker]; id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:[parts lastObject]]; [tracker set:kGAIScreenName value:[parts lastObject]];
[tracker send:[[GAIDictionaryBuilder createScreenView] build]]; [tracker send:[[GAIDictionaryBuilder createScreenView] build]];
} }
// Disables iOS 9 webview touch tooltip by disabling the long-press gesture recognizer in subviews // Disables iOS 9 webview touch tooltip by disabling the long-press gesture recognizer in subviews
@ -328,23 +328,23 @@ JSContext *js;
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init]; MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
mailComposeViewController.mailComposeDelegate = self; mailComposeViewController.mailComposeDelegate = self;
NSString* filename = [[projectURL absoluteString] lastPathComponent]; NSString* filename = name;
[mailComposeViewController setSubject: subject]; [mailComposeViewController setSubject: subject];
[mailComposeViewController setMessageBody:body isHTML:YES]; [mailComposeViewController setMessageBody:body isHTML:YES];
NSData *projectData = [NSData dataWithContentsOfURL:projectURL]; NSData *projectData = [NSData dataWithContentsOfURL:projectURL];
NSString* mimeType = @"application/x-scratchjr-project"; NSString* mimeType = @"application/x-scratchjr-project";
#if PBS #if PBS
mimeType = @"application/x-pbskids-scratchjr-project"; mimeType = @"application/x-pbskids-scratchjr-project";
#endif #endif
// Check to ensure modal is not nil. This can occur when the user does not have a mail account configured on their device // Check to ensure modal is not nil. This can occur when the user does not have a mail account configured on their device
if (mailComposeViewController == nil) return; if (mailComposeViewController == nil) return;
[mailComposeViewController addAttachmentData:projectData mimeType:mimeType fileName:filename]; [mailComposeViewController addAttachmentData:projectData mimeType:mimeType fileName:filename];
[self presentViewController:mailComposeViewController animated:YES completion:nil]; [self presentViewController:mailComposeViewController animated:YES completion:nil];
}); });
@ -374,4 +374,4 @@ JSContext *js;
} }
@end @end