tmp
[apps/madmutt.git] / lib-mime / rfc2231.c
index e7c1053..760bf11 100644 (file)
  *
  */
 
-#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <lib-lib/mem.h>
-#include <lib-lib/str.h>
-#include <lib-lib/ascii.h>
+#include <lib-lib/lib-lib.h>
 
 #include <lib-mime/mime.h>
 
 #include "charset.h"
+#include "mutt.h"
 
 typedef struct rfc2231_param {
     struct rfc2231_param *next;
@@ -133,25 +128,10 @@ rfc2231_list_insert(rfc2231_param **list, rfc2231_param *par)
     *list = par;
 }
 
-static void purge_empty_parameters(PARAMETER **headp)
-{
-    while (*headp) {
-        PARAMETER *p = *headp;
-
-        if (!p->attribute || !p->value) {
-            *headp = p->next;
-            p->next = NULL;
-            parameter_delete(&p);
-        } else {
-            headp = &(*headp)->next;
-        }
-    }
-}
-
 /* process continuation parameters */
 /* XXX: MC: not read */
 static void
-rfc2231_join_continuations(PARAMETER **head, rfc2231_param *par)
+rfc2231_join_continuations(parameters_t *head, rfc2231_param *par)
 {
     rfc2231_param *q;
 
@@ -164,7 +144,6 @@ rfc2231_join_continuations(PARAMETER **head, rfc2231_param *par)
     size_t l, vl;
 
     while (par) {
-        value = NULL;
         l = 0;
 
         m_strcpy(attribute, sizeof(attribute), par->attribute);
@@ -181,7 +160,7 @@ rfc2231_join_continuations(PARAMETER **head, rfc2231_param *par)
             vl = m_strlen(par->value);
 
             p_realloc(&value, l + vl + 1);
-            strcpy (value + l, par->value);   /* __STRCPY_CHECKED__ */
+            m_strcpy(value + l, vl + 1, par->value);
             l += vl;
 
             q = par->next;
@@ -190,15 +169,13 @@ rfc2231_join_continuations(PARAMETER **head, rfc2231_param *par)
                 valp = par->value;
         } while (par && !m_strcmp(par->attribute, attribute));
 
-        if (value) {
-            if (encoded)
-                mutt_convert_string (&value, charset, Charset, M_ICONV_HOOK_FROM);
-            *head = parameter_new();
-            (*head)->attribute = m_strdup(attribute);
-            (*head)->value = value;
-            head = &(*head)->next;
-        }
+        if (!value)
+            continue;
+        if (encoded)
+            mutt_convert_string (&value, charset, mod_cset.charset, M_ICONV_HOOK_FROM);
+        parameter_setval(head, attribute, value);
     }
+    p_delete(&value);
 }
 
 /****************************************************************************/
@@ -206,11 +183,12 @@ rfc2231_join_continuations(PARAMETER **head, rfc2231_param *par)
 /****************************************************************************/
 
 /* XXX: MC: not read */
-void rfc2231_decode_parameters (PARAMETER ** headp)
+void rfc2231_decode_parameters(parameters_t *headp)
 {
-    PARAMETER *head = NULL;
-    PARAMETER **last;
-    PARAMETER *p, *q;
+#if 0
+    parameter_t *head = NULL;
+    parameter_t **last;
+    parameter_t *p, *q;
 
     rfc2231_param *conthead = NULL;
     rfc2231_param *conttmp;
@@ -225,7 +203,7 @@ void rfc2231_decode_parameters (PARAMETER ** headp)
     if (!headp)
         return;
 
-    purge_empty_parameters (headp);
+    parameter_purge_empty(headp);
 
     for (last = &head, p = *headp; p; p = q) {
         q = p->next;
@@ -239,10 +217,10 @@ void rfc2231_decode_parameters (PARAMETER ** headp)
              * Internet Gateways.  So we actually decode it.
              */
 
-            if (option (OPTRFC2047PARAMS) && p->value && strstr (p->value, "=?"))
-                rfc2047_decode (&p->value);
-            else if (!option (OPTSTRICTMIME)) {
-                if (mime_which_token(AssumedCharset, -1) == MIME_US_ASCII)
+            if (p->value && strstr(p->value, "=?")) {
+                rfc2047_decode(&p->value);
+            } else {
+                if (mime_which_token(mod_cset.assumed_charset, -1) == MIME_US_ASCII)
                     mutt_convert_nonmime_string(&p->value);
             }
 
@@ -255,7 +233,7 @@ void rfc2231_decode_parameters (PARAMETER ** headp)
 
             s = rfc2231_get_charset (p->value, charset, sizeof (charset));
             rfc2231_decode_one (p->value, s);
-            mutt_convert_string (&p->value, charset, Charset, M_ICONV_HOOK_FROM);
+            mutt_convert_string (&p->value, charset, mod_cset.charset, M_ICONV_HOOK_FROM);
 
             *last = p;
             last = &p->next;
@@ -294,7 +272,8 @@ void rfc2231_decode_parameters (PARAMETER ** headp)
     *headp = head;
 
     if (dirty)
-        purge_empty_parameters (headp);
+        parameter_purge_empty(headp);
+#endif
 }
 
 #define RFC2231_SPECIALS  "@.,;:<>[]\\\"()?/= \t*'%"
@@ -319,13 +298,13 @@ int rfc2231_encode_string(char **s)
             return 0;
     }
 
-    if (Charset && SendCharset) {
-        charset = mutt_choose_charset(Charset, SendCharset,
+    if (mod_cset.charset && mod_cset.send_charset) {
+        charset = mutt_choose_charset(mod_cset.charset, mod_cset.send_charset,
                                       *s, m_strlen(*s), &d, &dlen);
     }
 
     if (!charset) {
-        charset = m_strdup(Charset ? Charset : "unknown-8bit");
+        charset = m_strdup(mod_cset.charset ?: "unknown-8bit");
         d = *s;
         dlen = m_strlen(d);
     }