From a27acace6b1f0965ab995249c8607f1ae9a1724d Mon Sep 17 00:00:00 2001 From: helge Date: Tue, 5 Oct 2004 12:34:15 +0000 Subject: [PATCH] fixed content decoding git-svn-id: http://svn.opengroupware.org/SOGo/trunk@357 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/UI/Mailer/ChangeLog | 8 ++++ SOGo/UI/Mailer/UIxMailPartTextViewer.m | 23 ------------ SOGo/UI/Mailer/UIxMailPartViewer.h | 2 + SOGo/UI/Mailer/UIxMailPartViewer.m | 51 ++++++++++++++++++++++++++ SOGo/UI/Mailer/Version | 2 +- 5 files changed, 62 insertions(+), 24 deletions(-) diff --git a/SOGo/UI/Mailer/ChangeLog b/SOGo/UI/Mailer/ChangeLog index 7d4259c3..12789f63 100644 --- a/SOGo/UI/Mailer/ChangeLog +++ b/SOGo/UI/Mailer/ChangeLog @@ -1,5 +1,13 @@ 2004-10-05 Helge Hess + * v0.9.19 + + * UIxMailPartViewer.m: added content decoding for QP, base64 and 7bit, + added proper charset decoding + + * UIxMailPartTextViewer.m: moved content => NSString conversion to + UIxMailPartViewer.m + * v0.9.18 * UIxMailPartViewer.m: added support methods for caches, added -sleep diff --git a/SOGo/UI/Mailer/UIxMailPartTextViewer.m b/SOGo/UI/Mailer/UIxMailPartTextViewer.m index d0c28c2a..990a4060 100644 --- a/SOGo/UI/Mailer/UIxMailPartTextViewer.m +++ b/SOGo/UI/Mailer/UIxMailPartTextViewer.m @@ -37,27 +37,4 @@ /* accessors */ -- (NSString *)flatContentAsString { - /* Note: we even have the line count in the body-info! */ - NSString *charset, *enc; - NSString *s; - NSData *content; - - if ((content = [self flatContent]) == nil) { - [self logWithFormat:@"ERROR: got no text content: %@", [self partPath]]; - return nil; - } - - charset = - [[[self bodyInfo] objectForKey:@"parameterList"] objectForKey:@"charset"]; - enc = [[self bodyInfo] objectForKey:@"encoding"]; - - // TODO: properly decode charset, might need to handle encoding? - - s = [[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding]; - if (s == nil) - [self logWithFormat:@"ERROR: could not convert content to text!"]; - return [s autorelease]; -} - @end /* UIxMailPartTextViewer */ diff --git a/SOGo/UI/Mailer/UIxMailPartViewer.h b/SOGo/UI/Mailer/UIxMailPartViewer.h index a5551f08..551085e7 100644 --- a/SOGo/UI/Mailer/UIxMailPartViewer.h +++ b/SOGo/UI/Mailer/UIxMailPartViewer.h @@ -48,6 +48,8 @@ - (id)bodyInfo; - (NSData *)flatContent; +- (NSData *)decodedFlatContent; +- (NSString *)flatContentAsString; /* caches */ diff --git a/SOGo/UI/Mailer/UIxMailPartViewer.m b/SOGo/UI/Mailer/UIxMailPartViewer.m index e172aac4..f032bb7b 100644 --- a/SOGo/UI/Mailer/UIxMailPartViewer.m +++ b/SOGo/UI/Mailer/UIxMailPartViewer.m @@ -22,6 +22,7 @@ #include "UIxMailPartViewer.h" #include "UIxMailRenderingContext.h" #include "WOContext+UIxMailer.h" +#include #include "common.h" @implementation UIxMailPartViewer @@ -81,4 +82,54 @@ return self->flatContent; } +- (NSData *)decodedFlatContent { + NSString *enc; + + enc = [[[self bodyInfo] objectForKey:@"encoding"] lowercaseString]; + + if ([enc isEqualToString:@"7bit"]) + return [self flatContent]; + + if ([enc isEqualToString:@"base64"]) + return [[self flatContent] dataByDecodingBase64]; + + if ([enc isEqualToString:@"quoted-printable"]) + return [[self flatContent] dataByDecodingQuotedPrintable]; + + [self logWithFormat:@"ERROR: unsupported MIME encoding: %@", enc]; + return [self flatContent]; +} + +- (NSString *)flatContentAsString { + /* Note: we even have the line count in the body-info! */ + NSString *charset; + NSString *s; + NSData *content; + + if ((content = [self decodedFlatContent]) == nil) { + [self logWithFormat:@"ERROR: got no text content: %@", [self partPath]]; + return nil; + } + + charset = + [[[self bodyInfo] objectForKey:@"parameterList"] objectForKey:@"charset"]; + charset = [charset lowercaseString]; + + // TODO: properly decode charset, might need to handle encoding? + + if ([charset length] > 0) { + s = [NSString stringWithData:content usingEncodingNamed:charset]; + } + else { + s = [[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding]; + s = [s autorelease]; + } + if (s == nil) { + [self logWithFormat: + @"ERROR: could not convert content to text, charset: '%@'", + charset]; + } + return s; +} + @end /* UIxMailPartViewer */ diff --git a/SOGo/UI/Mailer/Version b/SOGo/UI/Mailer/Version index cd35ad0f..93c8cd1d 100644 --- a/SOGo/UI/Mailer/Version +++ b/SOGo/UI/Mailer/Version @@ -1,3 +1,3 @@ # $Id$ -SUBMINOR_VERSION:=18 +SUBMINOR_VERSION:=19 -- 2.39.5