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;
}
}
if (doEnc) {
+ /* FIXME - better use UTF8 encoding! */
unsigned char iso[] = "=?iso-8859-15?q?";
unsigned isoLen = 16;
unsigned char isoEnd[] = "?=";
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:
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];
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++;
[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]))