Monotone-Parent: 21a3dbfea6d041ca22f1f9804ac4084ea25551bc
Monotone-Revision: 6223f47e26b3dedfd23e6559da23309cfecc4449 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-02-13T22:57:04 Monotone-Branch: ca.inverse.sogomaint-2.0.2
parent
a564e7b302
commit
75b199d27a
|
@ -1,5 +1,12 @@
|
|||
2011-02-13 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
|
||||
* UI/MailPartViewers/UIxMailPartViewer.m (-decodedFlatContent):
|
||||
finally make use of the -bodyDataFromEncoding: category method
|
||||
from NSData+Mail (Mailer module).
|
||||
(-flatContentAsString): moved charset-decoding code into a new
|
||||
category method named "-bodyStringFromCharset:" in NSData+Mail
|
||||
(Mailer module).
|
||||
|
||||
* SoObjects/Mailer/SOGoMailObject.m (-lookupInfoForBodyPart:):
|
||||
accept "text" as path parameter and return the main bodyStructure
|
||||
in that case.
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
@interface NSData (SOGoMailUtilities)
|
||||
|
||||
- (NSData *) bodyDataFromEncoding: (NSString *) encoding;
|
||||
- (NSString *) bodyStringFromCharset: (NSString *) charset;
|
||||
|
||||
- (NSString *) decodedHeader;
|
||||
|
||||
@end
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#import <NGExtensions/NGBase64Coding.h>
|
||||
#import <NGExtensions/NGQuotedPrintableCoding.h>
|
||||
#import <NGExtensions/NSString+Encoding.h>
|
||||
#import <NGExtensions/NSObject+Logs.h>
|
||||
|
||||
#import "NSData+Mail.h"
|
||||
|
||||
|
@ -36,6 +37,8 @@
|
|||
NSString *realEncoding;
|
||||
NSData *decodedData;
|
||||
|
||||
if ([encoding length] > 0)
|
||||
{
|
||||
realEncoding = [encoding lowercaseString];
|
||||
|
||||
if ([realEncoding isEqualToString: @"7bit"]
|
||||
|
@ -50,10 +53,56 @@
|
|||
decodedData = nil;
|
||||
NSLog (@"encoding '%@' unknown, returning nil data", realEncoding);
|
||||
}
|
||||
}
|
||||
else
|
||||
decodedData = self;
|
||||
|
||||
return decodedData;
|
||||
}
|
||||
|
||||
- (NSString *) bodyStringFromCharset: (NSString *) charset
|
||||
{
|
||||
NSString *lcCharset, *bodyString;
|
||||
|
||||
if ([charset length])
|
||||
lcCharset = [charset lowercaseString];
|
||||
else
|
||||
lcCharset = @"us-ascii";
|
||||
|
||||
bodyString = [NSString stringWithData: self usingEncodingNamed: lcCharset];
|
||||
if (![bodyString length])
|
||||
{
|
||||
/* UTF-8 is used as a 8bit fallback charset... */
|
||||
bodyString = [[NSString alloc] initWithData: self
|
||||
encoding: NSUTF8StringEncoding];
|
||||
[bodyString autorelease];
|
||||
}
|
||||
|
||||
if (!bodyString)
|
||||
{
|
||||
/*
|
||||
iCalendar invitations sent by Outlook 2002 have the annoying bug that the
|
||||
mail states an UTF-8 content encoding but the actual iCalendar content is
|
||||
encoding in Latin-1 (or Windows Western?).
|
||||
|
||||
As a result the content decoding will fail (TODO: always?). In this case we
|
||||
try to decode with Latin-1.
|
||||
|
||||
Note: we could check for the Outlook x-mailer, but it was considered better
|
||||
to try Latin-1 as a fallback in any case (be tolerant).
|
||||
*/
|
||||
|
||||
bodyString = [[NSString alloc] initWithData: self
|
||||
encoding: NSISOLatin1StringEncoding];
|
||||
if (!bodyString)
|
||||
[self errorWithFormat: @"an attempt to use"
|
||||
@" NSISOLatin1StringEncoding as callback failed"];
|
||||
[bodyString autorelease];
|
||||
}
|
||||
|
||||
return bodyString;
|
||||
}
|
||||
|
||||
/*
|
||||
* Excpected form is: "=?charset?encoding?encoded text?=".
|
||||
*/
|
||||
|
|
|
@ -31,13 +31,14 @@
|
|||
#import <NGExtensions/NSString+Encoding.h>
|
||||
#import <NGExtensions/NSString+misc.h>
|
||||
|
||||
#import <SoObjects/SOGo/NSString+Utilities.h>
|
||||
#import <SoObjects/Mailer/SOGoMailBodyPart.h>
|
||||
#import <SOGo/NSString+Utilities.h>
|
||||
#import <Mailer/NSData+Mail.h>
|
||||
#import <Mailer/SOGoMailBodyPart.h>
|
||||
|
||||
#import "UI/MailerUI/WOContext+UIxMailer.h"
|
||||
#import "MailerUI/WOContext+UIxMailer.h"
|
||||
#import "UIxMailRenderingContext.h"
|
||||
#import "UIxMailSizeFormatter.h"
|
||||
#import "UI/SOGoUI/UIxComponent.h"
|
||||
#import "SOGoUI/UIxComponent.h"
|
||||
|
||||
#import "UIxMailPartViewer.h"
|
||||
|
||||
|
@ -114,28 +115,13 @@
|
|||
return flatContent;
|
||||
}
|
||||
|
||||
#warning we should use NSData+Mail bodyDataFromEncoding: instead
|
||||
- (NSData *) decodedFlatContent
|
||||
{
|
||||
NSString *enc;
|
||||
|
||||
enc = [[bodyInfo objectForKey:@"encoding"] lowercaseString];
|
||||
|
||||
if ([enc isEqualToString:@"7bit"])
|
||||
return [self flatContent];
|
||||
|
||||
if ([enc isEqualToString:@"8bit"]) // TODO: correct?
|
||||
return [self flatContent];
|
||||
|
||||
if ([enc isEqualToString:@"base64"])
|
||||
return [[self flatContent] dataByDecodingBase64];
|
||||
|
||||
if ([enc isEqualToString:@"quoted-printable"])
|
||||
return [[self flatContent] dataByDecodingQuotedPrintableTransferEncoding];
|
||||
|
||||
[self errorWithFormat:@"unsupported MIME encoding: %@", enc];
|
||||
|
||||
return [self flatContent];
|
||||
return [[self flatContent] bodyDataFromEncoding: enc];
|
||||
}
|
||||
|
||||
- (SOGoMailBodyPart *) clientPart
|
||||
|
@ -170,40 +156,7 @@
|
|||
{
|
||||
charset = [[bodyInfo objectForKey:@"parameterList"]
|
||||
objectForKey: @"charset"];
|
||||
if ([charset length])
|
||||
charset = [charset lowercaseString];
|
||||
else
|
||||
charset = @"us-ascii";
|
||||
s = [NSString stringWithData: content usingEncodingNamed: charset];
|
||||
if (![s length])
|
||||
{
|
||||
/* UTF-8 is used as a 8bit fallback charset... */
|
||||
s = [[NSString alloc] initWithData: content
|
||||
encoding: NSUTF8StringEncoding];
|
||||
[s autorelease];
|
||||
}
|
||||
|
||||
if (!s)
|
||||
{
|
||||
/*
|
||||
iCalendar invitations sent by Outlook 2002 have the annoying bug that the
|
||||
mail states an UTF-8 content encoding but the actual iCalendar content is
|
||||
encoding in Latin-1 (or Windows Western?).
|
||||
|
||||
As a result the content decoding will fail (TODO: always?). In this case we
|
||||
try to decode with Latin-1.
|
||||
|
||||
Note: we could check for the Outlook x-mailer, but it was considered better
|
||||
to try Latin-1 as a fallback in any case (be tolerant).
|
||||
*/
|
||||
|
||||
s = [[NSString alloc] initWithData:content
|
||||
encoding: NSISOLatin1StringEncoding];
|
||||
if (!s)
|
||||
[self errorWithFormat: @"an attempt to use"
|
||||
@" NSISOLatin1StringEncoding as callback failed"];
|
||||
[s autorelease];
|
||||
}
|
||||
s = [content bodyStringFromCharset: charset];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue