diff --git a/SoObjects/Mailer/GNUmakefile b/SoObjects/Mailer/GNUmakefile index db5edc0b0..7934e878a 100644 --- a/SoObjects/Mailer/GNUmakefile +++ b/SoObjects/Mailer/GNUmakefile @@ -35,6 +35,7 @@ Mailer_OBJC_FILES += \ \ EOQualifier+MailDAV.m \ NSData+Mail.m \ + NSDictionary+Mail.m \ NSString+Mail.m \ SOGoUser+Mailer.m diff --git a/SoObjects/Mailer/NSDictionary+Mail.h b/SoObjects/Mailer/NSDictionary+Mail.h new file mode 100644 index 000000000..fceea68da --- /dev/null +++ b/SoObjects/Mailer/NSDictionary+Mail.h @@ -0,0 +1,34 @@ +/* NSDictionary+Mail.h - this file is part of SOGo + * + * Copyright (C) 2013 Inverse inc. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef NSDICTIONARY_MAIL_H +#define NSDICTIONARY_MAIL_H + +#import + +@class NSString; + +@interface NSDictionary (SOGoExtension) + +- (NSString *) filename; + +@end + +#endif /* NSDICTIONARY_MAIL_H */ diff --git a/SoObjects/Mailer/NSDictionary+Mail.m b/SoObjects/Mailer/NSDictionary+Mail.m new file mode 100644 index 000000000..74311f292 --- /dev/null +++ b/SoObjects/Mailer/NSDictionary+Mail.m @@ -0,0 +1,73 @@ +/* NSDictionary+Mail.m - this file is part of SOGo + * + * Copyright (C) 2013 Inverse inc. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#import + +#import "NSDictionary+Mail.h" + +@implementation NSDictionary (SOGoExtension) + +- (NSString *) filename +{ + NSDictionary *parameters; + NSString *filename; + + filename = [[self objectForKey: @"parameterList"] + objectForKey: @"name"]; + + if (!filename) + { + parameters = [[self objectForKey: @"disposition"] + objectForKey: @"parameterList"]; + filename = [parameters objectForKey: @"filename"]; + + + // We might have something like filename*=UTF-8''foobar + // See RFC2231 for details. If it was folded before, it will + // be unfolded when we get here. + if (!filename) + { + filename = [parameters objectForKey: @"filename*"]; + + if (filename) + { + NSRange r; + + filename = [filename stringByUnescapingURL]; + + // We skip up to the language + r = [filename rangeOfString: @"'"]; + + if (r.length) + { + r = [filename rangeOfString: @"'" options: 0 range: NSMakeRange(r.location+1, [filename length]-r.location-1)]; + + if (r.length) + filename = [filename substringFromIndex: r.location+1]; + } + } + } + } + + return filename; +} + +@end diff --git a/SoObjects/Mailer/SOGoMailBodyPart.m b/SoObjects/Mailer/SOGoMailBodyPart.m index 975463d0e..2fb075f4c 100644 --- a/SoObjects/Mailer/SOGoMailBodyPart.m +++ b/SoObjects/Mailer/SOGoMailBodyPart.m @@ -38,6 +38,7 @@ #import +#import "NSDictionary+Mail.h" #import "SOGoMailObject.h" #import "SOGoMailManager.h" @@ -201,21 +202,9 @@ static BOOL debugOn = NO; - (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; + + return [partInfo filename]; } /* We overwrite the super's class method in order to make sure diff --git a/SoObjects/Mailer/SOGoMailObject+Draft.m b/SoObjects/Mailer/SOGoMailObject+Draft.m index ff74c8e01..00f34be50 100644 --- a/SoObjects/Mailer/SOGoMailObject+Draft.m +++ b/SoObjects/Mailer/SOGoMailObject+Draft.m @@ -34,6 +34,7 @@ #import #import +#import "NSDictionary+Mail.h" #import "NSString+Mail.h" #import "SOGoMailForward.h" #import "SOGoMailObject+Draft.h" @@ -250,39 +251,10 @@ intoArray: (NSMutableArray *) keys withPath: (NSString *) path { - NSDictionary *disposition, *currentFile; NSString *filename, *mimeType; + NSDictionary *currentFile; - disposition = [part objectForKey: @"disposition"]; - filename = [[disposition objectForKey: @"parameterList"] - objectForKey: @"filename"]; - - // We might have something like filename*=UTF-8''foobar - // See RFC2231 for details. If it was folded before, it will - // be unfolded when we get here. - if (!filename) - { - filename = [[disposition objectForKey: @"parameterList"] - objectForKey: @"filename*"]; - - if (filename) - { - NSRange r; - - filename = [filename stringByUnescapingURL]; - - // We skip up to the language - r = [filename rangeOfString: @"'"]; - - if (r.length) - { - r = [filename rangeOfString: @"'" options: 0 range: NSMakeRange(r.location+1, [filename length]-r.location-1)]; - - if (r.length) - filename = [filename substringFromIndex: r.location+1]; - } - } - } + filename = [part filename]; mimeType = [NSString stringWithFormat: @"%@/%@", [part objectForKey: @"type"], diff --git a/UI/MailPartViewers/UIxMailPartViewer.m b/UI/MailPartViewers/UIxMailPartViewer.m index 2981875fd..51e8752a6 100644 --- a/UI/MailPartViewers/UIxMailPartViewer.m +++ b/UI/MailPartViewers/UIxMailPartViewer.m @@ -1,5 +1,5 @@ /* - Copyright (C) 2007-2009 Inverse inc. + Copyright (C) 2007-2013 Inverse inc. Copyright (C) 2004-2005 SKYRIX Software AG This file is part of SOGo. @@ -33,6 +33,7 @@ #import #import +#import #import #import "MailerUI/WOContext+UIxMailer.h" @@ -210,22 +211,7 @@ - (NSString *) filename { - NSDictionary *parameters; - NSString *filename; - - filename = nil; - parameters = [bodyInfo valueForKey: @"parameterList"]; - if (parameters) - filename = [parameters valueForKey: @"name"]; - - if (!filename) - { - parameters = [[bodyInfo valueForKey: @"disposition"] - valueForKey: @"parameterList"]; - filename = [parameters valueForKey: @"filename"]; - } - - return filename; + return [bodyInfo filename]; } - (NSString *) filenameForDisplay @@ -280,7 +266,7 @@ NSMutableString *filename; NSString *extension; - filename = [NSMutableString stringWithString: [bodyPart filename]]; + filename = [self filename]; if (![filename length]) [filename appendFormat: @"%@-%@", [self labelForKey: @"Untitled"], @@ -323,22 +309,22 @@ NSString *mimeImageFile, *mimeImageUrl; mimeImageFile = [NSString stringWithFormat: @"mime-%@-%@.png", - [bodyInfo objectForKey: @"type"], - [bodyInfo objectForKey: @"subtype"]]; + [bodyInfo objectForKey: @"type"], + [bodyInfo objectForKey: @"subtype"]]; mimeImageUrl = [self urlForResourceFilename: mimeImageFile]; - if ( [mimeImageUrl length] == 0 ) - { - mimeImageFile = [NSString stringWithFormat: @"mime-%@.png", - [bodyInfo objectForKey: @"type"]]; - mimeImageUrl = [self urlForResourceFilename: mimeImageFile]; - } + if ([mimeImageUrl length] == 0) + { + mimeImageFile = [NSString stringWithFormat: @"mime-%@.png", + [bodyInfo objectForKey: @"type"]]; + mimeImageUrl = [self urlForResourceFilename: mimeImageFile]; + } - if ( [mimeImageUrl length] == 0 ) - { - mimeImageUrl = [self urlForResourceFilename: @"mime-unknown.png"]; - } + if ([mimeImageUrl length] == 0) + { + mimeImageUrl = [self urlForResourceFilename: @"mime-unknown.png"]; + } return mimeImageUrl; }