From: helge Date: Mon, 28 May 2007 12:56:19 +0000 (+0000) Subject: applied patch in bug #1873 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5cd2dd3fdd512c78ef4ce57dbbc6332334b2791;p=sope applied patch in bug #1873 git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1486 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-mime/ChangeLog b/sope-mime/ChangeLog index 83519a8d..9cc785d1 100644 --- a/sope-mime/ChangeLog +++ b/sope-mime/ChangeLog @@ -1,3 +1,8 @@ +2007-05-15 Wolfgang Sourdeau + + * NGMime.m: encode string body contents using the charset + of the content-type (when available) (OGo bug #1873) (v4.7.245) + 2007-05-28 Helge Hess * NGImap4: changed behaviour wrt bug 1875 (v4.7.244) diff --git a/sope-mime/NGMime/ChangeLog b/sope-mime/NGMime/ChangeLog index b456cf05..e255405e 100644 --- a/sope-mime/NGMime/ChangeLog +++ b/sope-mime/NGMime/ChangeLog @@ -1,3 +1,8 @@ +2007-05-15 Wolfgang Sourdeau + + * NGMimeBodyGenerator.m: encode string body contents using the charset + of the content-type (when available) (OGo bug #1873) + 2006-02-22 Helge Hess * NGMimeRFC822DateHeaderFieldParser.m: added hardcoded detection for diff --git a/sope-mime/NGMime/NGMimeBodyGenerator.m b/sope-mime/NGMime/NGMimeBodyGenerator.m index 09310ed7..39fc4020 100644 --- a/sope-mime/NGMime/NGMimeBodyGenerator.m +++ b/sope-mime/NGMime/NGMimeBodyGenerator.m @@ -1,5 +1,6 @@ /* - Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2000-2007 SKYRIX Software AG + Copyright (C) 2007 Helge Hess This file is part of SOPE. @@ -97,6 +98,25 @@ static BOOL debugOn = NO; NSStringFromClass([self superclass]), [super version]); } +- (NSStringEncoding)_encodingFromContentType:(NGMimeType *)_type { + NSStringEncoding encoding; + NSString *charset; + + encoding = [NSString defaultCStringEncoding]; + if (_type != nil) { + charset = [_type valueOfParameter: @"charset"]; + if ([charset length] > 0) { + if ([charset isEqualToString: @"utf-8"]) + encoding = NSUTF8StringEncoding; + else if ([charset isEqualToString: @"iso-8859-1"]) + encoding = NSISOLatin1StringEncoding; + /* more should be handled here */ + } + } + + return encoding; +} + - (NSData *)generateBodyOfPart:(id)_part additionalHeaders:(NGMutableHashMap *)_addHeaders delegate:(id)_delegate @@ -105,14 +125,12 @@ static BOOL debugOn = NO; NSData *data; id body; - encoding = [NSString defaultCStringEncoding]; + encoding = [self _encodingFromContentType: [_part contentType]]; body = [_part body]; data = nil; - if ([body isKindOfClass:[NSString class]]) { - // TODO: deal with charset in content-type! + if ([body isKindOfClass:[NSString class]]) data = [body dataUsingEncoding:encoding]; - } else if ([body respondsToSelector:@selector(bytes)]) data = body; else if ([body respondsToSelector:@selector(dataUsingEncoding:)]) diff --git a/sope-mime/Version b/sope-mime/Version index 5afd1539..e00a6227 100644 --- a/sope-mime/Version +++ b/sope-mime/Version @@ -2,7 +2,7 @@ MAJOR_VERSION:=4 MINOR_VERSION:=7 -SUBMINOR_VERSION:=244 +SUBMINOR_VERSION:=245 # v4.5.214 requires libNGExtensions v4.5.146 # v4.2.149 requires libNGStreams v4.2.34