From b3679212bb9ac9395aaa0701cf1ef3fffcdd68d2 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 17 Dec 2007 20:24:07 +0000 Subject: [PATCH] Monotone-Parent: 7673d0874bfab0e145fb002673765af736eb602a Monotone-Revision: ac841eb2b94bbfe80bea0191f70da349cc60a700 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-12-17T20:24:07 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 29 +++++-- .../SOGoAptMailFrenchUpdate.html | 2 +- SoObjects/Mailer/SOGoMailBodyPart.h | 1 + SoObjects/Mailer/SOGoMailBodyPart.m | 84 +++++++++++-------- UI/MailPartViewers/UIxMailPartImageViewer.m | 24 +----- UI/MailPartViewers/UIxMailPartViewer.h | 8 +- UI/MailPartViewers/UIxMailPartViewer.m | 79 +++++++++-------- .../UIxMailPartImageViewer.wox | 2 +- 8 files changed, 126 insertions(+), 103 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3d5fba87c..a2ac5c07d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,13 +1,32 @@ +2007-12-17 Wolfgang Sourdeau + + * UI/MailPartViewers/UIxMailPartViewer.m ([UIxMailPartViewer + -clientPart]): new method that returns the corresponding + SOGoMailPart instance. + ([UIxMailPartViewer -pathToAttachment]): simplified method, ensure + the filename is present. If the part has none, create one with the + "Untitled-" prefix. Add an extension if none is found. + + * UI/MailPartViewers/UIxMailPartImageViewer.m + ([UIxMailPartImageViewer -pathToImage]): removed method since it + implementents exactly the same functionality as + [UIxMailPartViewer -pathToAttachment]. + + * SoObjects/Mailer/SOGoMailBodyPart.m ([SOGoMailBodyPart + -filename]): new method that returns the filename to the current + part by taking the different mime implementations into account. + [SOGoMailBodyPart -isBodyPartKey:inContext:]: commented out method + because we need to handle the part recognition in a different way, + by using the prefix "part" for example. One day we will do that. + + * UI/Scheduler/NSArray+Scheduler.m ([NSMutableArray + -reverseArray]): new category method. + 2007-12-17 Francis Lachapelle * UI/MailerUI/UIxMailMainFrame.m ([UIxMailMainFrame -composeAction]): fixed URL when no recipient is specified. -2007-12-17 Wolfgang Sourdeau - - * UI/Scheduler/NSArray+Scheduler.m ([NSMutableArray - -reverseArray]): new category method. - 2007-12-14 Ludovic Marcotte * SoObjects/Appointments/SOGoCalendarComponent.m diff --git a/SoObjects/Appointments/SOGoAptMailFrenchUpdate.wo/SOGoAptMailFrenchUpdate.html b/SoObjects/Appointments/SOGoAptMailFrenchUpdate.wo/SOGoAptMailFrenchUpdate.html index c008d3804..e23d83faf 100644 --- a/SoObjects/Appointments/SOGoAptMailFrenchUpdate.wo/SOGoAptMailFrenchUpdate.html +++ b/SoObjects/Appointments/SOGoAptMailFrenchUpdate.wo/SOGoAptMailFrenchUpdate.html @@ -1,5 +1,5 @@ <#IsSubject>Rendez-vous du <#OldAptStartDate /> à <#OldAptStartTime /> modifié <#IsBody> La réunion qui devait se dérouler le <#OldAptStartDate /> à <#OldAptStartTime /> est maintenant prévue le <#NewAptStartDate /> à <#NewAptStartTime />. -Vous êtes invité à accepter ou refuser de participer à la réunion pour cette nouvelle date à l'adresse <#HomePageURL />. +Vous êtes invité à accepter ou refuser de participer à la réunion pour cette nouvelle date à l'adresse <#HomePageURL />. diff --git a/SoObjects/Mailer/SOGoMailBodyPart.h b/SoObjects/Mailer/SOGoMailBodyPart.h index 4234074d0..76cc84dba 100644 --- a/SoObjects/Mailer/SOGoMailBodyPart.h +++ b/SoObjects/Mailer/SOGoMailBodyPart.h @@ -53,6 +53,7 @@ - (NSString *) bodyPartName; - (NSArray *) bodyPartPath; - (NSString *) bodyPartIdentifier; +- (NSString *) filename; /* part info */ diff --git a/SoObjects/Mailer/SOGoMailBodyPart.m b/SoObjects/Mailer/SOGoMailBodyPart.m index 6fac084d8..970abbb8d 100644 --- a/SoObjects/Mailer/SOGoMailBodyPart.m +++ b/SoObjects/Mailer/SOGoMailBodyPart.m @@ -73,9 +73,9 @@ static BOOL debugOn = NO; - (void) dealloc { - [self->partInfo release]; - [self->identifier release]; - [self->pathToPart release]; + [partInfo release]; + [identifier release]; + [pathToPart release]; [super dealloc]; } @@ -108,8 +108,8 @@ static BOOL debugOn = NO; NSMutableArray *p; id obj; - if (self->pathToPart != nil) - return [self->pathToPart isNotNull] ? self->pathToPart : nil; + if (pathToPart != nil) + return [pathToPart isNotNull] ? pathToPart : nil; p = [[NSMutableArray alloc] initWithCapacity:8]; for (obj = self; [obj isKindOfClass:[SOGoMailBodyPart class]]; @@ -117,18 +117,18 @@ static BOOL debugOn = NO; [p insertObject:[obj bodyPartName] atIndex:0]; } - self->pathToPart = [p copy]; + pathToPart = [p copy]; [p release]; - return self->pathToPart; + return pathToPart; } - (NSString *)bodyPartIdentifier { - if (self->identifier != nil) - return [self->identifier isNotNull] ? self->identifier : nil; + if (identifier != nil) + return [identifier isNotNull] ? identifier : nil; - self->identifier = + identifier = [[[self bodyPartPath] componentsJoinedByString:@"."] copy]; - return self->identifier; + return identifier; } - (NSURL *)imap4URL { @@ -139,12 +139,12 @@ static BOOL debugOn = NO; /* part info */ - (id)partInfo { - if (self->partInfo != nil) - return [self->partInfo isNotNull] ? self->partInfo : nil; + if (partInfo != nil) + return [partInfo isNotNull] ? partInfo : nil; - self->partInfo = + partInfo = [[[self mailObject] lookupInfoForBodyPart:[self bodyPartPath]] retain]; - return self->partInfo; + return partInfo; } /* name lookup */ @@ -160,25 +160,40 @@ static BOOL debugOn = NO; return [clazz objectWithName: _key inContainer: self]; } +- (NSString *) filename +{ + NSString *filename; + NSDictionary *parameters; + + [self partInfo]; + + filename = [[partInfo objectForKey: @"parameterList"] + objectForKey: @"name"]; + if (!filename) + { + parameters = [[partInfo objectForKey: @"disposition"] + objectForKey: @"parameterList"]; + filename = [parameters objectForKey: @"filename"]; + } + + return filename; +} + /* We overwrite the super's class method in order to make sure we aren't dealing with our actual filename as the _key. That could lead to problems if we weren't doing this as our filename could start with a digit, leading to a wrong assumption in the super class */ -- (BOOL)isBodyPartKey:(NSString *)_key inContext:(id)_ctx -{ - NSString *s; - - s = [[[self partInfo] objectForKey: @"parameterList"] objectForKey: @"name"]; +// - (BOOL)isBodyPartKey:(NSString *)_key inContext:(id)_ctx +// { +// NSString *s; - if (!s) - s = [[[[self partInfo] objectForKey: @"disposition"] objectForKey: @"parameterList"] objectForKey: @"filename"]; - - if (s && [s isEqualToString: _key]) return NO; +// s = [self filename]; +// if (s && [s isEqualToString: _key]) return NO; - return [super isBodyPartKey: _key inContext: _ctx]; -} +// return [super isBodyPartKey: _key inContext: _ctx]; +// } - (id) lookupName: (NSString *) _key inContext: (id) _ctx @@ -355,16 +370,13 @@ static BOOL debugOn = NO; [r setHeader: [NSString stringWithFormat:@"%d", [data length]] forKey: @"content-length"]; - if (asAttachment) { - fileName = [[[self partInfo] objectForKey: @"parameterList"] objectForKey: @"name"]; - if (!fileName) - fileName = [[[[self partInfo] objectForKey: @"disposition"] - objectForKey: @"parameterList"] - objectForKey: @"filename"]; - if ([fileName length]) - [r setHeader: [NSString stringWithFormat: @"attachment; filename=%@", fileName] - forKey: @"content-disposition"]; - } + if (asAttachment) + { + fileName = [self filename]; + if ([fileName length]) + [r setHeader: [NSString stringWithFormat: @"attachment; filename=%@", fileName] + forKey: @"content-disposition"]; + } if ((etag = [self davEntityTag]) != nil) [r setHeader:etag forKey:@"etag"]; diff --git a/UI/MailPartViewers/UIxMailPartImageViewer.m b/UI/MailPartViewers/UIxMailPartImageViewer.m index cb9b82e5d..bb05b1a2f 100644 --- a/UI/MailPartViewers/UIxMailPartImageViewer.m +++ b/UI/MailPartViewers/UIxMailPartImageViewer.m @@ -19,6 +19,8 @@ 02111-1307, USA. */ +#import + #import "UIxMailPartViewer.h" @interface UIxMailPartImageViewer : UIxMailPartViewer @@ -29,26 +31,4 @@ @implementation UIxMailPartImageViewer -/* URLs */ - -- (NSString *) pathToImage -{ - NSMutableString *url; - NSString *s; - - s = [[self clientObject] baseURLInContext: [self context]]; - url = [NSMutableString stringWithString: s]; - if (![url hasSuffix: @"/"]) - [url appendString: @"/"]; - - s = [[self partPath] componentsJoinedByString:@"/"]; - [url appendString: s]; - - s = [self preferredPathExtension]; - if (s) - [url appendFormat: @".%@", s]; - - return url; -} - @end /* UIxMailPartImageViewer */ diff --git a/UI/MailPartViewers/UIxMailPartViewer.h b/UI/MailPartViewers/UIxMailPartViewer.h index 5cd259441..fd0423203 100644 --- a/UI/MailPartViewers/UIxMailPartViewer.h +++ b/UI/MailPartViewers/UIxMailPartViewer.h @@ -41,7 +41,11 @@ content. */ -@class NSData, NSArray, NSFormatter; +@class NSArray; +@class NSData; +@class NSFormatter; + +@class SOGoMailBodyPart; @interface UIxMailPartViewer : UIxComponent { @@ -58,6 +62,8 @@ - (void)setBodyInfo:(id)_info; - (id)bodyInfo; +- (SOGoMailBodyPart *) clientPart; + - (NSData *)flatContent; - (NSData *)decodedFlatContent; - (NSString *)flatContentAsString; diff --git a/UI/MailPartViewers/UIxMailPartViewer.m b/UI/MailPartViewers/UIxMailPartViewer.m index f3a44db78..96b9e50a6 100644 --- a/UI/MailPartViewers/UIxMailPartViewer.m +++ b/UI/MailPartViewers/UIxMailPartViewer.m @@ -134,29 +134,25 @@ return [self flatContent]; } -- (NSData *) content +- (SOGoMailBodyPart *) clientPart { - NSData *content; - NSEnumerator *parts; id currentObject; NSString *currentPart; - - content = nil; + NSEnumerator *parts; currentObject = [self clientObject]; parts = [partPath objectEnumerator]; - currentPart = [parts nextObject]; - while (currentPart) - { - currentObject = [currentObject lookupName: currentPart - inContext: context - acquire: NO]; - currentPart = [parts nextObject]; - } + while ((currentPart = [parts nextObject])) + currentObject = [currentObject lookupName: currentPart + inContext: context + acquire: NO]; - content = [currentObject fetchBLOB]; + return currentObject; +} - return content; +- (NSData *) content +{ + return [[self clientPart] fetchBLOB]; } - (NSString *) flatContentAsString @@ -323,32 +319,41 @@ return url; } +- (NSString *) _filenameForAttachment: (SOGoMailBodyPart *) bodyPart +{ + NSMutableString *filename; + NSString *extension; + + filename = [NSMutableString stringWithString: [bodyPart filename]]; + if (![filename length]) + [filename appendFormat: @"%@-%@", + [self labelForKey: @"Untitled"], + [bodyPart nameInContainer]]; + + if (![[filename pathExtension] length]) + { + extension = [self preferredPathExtension]; + if (extension) + [filename appendFormat: @".%@", extension]; + } + + return [filename stringByEscapingURL]; +} + - (NSString *) pathToAttachment { - /* this generates a more beautiful 'download' URL for a part */ - NSString *fn; NSMutableString *url; + NSString *s; + SOGoMailBodyPart *bodyPart; - fn = [self filename]; - if ([fn length] > 0) - { - /* get basic URL */ - url = [NSMutableString stringWithString: [self pathToAttachmentObject]]; - - /* - If we have an attachment name, we attach it, this is properly handled by - SOGoMailBodyPart. - */ - - if (![url hasSuffix: @"/"]) - [url appendString: @"/"]; - if (isdigit([url characterAtIndex: 0])) - [url appendString: @"fn-"]; - [url appendString: [fn stringByEscapingURL]]; - // TODO: should we check for a proper extension? - } - else - url = nil; + bodyPart = [self clientPart]; + s = [bodyPart baseURLInContext: [self context]]; + url = [NSMutableString stringWithString: s]; + if (![url hasSuffix: @"/"]) + [url appendString: @"/"]; + +// s = [[self partPath] componentsJoinedByString: @"/"]; + [url appendString: [self _filenameForAttachment: bodyPart]]; return url; } diff --git a/UI/Templates/MailPartViewers/UIxMailPartImageViewer.wox b/UI/Templates/MailPartViewers/UIxMailPartImageViewer.wox index 1590d7a04..57da0493f 100644 --- a/UI/Templates/MailPartViewers/UIxMailPartImageViewer.wox +++ b/UI/Templates/MailPartViewers/UIxMailPartImageViewer.wox @@ -3,7 +3,7 @@ xmlns="http://www.w3.org/1999/xhtml" xmlns:var="http://www.skyrix.com/od/binding" - var:src="pathToImage" + var:src="pathToAttachment" var:title="filenameForDisplay" class="mailer_imagecontent" >