From: helge Date: Sun, 30 Jan 2005 21:38:25 +0000 (+0000) Subject: some fixes to attachment name escaping, added type specific body part objects X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=746dc044d83d0a9ceeb4aaf63a1a094181b7baa5;p=scalable-opengroupware.org some fixes to attachment name escaping, added type specific body part objects git-svn-id: http://svn.opengroupware.org/SOGo/trunk@510 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 3b728916..0f90c473 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,5 +1,10 @@ 2005-01-30 Helge Hess - + + * v0.9.61 + + * SOGoMailObject.m, SOGoMailBodyPart.m, product.plist: added type + specific SOGoMailBodyPart controller objects, reduced debug logs + * v0.9.60 * SOGoDraftObject.m: added -content and -contentAsString methods (Note: diff --git a/SOGo/SoObjects/Mailer/GNUmakefile b/SOGo/SoObjects/Mailer/GNUmakefile index c594750f..1e6ae666 100644 --- a/SOGo/SoObjects/Mailer/GNUmakefile +++ b/SOGo/SoObjects/Mailer/GNUmakefile @@ -17,7 +17,10 @@ Mailer_OBJC_FILES += \ SOGoMailAccount.m \ SOGoMailFolder.m \ SOGoMailObject.m \ + \ SOGoMailBodyPart.m \ + SOGoImageMailBodyPart.m \ + SOGoMessageMailBodyPart.m \ \ SOGoDraftsFolder.m \ SOGoDraftObject.m \ diff --git a/SOGo/SoObjects/Mailer/SOGoImageMailBodyPart.m b/SOGo/SoObjects/Mailer/SOGoImageMailBodyPart.m new file mode 100644 index 00000000..3a4f1a51 --- /dev/null +++ b/SOGo/SoObjects/Mailer/SOGoImageMailBodyPart.m @@ -0,0 +1,42 @@ +/* + Copyright (C) 2004-2005 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include + +/* + SOGoImageMailBodyPart + + A specialized SOGoMailBodyPart subclass for image attachments. Can be used + to attach special SoMethods. + + See the superclass for more information on part objects. +*/ + +@interface SOGoImageMailBodyPart : SOGoMailBodyPart +{ +} + +@end + +#include "common.h" + +@implementation SOGoImageMailBodyPart +@end /* SOGoImageMailBodyPart */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailBodyPart.h b/SOGo/SoObjects/Mailer/SOGoMailBodyPart.h index 815d78f5..7a996ebd 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailBodyPart.h +++ b/SOGo/SoObjects/Mailer/SOGoMailBodyPart.h @@ -57,6 +57,10 @@ - (id)partInfo; +/* factory */ + ++ (Class)bodyPartClassForKey:(NSString *)_key inContext:(id)_ctx; + @end #endif /* __Mailer_SOGoMailBodyPart_H__ */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailBodyPart.m b/SOGo/SoObjects/Mailer/SOGoMailBodyPart.m index 4ced6a48..61873b8c 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailBodyPart.m +++ b/SOGo/SoObjects/Mailer/SOGoMailBodyPart.m @@ -26,6 +26,8 @@ @implementation SOGoMailBodyPart +static BOOL debugOn = NO; + - (void)dealloc { [self->partInfo release]; [self->identifier release]; @@ -99,9 +101,10 @@ - (id)lookupImap4BodyPartKey:(NSString *)_key inContext:(id)_ctx { // TODO: we might want to check for existence prior controller creation - // TODO: we might(should?) want to create type-specific body-part objects - return [[[SOGoMailBodyPart alloc] initWithName:_key - inContainer:self] autorelease]; + Class clazz; + + clazz = [SOGoMailBodyPart bodyPartClassForKey:_key inContext:_ctx]; + return [[[clazz alloc] initWithName:_key inContainer:self] autorelease]; } - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag { @@ -245,4 +248,35 @@ return r; } +/* factory */ + ++ (Class)bodyPartClassForKey:(NSString *)_key inContext:(id)_ctx { + NSString *pe; + + pe = [_key pathExtension]; + if (![pe isNotNull] || [pe length] == 0) + return self; + + /* hard coded for now */ + + switch ([pe length]) { + case 3: + if ([pe isEqualToString:@"gif"] || + [pe isEqualToString:@"png"] || + [pe isEqualToString:@"jpg"]) + return NSClassFromString(@"SOGoImageMailBodyPart"); + case 4: + if ([pe isEqualToString:@"mail"]) + return NSClassFromString(@"SOGoMessageMailBodyPart"); + default: + return self; + } +} + +/* debugging */ + +- (BOOL)isDebuggingEnabled { + return debugOn; +} + @end /* SOGoMailBodyPart */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.m b/SOGo/SoObjects/Mailer/SOGoMailObject.m index 43150091..f87e20b6 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.m +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.m @@ -30,6 +30,7 @@ static NSArray *coreInfoKeys = nil; static BOOL heavyDebug = NO; +static BOOL debugOn = NO; + (void)initialize { /* Note: see SOGoMailManager.m for allowed IMAP4 keys */ @@ -184,7 +185,7 @@ static BOOL heavyDebug = NO; unsigned idx; NSArray *parts; - [self logWithFormat:@"check PATH: %@", p]; + [self debugWithFormat:@"check PATH: %@", p]; idx = [p intValue] - 1; parts = [info valueForKey:@"parts"]; @@ -274,8 +275,10 @@ static BOOL heavyDebug = NO; - (id)lookupImap4BodyPartKey:(NSString *)_key inContext:(id)_ctx { // TODO: we might want to check for existence prior controller creation - return [[[SOGoMailBodyPart alloc] initWithName:_key - inContainer:self] autorelease]; + Class clazz; + + clazz = [SOGoMailBodyPart bodyPartClassForKey:_key inContext:_ctx]; + return [[[clazz alloc] initWithName:_key inContainer:self] autorelease]; } - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag { @@ -343,4 +346,10 @@ static BOOL heavyDebug = NO; password:[self imap4Password]]; } +/* debugging */ + +- (BOOL)isDebuggingEnabled { + return debugOn; +} + @end /* SOGoMailObject */ diff --git a/SOGo/SoObjects/Mailer/SOGoMessageMailBodyPart.m b/SOGo/SoObjects/Mailer/SOGoMessageMailBodyPart.m new file mode 100644 index 00000000..90e03777 --- /dev/null +++ b/SOGo/SoObjects/Mailer/SOGoMessageMailBodyPart.m @@ -0,0 +1,42 @@ +/* + Copyright (C) 2004-2005 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include + +/* + SOGoMessageMailBodyPart + + A specialized SOGoMailBodyPart subclass for message attachments. Can be used + to attach special SoMethods. + + See the superclass for more information on part objects. +*/ + +@interface SOGoMessageMailBodyPart : SOGoMailBodyPart +{ +} + +@end + +#include "common.h" + +@implementation SOGoMessageMailBodyPart +@end /* SOGoMessageMailBodyPart */ diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 563de9bc..fed4e8c1 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=59 +SUBMINOR_VERSION:=61 # v0.9.55 requires NGExtensions v4.5.136 # v0.9.44 requires libNGMime v4.3.194 diff --git a/SOGo/SoObjects/Mailer/product.plist b/SOGo/SoObjects/Mailer/product.plist index 16bc55b6..5ca398aa 100644 --- a/SOGo/SoObjects/Mailer/product.plist +++ b/SOGo/SoObjects/Mailer/product.plist @@ -34,6 +34,9 @@ SOGoMailBodyPart = { superclass = "SOGoMailBaseObject"; }; + SOGoImageMailBodyPart = { + superclass = "SOGoMailBodyPart"; + }; SOGoDraftsFolder = { superclass = "SOGoMailBaseObject"; diff --git a/SOGo/SoObjects/Sieve/SOGoSieveScriptObject.m b/SOGo/SoObjects/Sieve/SOGoSieveScriptObject.m index eebc5df9..b874a6db 100644 --- a/SOGo/SoObjects/Sieve/SOGoSieveScriptObject.m +++ b/SOGo/SoObjects/Sieve/SOGoSieveScriptObject.m @@ -51,7 +51,6 @@ /* Note: valueForKey:@"reason" does not work?! */ reason = [[_result valueForKey:@"RawResponse"] objectForKey:@"reason"]; - [self logWithFormat:@"REASON: %@", reason]; if (![reason isNotNull]) reason = @"Failed to upload Sieve script."; diff --git a/SOGo/UI/Mailer/ChangeLog b/SOGo/UI/Mailer/ChangeLog index 04b698ec..8c594df0 100644 --- a/SOGo/UI/Mailer/ChangeLog +++ b/SOGo/UI/Mailer/ChangeLog @@ -1,4 +1,12 @@ 2005-01-30 Helge Hess + + * v0.9.82 + + * UIxMailPartLinkViewer.m: prefix filenames which start with a digit, + properly escape attachment names + + * UIxMailPartImageViewer.m (UIxMailPartViewer): append image extension + to attachments * v0.9.81 diff --git a/SOGo/UI/Mailer/UIxMailPartImageViewer.m b/SOGo/UI/Mailer/UIxMailPartImageViewer.m index 1dc4b7d3..deb7252e 100644 --- a/SOGo/UI/Mailer/UIxMailPartImageViewer.m +++ b/SOGo/UI/Mailer/UIxMailPartImageViewer.m @@ -31,19 +31,24 @@ @implementation UIxMailPartImageViewer -- (void)dealloc { - [super dealloc]; -} - /* URLs */ - (NSString *)pathToImage { NSString *url; + NSString *s; url = [[self clientObject] baseURLInContext:[self context]]; if (![url hasSuffix:@"/"]) url = [url stringByAppendingString:@"/"]; - return [url stringByAppendingString: - [[self partPath] componentsJoinedByString:@"/"]]; + + s = [[self partPath] componentsJoinedByString:@"/"]; + url = [url stringByAppendingString:s]; + + if ((s = [self preferredPathExtension]) != nil) { + url = [url stringByAppendingString:@"."]; + url = [url stringByAppendingString:s]; + } + + return url; } @end /* UIxMailPartImageViewer */ diff --git a/SOGo/UI/Mailer/UIxMailPartLinkViewer.m b/SOGo/UI/Mailer/UIxMailPartLinkViewer.m index b43395f0..16574e1b 100644 --- a/SOGo/UI/Mailer/UIxMailPartLinkViewer.m +++ b/SOGo/UI/Mailer/UIxMailPartLinkViewer.m @@ -58,7 +58,9 @@ /* URLs */ - (NSString *)pathToAttachment { - NSString *url, *n; + NSString *url, *n, *pext; + + pext = [self preferredPathExtension]; /* path to mail controller object */ @@ -69,21 +71,25 @@ n = [[self partPath] componentsJoinedByString:@"/"]; url = [url stringByAppendingString:n]; + if ([pext isNotNull] && [pext length] > 0) { + /* attach extension */ + url = [url stringByAppendingString:@"."]; + url = [url stringByAppendingString:pext]; + } /* If we have an attachment name, we attach it, this is properly handled by SOGoMailBodyPart. */ - n = [[[self bodyInfo] valueForKey:@"parameterList"] valueForKey:@"name"]; + n = [self filenameForDisplay]; if ([n isNotNull] && [n length] > 0) { url = [url stringByAppendingString:@"/"]; - url = [url stringByAppendingString:n]; - } - else if ([(n = [[self bodyInfo] valueForKey:@"type"]) isNotNull]) { - /* attach extension */ - url = [url stringByAppendingString:@"."]; - url = [url stringByAppendingString:[self preferredPathExtension]]; + if (isdigit([n characterAtIndex:0])) + url = [url stringByAppendingString:@"fn-"]; + url = [url stringByAppendingString:[n stringByEscapingURL]]; + + // TODO: should we check for a proper extension? } return url; diff --git a/SOGo/UI/Mailer/UIxMailPartViewer.m b/SOGo/UI/Mailer/UIxMailPartViewer.m index 6a174ee0..07fc1b34 100644 --- a/SOGo/UI/Mailer/UIxMailPartViewer.m +++ b/SOGo/UI/Mailer/UIxMailPartViewer.m @@ -153,6 +153,9 @@ if ([_st isEqualToString:@"plain"]) return @"txt"; if ([_st isEqualToString:@"xml"]) return @"xml"; } + else if ([_mt isEqualToString:@"message"]) { + if ([_st isEqualToString:@"rfc822"]) return @"mail"; + } else if ([_mt isEqualToString:@"application"]) { if ([_st isEqualToString:@"pdf"]) return @"pdf"; } @@ -174,8 +177,10 @@ tmp = [tmp valueForKey:@"name"]; if (![tmp isNotNull]) return nil; + if ([tmp length] == 0) + return nil; - return [tmp length] > 0 ? tmp : nil; + return tmp; } - (NSString *)filenameForDisplay { diff --git a/SOGo/UI/Mailer/Version b/SOGo/UI/Mailer/Version index e846368e..06f04de4 100644 --- a/SOGo/UI/Mailer/Version +++ b/SOGo/UI/Mailer/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=81 +SUBMINOR_VERSION:=82 # v0.9.81 requires SoObjects/Sieve v0.9.5 # v0.9.80 requires SoObjects/Mailer v0.9.59