From 98d60326385de88d04e5b06b7af72096d30a69b8 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Fri, 22 Aug 2008 13:52:24 +0000 Subject: [PATCH] see changelog Monotone-Parent: a9323afc29bd494143d2c78639e7a02f3d3804cb Monotone-Revision: 1af347fe96abc17587172e207fcbf80e98d7f6f8 Monotone-Author: ludovic@Sophos.ca Monotone-Date: 2008-08-22T13:52:24 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 6 +++ SoObjects/Mailer/NSData+Mail.m | 40 +++++++++++++++---- SoObjects/Mailer/NSString+Mail.m | 6 ++- SoObjects/SOGo/NSString+Utilities.m | 2 +- UI/MailPartViewers/UIxMailPartMessageViewer.m | 8 ++++ 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 78499122b..0b6848b79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-08-22 Ludovic Marcotte + + * Modified SoObjects/Mailer/NSData+Mail.m + -decodedSubject so we correctly implement decoding + instead of relying on the broken SOPE implementation. + 2008-08-21 Ludovic Marcotte * SoObjects/SOGo/LDAPUserManager.m diff --git a/SoObjects/Mailer/NSData+Mail.m b/SoObjects/Mailer/NSData+Mail.m index 524553209..09af5b918 100644 --- a/SoObjects/Mailer/NSData+Mail.m +++ b/SoObjects/Mailer/NSData+Mail.m @@ -1,8 +1,9 @@ /* NSData+Mail.m - this file is part of SOGo * - * Copyright (C) 2007 Inverse groupe conseil + * Copyright (C) 2007-2008 Inverse inc. * * Author: Wolfgang Sourdeau + * Ludovic Marcotte * * 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 @@ -56,7 +57,7 @@ { const char *cData, *endFlag; unsigned int len; - NSString *converted, *decodedSubject; + NSString *decodedSubject; cData = [self bytes]; len = [self length]; @@ -70,14 +71,37 @@ if (*cData == '=' && *(cData + 1) == '?' && *endFlag == '?' && *(endFlag + 1) == '=') { - converted - = [[NSString alloc] initWithData: self - encoding: NSASCIIStringEncoding]; - if (converted) + NSString *enc; + int i; + + cData += 2; + i = 2; + + while (*cData != '?' && i < len) { - [converted autorelease]; - decodedSubject = [converted stringByDecodingQuotedPrintable]; + cData++; + i++; } + + enc = [[[NSString alloc] initWithData:[self subdataWithRange: NSMakeRange(2, i-2)] + encoding: NSASCIIStringEncoding] autorelease]; + + if (i+3 < len) + { + NSData *d; + + d = [self subdataWithRange: NSMakeRange(i+3, len-i-5)]; + + // We check if we have a QP or Base64 encoding + if (*(cData+1) == 'q' || *(cData+1) == 'Q') + d = [d dataByDecodingQuotedPrintable]; + else + d = [d dataByDecodingBase64]; + + decodedSubject = [NSString stringWithData: d usingEncodingNamed: enc]; + } + else + decodedSubject = nil; } } if (!decodedSubject) diff --git a/SoObjects/Mailer/NSString+Mail.m b/SoObjects/Mailer/NSString+Mail.m index a17658273..f02c9ac69 100644 --- a/SoObjects/Mailer/NSString+Mail.m +++ b/SoObjects/Mailer/NSString+Mail.m @@ -1,6 +1,6 @@ /* NSString+Mail.m - this file is part of SOGo * - * Copyright (C) 2007 Inverse groupe conseil + * Copyright (C) 2008 Inverse inc. * * Author: Wolfgang Sourdeau * @@ -33,6 +33,7 @@ #import #import "NSString+Mail.h" +#import "NSData+Mail.h" #if 1 #define showWhoWeAre() \ @@ -369,7 +370,8 @@ if ([self hasPrefix: @"=?"] && [self hasSuffix: @"?="]) { - decodedSubject = [self stringByDecodingQuotedPrintable]; + decodedSubject = [[self dataUsingEncoding: NSASCIIStringEncoding] + decodedSubject]; if (!decodedSubject) decodedSubject = self; } diff --git a/SoObjects/SOGo/NSString+Utilities.m b/SoObjects/SOGo/NSString+Utilities.m index 9da659743..6fbb3d7d4 100644 --- a/SoObjects/SOGo/NSString+Utilities.m +++ b/SoObjects/SOGo/NSString+Utilities.m @@ -1,6 +1,6 @@ /* NSString+Utilities.m - this file is part of SOGo * - * Copyright (C) 2006 Inverse groupe conseil + * Copyright (C) 2006-2008 Inverse inc. * * Author: Wolfgang Sourdeau * diff --git a/UI/MailPartViewers/UIxMailPartMessageViewer.m b/UI/MailPartViewers/UIxMailPartMessageViewer.m index 04cb6aa16..c30f19908 100644 --- a/UI/MailPartViewers/UIxMailPartMessageViewer.m +++ b/UI/MailPartViewers/UIxMailPartMessageViewer.m @@ -22,6 +22,8 @@ #import #import +#import + #import #import @@ -154,7 +156,13 @@ NSString *subject; baseSubject = [[self envelope] subject]; + + // We avoid uber-lamenesses in SOPE - see sope-core/NGExtensions/NGQuotedPrintableCoding.m + // -stringByDecodingQuotedPrintable for all details + if ([baseSubject isKindOfClass: [NSString class]]) + baseSubject = [baseSubject dataUsingEncoding: NSASCIIStringEncoding]; subject = [baseSubject decodedSubject]; + if (![subject length]) subject = [self labelForKey: @"Untitled"];