From 479352df8b9bf2cda4ac6a1a8615cc9ee494f7ad Mon Sep 17 00:00:00 2001 From: helge Date: Tue, 29 Jan 2008 09:47:54 +0000 Subject: [PATCH] applied patch from OGo bug #789, 2008-01-29 git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1592 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-mime/ChangeLog | 4 +++ sope-mime/NGMime/ChangeLog | 4 +++ .../NGMimeAddressHeaderFieldGenerator.m | 28 ++++++++++++------- sope-mime/NGMime/NGMimeHeaderFieldGenerator.m | 12 +++++--- .../NGMime/NGMimeHeaderFieldGeneratorSet.m | 8 ++++++ sope-mime/Version | 2 +- 6 files changed, 43 insertions(+), 15 deletions(-) diff --git a/sope-mime/ChangeLog b/sope-mime/ChangeLog index ed0759c2..bfa52e1b 100644 --- a/sope-mime/ChangeLog +++ b/sope-mime/ChangeLog @@ -1,3 +1,7 @@ +2008-01-29 Albrecht Dress + + * fixes for OGo bug #789 (reply-to QP encoding) (v4.7.2) + 2007-08-29 Helge Hess * MacOS Version overflow (v4.7.1) diff --git a/sope-mime/NGMime/ChangeLog b/sope-mime/NGMime/ChangeLog index fd4bcd27..a62752a3 100644 --- a/sope-mime/NGMime/ChangeLog +++ b/sope-mime/NGMime/ChangeLog @@ -1,3 +1,7 @@ +2008-01-29 Albrecht Dress + + * fixes for OGo bug #789 (reply-to QP encoding) + 2007-08-29 Helge Hess * NGMimeFileData.m ([NGMimeFileData -initWithBytes:length:]): do not diff --git a/sope-mime/NGMime/NGMimeAddressHeaderFieldGenerator.m b/sope-mime/NGMime/NGMimeAddressHeaderFieldGenerator.m index f4cbd869..abe06387 100644 --- a/sope-mime/NGMime/NGMimeAddressHeaderFieldGenerator.m +++ b/sope-mime/NGMime/NGMimeAddressHeaderFieldGenerator.m @@ -114,7 +114,14 @@ static int UseLFSeperatedAddressEntries = -1; doEnc = NO; while (cnt < bufLen) { - if ((unsigned char)buffer[cnt] > 127) { + /* must encode chars outside ASCII 33..60, 62..126 ranges [RFC 2045, Sect. 6.7] + * RFC 2047, Sect. 4.2 also requires chars 63 and 95 to be encoded + * For spaces, quotation is fine */ + if ((unsigned char)buffer[cnt] < 32 || + (unsigned char)buffer[cnt] == 61 || + (unsigned char)buffer[cnt] == 63 || + (unsigned char)buffer[cnt] == 95 || + (unsigned char)buffer[cnt] > 126) { doEnc = YES; break; } @@ -122,6 +129,7 @@ static int UseLFSeperatedAddressEntries = -1; } if (doEnc) { + /* FIXME - better use UTF8 encoding! */ unsigned char iso[] = "=?iso-8859-15?q?"; unsigned isoLen = 16; unsigned char isoEnd[] = "?="; @@ -147,16 +155,15 @@ static int UseLFSeperatedAddressEntries = -1; desLen = bufLen * 3 + 20; des = calloc(desLen + 10, sizeof(char)); - memcpy(des, buffer, cnt); - memcpy(des + cnt, iso, isoLen); + memcpy(des, iso, isoLen); + memcpy(des + isoLen, buffer, bufLen); desLen = - NGEncodeQuotedPrintableMime((unsigned char *)buffer + cnt, bufLen- cnt, - des + cnt + isoLen, - desLen - cnt - isoLen); + NGEncodeQuotedPrintableMime((unsigned char *)buffer, bufLen, + des + isoLen, desLen - isoLen); if ((int)desLen != -1) { - memcpy(des + cnt + isoLen + desLen, isoEnd, isoEndLen); + memcpy(des + isoLen + desLen, isoEnd, isoEndLen); tmp = [NSString stringWithCString:(char *)des - length:(cnt + isoLen + desLen + isoEndLen)]; + length:(isoLen + desLen + isoEndLen)]; } else { [self warnWithFormat: @@ -168,9 +175,10 @@ static int UseLFSeperatedAddressEntries = -1; if (buffer) free(buffer); buffer = NULL; if ([tmp length] > 0) { - [result appendString:@"\""]; + /* do not place encoded strings in quotes [RFC 2045, RFC 2047, RFC 2822] */ + if (!doEnc) [result appendString:@"\""]; [result appendString:tmp]; - [result appendString:@"\""]; + if (!doEnc) [result appendString:@"\""]; if ((tmp = [(NSHost *)obj address])) { [result appendString:@" <"]; [result appendString:tmp]; diff --git a/sope-mime/NGMime/NGMimeHeaderFieldGenerator.m b/sope-mime/NGMime/NGMimeHeaderFieldGenerator.m index 15ad1d0a..5629862c 100644 --- a/sope-mime/NGMime/NGMimeHeaderFieldGenerator.m +++ b/sope-mime/NGMime/NGMimeHeaderFieldGenerator.m @@ -59,10 +59,14 @@ int NGEncodeQuotedPrintableMime for (cnt = 0; (cnt < _srcLen) && (destCnt < _destLen); cnt++) { register unsigned char c = _src[cnt]; - - if (((c > 47) && (c < 58)) || - ((c > 64) && (c < 91)) || - ((c > 96) && (c < 123))) { + + /* RFC 2045, Sect. 6.7 allows chars 33 through 60 inclusive, and 62 through 126, inclusive + * RFC 2047, Sect. 4.2 also requires chars 63 and 95 to be encoded + * Space might be "_", but let's encode it, too... */ + if (((c >= 33) && (c <= 60)) || + (c == 62) || + ((c >= 64) && (c <= 94)) || + ((c >= 96) && (c <= 126))) { // no quoting _dest[destCnt] = c; destCnt++; diff --git a/sope-mime/NGMime/NGMimeHeaderFieldGeneratorSet.m b/sope-mime/NGMime/NGMimeHeaderFieldGeneratorSet.m index 67b0a77c..95f8f7d4 100644 --- a/sope-mime/NGMime/NGMimeHeaderFieldGeneratorSet.m +++ b/sope-mime/NGMime/NGMimeHeaderFieldGeneratorSet.m @@ -64,12 +64,20 @@ static NGMimeHeaderFieldGeneratorSet *rfc822Set = nil; [rfc822Set setGenerator:gen forField:Fields->date]; if ((gen = [NGMimeAddressHeaderFieldGenerator headerFieldGenerator])) { + /* FIXME - following additional fields containing an address may be added here: + * - sender (RFC 2822, sect. 3.6.2) + * - resent-sender, resent-cc, resent-bcc (RFC 2822, sect. 3.6.6) + * Are the values case-insensitive, so "Reply-To" and "reply-to" will both + * be detected? + */ [rfc822Set setGenerator:gen forField:@"resent-from"]; [rfc822Set setGenerator:gen forField:@"resent-to"]; [rfc822Set setGenerator:gen forField:Fields->to]; [rfc822Set setGenerator:gen forField:Fields->cc]; [rfc822Set setGenerator:gen forField:@"bcc"]; [rfc822Set setGenerator:gen forField:Fields->from]; + [rfc822Set setGenerator:gen forField:@"reply-to"]; + [rfc822Set setGenerator:gen forField:@"Disposition-Notification-To"]; } if ((gen = [NGMimeStringHeaderFieldGenerator headerFieldGenerator])) diff --git a/sope-mime/Version b/sope-mime/Version index 4815fd2a..c9b3501a 100644 --- a/sope-mime/Version +++ b/sope-mime/Version @@ -2,7 +2,7 @@ MAJOR_VERSION:=4 MINOR_VERSION:=7 -SUBMINOR_VERSION:=1 +SUBMINOR_VERSION:=2 # v4.5.214 requires libNGExtensions v4.5.146 # v4.2.149 requires libNGStreams v4.2.34 -- 2.39.5