From e3da5b29549b877e0e944903a3fd6f07763efaa1 Mon Sep 17 00:00:00 2001 From: helge Date: Thu, 24 Mar 2005 16:40:18 +0000 Subject: [PATCH] minor code cleanups in message generator git-svn-id: http://svn.opengroupware.org/SOPE/trunk@696 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-mime/ChangeLog | 4 + sope-mime/NGMail/ChangeLog | 4 + sope-mime/NGMail/NGMimeMessageGenerator.m | 113 ++++++++++++---------- sope-mime/Version | 2 +- 4 files changed, 71 insertions(+), 52 deletions(-) diff --git a/sope-mime/ChangeLog b/sope-mime/ChangeLog index ded5fc96..2cfeee07 100644 --- a/sope-mime/ChangeLog +++ b/sope-mime/ChangeLog @@ -1,3 +1,7 @@ +2005-03-24 Helge Hess + + * NGMime: minor code cleanups (v4.5.218) + 2005-03-05 Helge Hess * NGMime: fixed an issue with incorrect header field termination diff --git a/sope-mime/NGMail/ChangeLog b/sope-mime/NGMail/ChangeLog index 009fae08..96648451 100644 --- a/sope-mime/NGMail/ChangeLog +++ b/sope-mime/NGMail/ChangeLog @@ -1,3 +1,7 @@ +2005-03-24 Helge Hess + + * NGMimeMessageGenerator.m: minor code cleanups + 2005-01-30 Helge Hess * NGMimeMessageGenerator.m: fixed a format bug in an error log which diff --git a/sope-mime/NGMail/NGMimeMessageGenerator.m b/sope-mime/NGMail/NGMimeMessageGenerator.m index 415b34c3..50820cf0 100644 --- a/sope-mime/NGMail/NGMimeMessageGenerator.m +++ b/sope-mime/NGMail/NGMimeMessageGenerator.m @@ -45,68 +45,79 @@ static BOOL debugOn = NO; /* header field specifics */ -- (NSData *)generateDataForHeaderField:(NSString *)_headerField - value:(id)_value -{ - NSData *data = nil; +- (id)_escapeHeaderFieldValue:(NSData *)_data { + const char *bytes = NULL; + unsigned int length = 0; + unsigned int desLen = 0; + char *des = NULL; + unsigned int cnt; + BOOL doEnc; + NSString *str; - data = [super generateDataForHeaderField:_headerField - value:_value]; - { - const char *bytes = NULL; - unsigned int length = 0; - unsigned int desLen = 0; - char *des = NULL; - unsigned int cnt = 0; - BOOL doEnc = NO; - NSString *str; + // TODO: this s***s big time! #if APPLE_Foundation_LIBRARY || NeXT_Foundation_LIBRARY - str = [[NSString alloc] initWithData:data - encoding:NSISOLatin1StringEncoding]; + str = [[NSString alloc] initWithData:_data + encoding:NSISOLatin1StringEncoding]; #else - str = [[NSString alloc] initWithData:data - encoding:NSISOLatin9StringEncoding]; + str = [[NSString alloc] initWithData:_data + encoding:NSISOLatin9StringEncoding]; #endif - str = [str autorelease]; - - bytes = [str cString]; - length = [str cStringLength]; - - while (cnt < length) { - if ((unsigned char)bytes[cnt] > 127) { - doEnc = YES; - break; - } - cnt++; + str = [str autorelease]; + + bytes = [str cString]; + length = [str cStringLength]; + + /* check whether we need to encode */ + + for (cnt = 0, doEnc = NO; cnt < length; cnt++) { + if ((unsigned char)bytes[cnt] > 127) { + doEnc = YES; + break; } - if (doEnc) { - char iso[] = "=?iso-8859-15?q?"; - unsigned isoLen = 16; - char isoEnd[] = "?="; - unsigned isoEndLen = 2; + } + + if (!doEnc) + return _data; + + /* encode quoted printable */ + { + char iso[] = "=?iso-8859-15?q?"; + unsigned isoLen = 16; + char isoEnd[] = "?="; + unsigned isoEndLen = 2; + + desLen = length * 3 + 20; - desLen = length * 3 + 20; + des = calloc(desLen + 2, sizeof(char)); - des = calloc(desLen + 2, sizeof(char)); + // memcpy(des, bytes, cnt); + memcpy(des, iso, isoLen); + desLen = NGEncodeQuotedPrintableMime(bytes, length, + des + isoLen, desLen - isoLen); + if ((int)desLen != -1) { + memcpy(des + isoLen + desLen, isoEnd, isoEndLen); - // memcpy(des, bytes, cnt); - memcpy(des, iso, isoLen); - desLen = NGEncodeQuotedPrintableMime(bytes, length, - des + isoLen, desLen - isoLen); - if ((int)desLen != -1) { - memcpy(des + isoLen + desLen, isoEnd, isoEndLen); - - data = [NSData dataWithBytesNoCopy:des - length:(isoLen + desLen + isoEndLen)]; - } - else { - NSLog(@"WARNING: An error occour during quoted-printable decoding"); - if (des != NULL) free(des); - } + return [NSData dataWithBytesNoCopy:des + length:(isoLen + desLen + isoEndLen)]; + } + else { + [self logWithFormat: + @"WARNING: An error occour during quoted-printable decoding"]; + if (des != NULL) free(des); + return _data; } } - return data; +} + +- (NSData *)generateDataForHeaderField:(NSString *)_hf value:(id)_value { + NSData *data; + + // TODO: properly deal with header field values, add proper quoting + // prior passing the value up? + + data = [super generateDataForHeaderField:_hf value:_value]; + return [self _escapeHeaderFieldValue:data]; } diff --git a/sope-mime/Version b/sope-mime/Version index 981f7bf8..f805eb4d 100644 --- a/sope-mime/Version +++ b/sope-mime/Version @@ -2,7 +2,7 @@ MAJOR_VERSION:=4 MINOR_VERSION:=5 -SUBMINOR_VERSION:=217 +SUBMINOR_VERSION:=218 # v4.5.214 requires libNGExtensions v4.5.146 # v4.2.149 requires libNGStreams v4.2.34 -- 2.39.5