* add function decode_hex() that interprets 2 chars as hexdigits representing an...
authorWilfried Göesgens <willi@citadel.org>
Thu, 12 Mar 2009 22:54:48 +0000 (22:54 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 12 Mar 2009 22:54:48 +0000 (22:54 +0000)
* use it in the QP decoder.

libcitadel/lib/libcitadel.h
libcitadel/lib/mime_parser.c

index a633d0fb134387588b96629e403e00a2464c336a..c6454f210332eb56bd1c88a7171db0294594fc2b 100644 (file)
@@ -327,6 +327,7 @@ unsigned long extract_unsigned_long(const char *source, int parmnum);
 void CtdlInitBase64Table(void);
 size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int linebreaks);
 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
+inline unsigned int decode_hex(char *Source);
 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
 void striplt(char *);
 int haschar(const char *st, int ch);
index 026d0555009cd76d66865dd327b484274091f6c5..76452935a6280cd6ef92e5b27d3e1d8a3f28d4b9 100644 (file)
@@ -71,6 +71,26 @@ char *fixed_partnum(char *supplied_partnum) {
 }
 
 
+inline unsigned int decode_hex(char *Source)
+{
+       int ret = 0;
+       if (*Source  < 'A') {
+               ret += (*Source - '0');
+       }
+       else {
+               ret += (*Source - 'A' + 10);
+       }
+       ret = ret << 4;
+       if (*(Source + 1) < 'A') {
+               ret += (*(Source + 1) - '0');
+       }
+       else {
+               ret += (*(Source + 1) - 'A' + 10);
+       }
+       if (ret > 255)
+               return 0;
+       return ret;
+}
 
 /*
  * Convert "quoted-printable" to binary.  Returns number of bytes decoded.
@@ -94,7 +114,7 @@ int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen) {
                else if (encoded[pos] == '=')
                {
                        ch = 0;
-                       sscanf(&encoded[pos+1], "%02x", &ch);
+                       ch = decode_hex(&encoded[pos+1]);
                        pos += 3;
                        decoded[decoded_length++] = ch;
                }