diff --git a/SoObjects/Mailer/SOGoMailObject+Draft.h b/SoObjects/Mailer/SOGoMailObject+Draft.h index c4054fa1d..1a106a2c0 100644 --- a/SoObjects/Mailer/SOGoMailObject+Draft.h +++ b/SoObjects/Mailer/SOGoMailObject+Draft.h @@ -28,7 +28,6 @@ @interface SOGoMailObject (SOGoDraftObjectExtensions) - (NSString *) contentForEditing; -- (NSArray *) fetchFileAttachmentKeys; - (NSString *) subjectForReply; - (NSString *) contentForReply; diff --git a/SoObjects/Mailer/SOGoMailObject+Draft.m b/SoObjects/Mailer/SOGoMailObject+Draft.m index 4b61e2b01..4d536b015 100644 --- a/SoObjects/Mailer/SOGoMailObject+Draft.m +++ b/SoObjects/Mailer/SOGoMailObject+Draft.m @@ -23,7 +23,6 @@ #import #import #import -#import #import #import @@ -35,7 +34,6 @@ #import #import -#import "NSDictionary+Mail.h" #import "NSString+Mail.h" #import "SOGoMailForward.h" #import "SOGoMailObject+Draft.h" @@ -272,108 +270,4 @@ return [[page generateResponse] contentAsString]; } -// -// -// -- (void) _fetchFileAttachmentKey: (NSDictionary *) part - intoArray: (NSMutableArray *) keys - withPath: (NSString *) path - andPrefix: (NSString *) prefix -{ - NSString *filename, *mimeType; - NSDictionary *currentFile; - - filename = [part filename]; - - mimeType = [NSString stringWithFormat: @"%@/%@", - [part objectForKey: @"type"], - [part objectForKey: @"subtype"]]; - - if (!filename) - // We might end up here because of MUA that actually strips the - // Content-Disposition (and thus, the filename) when mails containing - // attachments have been forwarded. Thunderbird (2.x) does just that - // when forwarding mails with images attached to them (using cid:...). - if ([mimeType hasPrefix: @"application/"] || - [mimeType hasPrefix: @"audio/"] || - [mimeType hasPrefix: @"image/"] || - [mimeType hasPrefix: @"video/"]) - filename = [NSString stringWithFormat: @"unknown_%@", path]; - - if (filename) - { - currentFile = [NSDictionary dictionaryWithObjectsAndKeys: - filename, @"filename", - [mimeType lowercaseString], @"mimetype", - path, @"path", - [part objectForKey: @"encoding"], @"encoding", - [part objectForKey:@ "size"], @"size", - [NSString stringWithFormat: @"%@/%@", prefix, [filename stringByEscapingURL]], @"url", - nil]; - [keys addObject: currentFile]; - } -} - -// -// -// -- (void) _fetchFileAttachmentKeysInPart: (NSDictionary *) part - intoArray: (NSMutableArray *) keys - withPath: (NSString *) path - andPrefix: (NSString *) prefix -{ - NSMutableDictionary *currentPart; - NSString *newPath; - NSArray *subparts; - NSString *type; - NSUInteger i; - - type = [[part objectForKey: @"type"] lowercaseString]; - if ([type isEqualToString: @"multipart"]) - { - subparts = [part objectForKey: @"parts"]; - for (i = 1; i <= [subparts count]; i++) - { - currentPart = [subparts objectAtIndex: i-1]; - if (path) - newPath = [NSString stringWithFormat: @"%@.%d", path, i]; - else - newPath = [NSString stringWithFormat: @"%d", i]; - [self _fetchFileAttachmentKeysInPart: currentPart - intoArray: keys - withPath: newPath - andPrefix: [NSString stringWithFormat: @"%@/%i", prefix, i]]; - } - } - else - { - if (!path) - path = @"1"; - [self _fetchFileAttachmentKey: part - intoArray: keys - withPath: path - andPrefix: prefix]; - } -} - -// -// -// -#warning we might need to handle parts with a "name" attribute -- (NSArray *) fetchFileAttachmentKeys -{ - NSString *prefix; - NSMutableArray *keys; - - prefix = [[self soURL] absoluteString]; - if ([prefix hasSuffix: @"/"]) - prefix = [prefix substringToIndex: [prefix length] - 1]; - - keys = [NSMutableArray array]; - [self _fetchFileAttachmentKeysInPart: [self bodyStructure] - intoArray: keys withPath: nil andPrefix: prefix]; - - return keys; -} - @end diff --git a/SoObjects/Mailer/SOGoMailObject.h b/SoObjects/Mailer/SOGoMailObject.h index cc56324d7..182efeea0 100644 --- a/SoObjects/Mailer/SOGoMailObject.h +++ b/SoObjects/Mailer/SOGoMailObject.h @@ -102,7 +102,9 @@ NSArray *SOGoMailCoreInfoKeys; - (NSDictionary *) fetchPlainTextParts; - (NSDictionary *) fetchPlainTextStrings:(NSArray *)_fetchKeys; -- (NSDictionary *) fetchAttachmentIds; +- (BOOL) hasAttachment; +- (NSDictionary *) fetchFileAttachmentIds; +- (NSArray *) fetchFileAttachmentKeys; /* flags */ diff --git a/SoObjects/Mailer/SOGoMailObject.m b/SoObjects/Mailer/SOGoMailObject.m index 9a73eb92b..aa808d196 100644 --- a/SoObjects/Mailer/SOGoMailObject.m +++ b/SoObjects/Mailer/SOGoMailObject.m @@ -52,6 +52,7 @@ #import "NSString+Mail.h" #import "NSData+Mail.h" +#import "NSDictionary+Mail.h" #import "SOGoMailFolder.h" #import "SOGoMailAccount.h" #import "SOGoMailAccounts.h" @@ -705,9 +706,9 @@ static BOOL debugSoParts = NO; return urlToPart; } -- (void) _feedAttachmentIds: (NSMutableDictionary *) attachmentIds - withInfos: (NSDictionary *) infos - andPrefix: (NSString *) prefix +- (void) _feedFileAttachmentIds: (NSMutableDictionary *) attachmentIds + withInfos: (NSDictionary *) infos + andPrefix: (NSString *) prefix { NSArray *parts; NSDictionary *currentPart; @@ -727,14 +728,14 @@ static BOOL debugSoParts = NO; for (count = 0; count < max; count++) { currentPart = [parts objectAtIndex: count]; - [self _feedAttachmentIds: attachmentIds - withInfos: currentPart - andPrefix: [NSString stringWithFormat: @"%@/%d", - prefix, count + 1]]; + [self _feedFileAttachmentIds: attachmentIds + withInfos: currentPart + andPrefix: [NSString stringWithFormat: @"%@/%d", + prefix, count + 1]]; } } -- (NSDictionary *) fetchAttachmentIds +- (NSDictionary *) fetchFileAttachmentIds { NSMutableDictionary *attachmentIds; NSString *prefix; @@ -745,13 +746,118 @@ static BOOL debugSoParts = NO; prefix = [[self soURL] absoluteString]; if ([prefix hasSuffix: @"/"]) prefix = [prefix substringToIndex: [prefix length] - 1]; - [self _feedAttachmentIds: attachmentIds + [self _feedFileAttachmentIds: attachmentIds withInfos: [coreInfos objectForKey: @"bodystructure"] andPrefix: prefix]; return attachmentIds; } +// +// +// +- (void) _fetchFileAttachmentKey: (NSDictionary *) part + intoArray: (NSMutableArray *) keys + withPath: (NSString *) path + andPrefix: (NSString *) prefix +{ + NSString *filename, *mimeType; + NSDictionary *currentFile; + + filename = [part filename]; + + mimeType = [NSString stringWithFormat: @"%@/%@", + [part objectForKey: @"type"], + [part objectForKey: @"subtype"]]; + + if (!filename) + // We might end up here because of MUA that actually strips the + // Content-Disposition (and thus, the filename) when mails containing + // attachments have been forwarded. Thunderbird (2.x) does just that + // when forwarding mails with images attached to them (using cid:...). + if ([mimeType hasPrefix: @"application/"] || + [mimeType hasPrefix: @"audio/"] || + [mimeType hasPrefix: @"image/"] || + [mimeType hasPrefix: @"video/"]) + filename = [NSString stringWithFormat: @"unknown_%@", path]; + + if (filename) + { + currentFile = [NSDictionary dictionaryWithObjectsAndKeys: + filename, @"filename", + [mimeType lowercaseString], @"mimetype", + path, @"path", + [part objectForKey: @"encoding"], @"encoding", + [part objectForKey:@ "size"], @"size", + [NSString stringWithFormat: @"%@/%@", prefix, [filename stringByEscapingURL]], @"url", + [NSString stringWithFormat: @"%@/asAttachment/%@", prefix, [filename stringByEscapingURL]], @"urlAsAttachment", + nil]; + [keys addObject: currentFile]; + } +} + +// +// +// +- (void) _fetchFileAttachmentKeysInPart: (NSDictionary *) part + intoArray: (NSMutableArray *) keys + withPath: (NSString *) path + andPrefix: (NSString *) prefix +{ + NSMutableDictionary *currentPart; + NSString *newPath; + NSArray *subparts; + NSString *type; + NSUInteger i; + + type = [[part objectForKey: @"type"] lowercaseString]; + if ([type isEqualToString: @"multipart"]) + { + subparts = [part objectForKey: @"parts"]; + for (i = 1; i <= [subparts count]; i++) + { + currentPart = [subparts objectAtIndex: i-1]; + if (path) + newPath = [NSString stringWithFormat: @"%@.%d", path, i]; + else + newPath = [NSString stringWithFormat: @"%d", i]; + [self _fetchFileAttachmentKeysInPart: currentPart + intoArray: keys + withPath: newPath + andPrefix: [NSString stringWithFormat: @"%@/%i", prefix, i]]; + } + } + else + { + if (!path) + path = @"1"; + [self _fetchFileAttachmentKey: part + intoArray: keys + withPath: path + andPrefix: prefix]; + } +} + +// +// +// +#warning we might need to handle parts with a "name" attribute +- (NSArray *) fetchFileAttachmentKeys +{ + NSString *prefix; + NSMutableArray *keys; + + prefix = [[self soURL] absoluteString]; + if ([prefix hasSuffix: @"/"]) + prefix = [prefix substringToIndex: [prefix length] - 1]; + + keys = [NSMutableArray array]; + [self _fetchFileAttachmentKeysInPart: [self bodyStructure] + intoArray: keys withPath: nil andPrefix: prefix]; + + return keys; +} + /* convert parts to strings */ - (NSString *) stringForData: (NSData *) _data partInfo: (NSDictionary *) _info @@ -1353,7 +1459,7 @@ static BOOL debugSoParts = NO; - (BOOL) hasAttachment { - return ([[self fetchAttachmentIds] count] > 0); + return ([[self fetchFileAttachmentKeys] count] > 0); } - (BOOL) isNewMail diff --git a/UI/MailPartViewers/UIxMailPartHTMLViewer.m b/UI/MailPartViewers/UIxMailPartHTMLViewer.m index e60f97d0f..e4623a006 100644 --- a/UI/MailPartViewers/UIxMailPartHTMLViewer.m +++ b/UI/MailPartViewers/UIxMailPartHTMLViewer.m @@ -839,7 +839,7 @@ static NSData* _sanitizeContent(NSData *theData) createXMLReaderForMimeType: @"text/html"]; handler = [_UIxHTMLMailContentHandler new]; - [handler setAttachmentIds: [mail fetchAttachmentIds]]; + [handler setAttachmentIds: [mail fetchFileAttachmentIds]]; // We check if we got an unsupported charset. If so // we convert everything to UTF-16{LE,BE} so it passes @@ -947,7 +947,7 @@ static NSData* _sanitizeContent(NSData *theData) encoding = @"us-ascii"; handler = [_UIxHTMLMailContentHandler new]; - [handler setAttachmentIds: [mail fetchAttachmentIds]]; + [handler setAttachmentIds: [mail fetchFileAttachmentIds]]; // We check if we got an unsupported charset. If so // we convert everything to UTF-16{LE,BE} so it passes