Properly handle RFC2231 everywhere

pull/12/head
Ludovic Marcotte 2013-07-16 15:18:04 -04:00
parent e08ebd2390
commit 16105d37b8
6 changed files with 130 additions and 75 deletions

View File

@ -35,6 +35,7 @@ Mailer_OBJC_FILES += \
\
EOQualifier+MailDAV.m \
NSData+Mail.m \
NSDictionary+Mail.m \
NSString+Mail.m \
SOGoUser+Mailer.m

View File

@ -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 <Foundation/NSDictionary.h>
@class NSString;
@interface NSDictionary (SOGoExtension)
- (NSString *) filename;
@end
#endif /* NSDICTIONARY_MAIL_H */

View File

@ -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 <Foundation/NSDictionary.h>
#import <Foundation/NSString.h>
#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

View File

@ -38,6 +38,7 @@
#import <SoObjects/SOGo/NSDictionary+Utilities.h>
#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

View File

@ -34,6 +34,7 @@
#import <SoObjects/SOGo/SOGoUser.h>
#import <SoObjects/SOGo/SOGoUserDefaults.h>
#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"],

View File

@ -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 <SOGo/NSString+Utilities.h>
#import <Mailer/NSData+Mail.h>
#import <Mailer/NSDictionary+Mail.h>
#import <Mailer/SOGoMailBodyPart.h>
#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;
}