diff --git a/ChangeLog b/ChangeLog index 5768df7b0..5d5854f00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2007-12-12 Wolfgang Sourdeau + + * SoObjects/Mailer/SOGoMailObject.m ([SOGoMailObject + -fetchAttachmentIds]): new method that wanders through the mail + structure to collect the attachment content ids and to associate + them with their url. + + * UI/MailPartViewers/UIxMailPartHTMLViewer.m + ([_UIxHTMLMailContentHandler + -startElement:_localNamenamespace:_nsrawName:_rawNameattributes:_attributes]): + the content-ids are now enclosed between "<>" before retrieval + from the attachment dictionary. + ([UIxMailPartHTMLViewer -cssContent]) + ([UIxMailPartHTMLViewer -flatContentAsString]): the content-ids + are now fetch from the clientobject (an instance of + SOGoMailObject) with the new "fetchAttachmentIds" method. + 2007-12-12 Francis Lachapelle * UI/Scheduler/UIxCalListingActions.m ([UIxCalListingActions diff --git a/SoObjects/Mailer/SOGoMailObject.h b/SoObjects/Mailer/SOGoMailObject.h index fa0b54584..e4f873bfa 100644 --- a/SoObjects/Mailer/SOGoMailObject.h +++ b/SoObjects/Mailer/SOGoMailObject.h @@ -89,6 +89,8 @@ - (NSDictionary *) fetchPlainTextParts; - (NSDictionary *) fetchPlainTextStrings:(NSArray *)_fetchKeys; +- (NSDictionary *) fetchAttachmentIds; + /* flags */ - (NSException *) addFlags:(id)_f; diff --git a/SoObjects/Mailer/SOGoMailObject.m b/SoObjects/Mailer/SOGoMailObject.m index a28d752e6..6c38725f0 100644 --- a/SoObjects/Mailer/SOGoMailObject.m +++ b/SoObjects/Mailer/SOGoMailObject.m @@ -24,6 +24,7 @@ #import #import #import +#import #import #import @@ -644,6 +645,72 @@ static BOOL debugSoParts = NO; return [self fetchPlainTextParts: [self plainTextContentFetchKeys]]; } +- (NSString *) _urlToPart: (NSDictionary *) infos + withPrefix: (NSString *) urlPrefix +{ + NSDictionary *parameters; + NSString *urlToPart, *filename; + + parameters = [infos objectForKey: @"parameterList"]; + filename = [parameters objectForKey: @"name"]; + if (!filename) + { + parameters = [[infos objectForKey: @"disposition"] + objectForKey: @"parameterList"]; + filename = [parameters objectForKey: @"filename"]; + } + + if ([filename length]) + urlToPart = [NSString stringWithFormat: @"%@/%@", urlPrefix, filename]; + else + urlToPart = nil; + + return urlToPart; +} + +- (void) _feedAttachmentIds: (NSMutableDictionary *) attachmentIds + withInfos: (NSDictionary *) infos + andPrefix: (NSString *) prefix +{ + NSArray *parts; + NSDictionary *currentPart; + unsigned int count, max; + NSString *url, *cid; + + cid = [infos objectForKey: @"bodyId"]; + if ([cid length]) + { + url = [self _urlToPart: infos withPrefix: prefix]; + if (url) + [attachmentIds setObject: url forKey: cid]; + } + + parts = [infos objectForKey: @"parts"]; + max = [parts count]; + for (count = 0; count < max; count++) + { + currentPart = [parts objectAtIndex: count]; + [self _feedAttachmentIds: attachmentIds + withInfos: currentPart + andPrefix: [NSString stringWithFormat: @"%@/%d", + prefix, count + 1]]; + } +} + +- (NSDictionary *) fetchAttachmentIds +{ + NSMutableDictionary *attachmentIds; + + attachmentIds = [NSMutableDictionary dictionary]; + + [self fetchCoreInfos]; + [self _feedAttachmentIds: attachmentIds + withInfos: [coreInfos objectForKey: @"body"] + andPrefix: [[self soURL] absoluteString]]; + + return attachmentIds; +} + /* convert parts to strings */ - (NSString *) stringForData: (NSData *) _data partInfo: (NSDictionary *) _info diff --git a/UI/MailPartViewers/UIxMailPartHTMLViewer.m b/UI/MailPartViewers/UIxMailPartHTMLViewer.m index 6644e30ff..94c7055de 100644 --- a/UI/MailPartViewers/UIxMailPartHTMLViewer.m +++ b/UI/MailPartViewers/UIxMailPartHTMLViewer.m @@ -35,6 +35,8 @@ #include +#import + #import "UIxMailPartHTMLViewer.h" #if 0 @@ -207,7 +209,7 @@ attributes: (id ) _attributes { unsigned int count, max; - NSString *name, *value; + NSString *name, *value, *cid; NSMutableString *resultPart; BOOL skipAttribute; @@ -237,8 +239,9 @@ value = [_attributes valueAtIndex: count]; if ([value hasPrefix: @"cid:"]) { - value = [attachmentIds - objectForKey: [value substringFromIndex: 4]]; + cid = [NSString stringWithFormat: @"<%@>", + [value substringFromIndex: 4]]; + value = [attachmentIds objectForKey: cid]; skipAttribute = (value == nil); } else @@ -433,68 +436,6 @@ [super dealloc]; } -- (void) _convertReferencesForPart: (NSDictionary *) part - withCount: (unsigned int) count - andBaseURL: (NSString *) url - intoDictionary: (NSMutableDictionary *) attachmentIds -{ - NSString *bodyId, *filename; - NSMutableString *attachmentURL; - - bodyId = [part objectForKey: @"bodyId"]; - if ([bodyId length] > 0) - { - filename = [[part objectForKey: @"parameterList"] objectForKey: @"name"]; - if (!filename) - filename = [[[part objectForKey: @"disposition"] - objectForKey: @"parameterList"] - objectForKey: @"filename"]; - if ([bodyId hasPrefix: @"<"]) - bodyId = [bodyId substringFromIndex: 1]; - if ([bodyId hasSuffix: @">"]) - bodyId = [bodyId substringToIndex: [bodyId length] - 1]; - attachmentURL = [NSMutableString stringWithString: url]; - [attachmentURL appendFormat: @"/%d", count]; - if ([filename length]) - [attachmentURL appendFormat: @"/%@", filename]; - [attachmentIds setObject: attachmentURL forKey: bodyId]; - } -} - -- (NSDictionary *) _attachmentIds -{ - NSMutableDictionary *attachmentIds; - UIxMailPartViewer *parent; - unsigned int count, max; -// NSMutableString *url; - NSString *baseURL; - NSArray *parts; - - attachmentIds = [NSMutableDictionary new]; - [attachmentIds autorelease]; - - parent = [self parent]; - if ([NSStringFromClass ([parent class]) - isEqualToString: @"UIxMailPartAlternativeViewer"]) - { - baseURL = [[self clientObject] baseURLInContext: context]; -// url = [NSMutableString new]; -// [url appendString: baseURL]; -// [url appendFormat: @"/%@", [partPath componentsJoinedByString: @"/"]]; -// [url deleteCharactersInRange: NSMakeRange([url length] - 4, 4)]; - parts = [[[parent parent] bodyInfo] objectForKey: @"parts"]; - max = [parts count]; - for (count = 0; count < max; count++) - [self _convertReferencesForPart: [parts objectAtIndex: count] - withCount: count + 1 - andBaseURL: baseURL - intoDictionary: attachmentIds]; -// [url release]; - } - - return attachmentIds; -} - - (xmlCharEncoding) _xmlCharsetForCharset: (NSString *) charset { struct { NSString *name; xmlCharEncoding encoding; } xmlEncodings[] = { @@ -557,13 +498,16 @@ { NSObject *parser; NSData *preparsedContent; + SOGoMailObject *mail; + + mail = [self clientObject]; preparsedContent = [super decodedFlatContent]; parser = [[SaxXMLReaderFactory standardXMLReaderFactory] createXMLReaderForMimeType: @"text/html"]; handler = [_UIxHTMLMailContentHandler new]; - [handler setAttachmentIds: [self _attachmentIds]]; + [handler setAttachmentIds: [mail fetchAttachmentIds]]; [handler setContentEncoding: [self _xmlCharEncoding]]; [parser setContentHandler: handler]; [parser parseFromSource: preparsedContent];