From: helge Date: Tue, 13 Dec 2005 15:41:27 +0000 (+0000) Subject: fixed underscore decoding in quoted printable X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07732b5d762f6cdf2744492dc7623399351966e1;p=sope fixed underscore decoding in quoted printable git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1197 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-core/NGExtensions/ChangeLog b/sope-core/NGExtensions/ChangeLog index 2c7f35ae..b7ee7219 100644 --- a/sope-core/NGExtensions/ChangeLog +++ b/sope-core/NGExtensions/ChangeLog @@ -1,3 +1,8 @@ +2005-12-13 Helge Hess + + * NGQuotedPrintableCoding.m (NGDecodeQuotedPrintable): properly decode + underscore as 0x20 (as per RFC 2047 4.2) (v4.5.180) + 2005-11-21 Helge Hess * NGExtensions/NSObject+Values.h: added NGBaseTypeValues protocol to diff --git a/sope-core/NGExtensions/NGQuotedPrintableCoding.m b/sope-core/NGExtensions/NGQuotedPrintableCoding.m index 2f9b1271..22780df0 100644 --- a/sope-core/NGExtensions/NGQuotedPrintableCoding.m +++ b/sope-core/NGExtensions/NGQuotedPrintableCoding.m @@ -99,7 +99,7 @@ // implementation -static inline char __hexToChar(char c) { +static inline signed char __hexToChar(char c) { if ((c > 47) && (c < 58)) // '0' .. '9' return c - 48; if ((c > 64) && (c < 71)) // 'A' .. 'F' @@ -110,7 +110,14 @@ static inline char __hexToChar(char c) { } int NGDecodeQuotedPrintable(const char *_src, unsigned _srcLen, - char *_dest, unsigned _destLen) { + char *_dest, unsigned _destLen) +{ + /* + Eg: "Hello=20World" => "Hello World" + + =XY where XY is a hex encoded byte. In addition '_' is decoded as 0x20 + (not as space!, this depends on the charset, see RFC 2047 4.2). + */ unsigned cnt = 0; unsigned destCnt = 0; @@ -119,33 +126,38 @@ int NGDecodeQuotedPrintable(const char *_src, unsigned _srcLen, for (cnt = 0; ((cnt < _srcLen) && (destCnt < _destLen)); cnt++) { if (_src[cnt] != '=') { - _dest[destCnt++] = _src[cnt]; + _dest[destCnt] = _src[cnt] == '_' ? 0x20 : _src[cnt]; + destCnt++; } else { if ((_srcLen - cnt) > 1) { signed char c1, c2; - c1 = _src[++cnt]; - + cnt++; // skip '=' + c1 = _src[cnt]; // first hex digit + if (c1 == '\r' || c1 == '\n') { - if (_src[cnt+1] == '\r' || _src[cnt+1] == '\n' ) + if (_src[cnt + 1] == '\r' || _src[cnt + 1] == '\n' ) cnt++; continue; } c1 = __hexToChar(c1); - c2 = __hexToChar(_src[++cnt]); + + cnt++; // skip first hex digit + c2 = __hexToChar(_src[cnt]); if ((c1 == -1) || (c2 == -1)) { if ((_destLen - destCnt) > 1) { - _dest[destCnt++] = _src[cnt - 1]; - _dest[destCnt++] = _src[cnt]; + _dest[destCnt] = _src[cnt - 1]; destCnt++; + _dest[destCnt] = _src[cnt]; destCnt++; } else break; } else { - char c = ((c1 << 4) | c2); - _dest[destCnt++] = c; + register unsigned char c = ((c1 << 4) | c2); + _dest[destCnt] = c; + destCnt++; } } else diff --git a/sope-core/NGExtensions/Version b/sope-core/NGExtensions/Version index 4d437fa9..91ad9c03 100644 --- a/sope-core/NGExtensions/Version +++ b/sope-core/NGExtensions/Version @@ -1,6 +1,6 @@ # version -SUBMINOR_VERSION:=179 +SUBMINOR_VERSION:=180 # v4.3.115 requires libFoundation v1.0.59 # v4.2.72 requires libEOControl v4.2.39