]> mj.ucw.cz Git - checkmail.git/commitdiff
Fixed a couple of bugs in rfc2047 parsing.
authorMartin Mares <mj@ucw.cz>
Mon, 25 Jun 2007 18:04:57 +0000 (20:04 +0200)
committerMartin Mares <mj@ucw.cz>
Mon, 25 Jun 2007 18:04:57 +0000 (20:04 +0200)
charset.c

index 280e42d1bf9dd827753bc29075100634097bf038..f9dcac9554104dfe7b5c9ebfce15d25c5a17dd03 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -74,12 +74,7 @@ static int Index_64[128] = {
 #define hexval(c) Index_hex[(unsigned int)(c)]
 #define base64val(c) Index_64[(unsigned int)(c)]
 
-#define OPTIGNORELWS 0
-
-static int option(int opt UNUSED)
-{
-  return 1;
-}
+#define option_OPTIGNORELWS 1
 
 static size_t convert_string (char *f, size_t flen,
                              const char *from, const char *to,
@@ -198,9 +193,20 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len)
     }
   }
 
-  size_t dlen;
   if (charset && system_charset)
-    convert_string (d0, strlen(d0), charset, system_charset, &d0, &dlen);
+    {
+      char *dnew;
+      size_t dlen;
+      if (convert_string (d0, strlen(d0), charset, system_charset, &dnew, &dlen) == (size_t) -1)
+       {
+         debug("Charset conversion failure: <%s> from %s\n", d0, charset);
+         free (charset);
+         free (d0);
+         return (-1);
+       }
+      free (d0);
+      d0 = dnew;
+    }
   strfcpy (d, d0, len);
   free (charset);
   free (d0);
@@ -305,7 +311,7 @@ static void rfc2047_decode (char **pd)
     if (!(p = find_encoded_word (s, &q)))
     {
       /* no encoded words */
-      if (option (OPTIGNORELWS))
+      if (option_OPTIGNORELWS)
       {
         n = strlen (s);
         if (found_encoded && (m = lwslen (s, n)) != 0)
@@ -325,7 +331,7 @@ static void rfc2047_decode (char **pd)
       n = (size_t) (p - s);
       /* ignore spaces between encoded word
        * and linear-white-space between encoded word and *text */
-      if (option (OPTIGNORELWS))
+      if (option_OPTIGNORELWS)
       {
         if (found_encoded && (m = lwslen (s, n)) != 0)
         {
@@ -355,7 +361,8 @@ static void rfc2047_decode (char **pd)
       }
     }
 
-    rfc2047_decode_word (d, p, dlen);
+    if (rfc2047_decode_word (d, p, dlen) < 0)
+      strcpy(d, p);
     found_encoded = 1;
     s = q;
     n = strlen (d);