move mutt_get_parameter -> parameter_getval into mime.c
authorPierre Habouzit <madcoder@debian.org>
Wed, 15 Nov 2006 18:39:03 +0000 (19:39 +0100)
committerPierre Habouzit <madcoder@debian.org>
Wed, 15 Nov 2006 18:39:03 +0000 (19:39 +0100)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
12 files changed:
commands.c
handler.c
lib-crypt/crypt.c
lib-mime/mime-types.h
lib-mime/mime.c
lib-mime/rfc1524.c
lib-mime/rfc3676.c
lib-mime/rfc822parse.c
muttlib.c
postpone.c
protos.h
sendlib.c

index bc05999..648966c 100644 (file)
@@ -833,7 +833,7 @@ void mutt_edit_content_type (HEADER * h, BODY * b, FILE * fp)
   short charset_changed = 0;
   short type_changed = 0;
 
-  cp = mutt_get_parameter ("charset", b->parameter);
+  cp = parameter_getval(b->parameter, "charset");
   m_strcpy(charset, sizeof(charset), NONULL(cp));
 
   snprintf (buf, sizeof (buf), "%s/%s", TYPE (b), b->subtype);
@@ -864,7 +864,7 @@ void mutt_edit_content_type (HEADER * h, BODY * b, FILE * fp)
   snprintf (tmp, sizeof (tmp), "%s/%s", TYPE (b), NONULL (b->subtype));
   type_changed = ascii_strcasecmp (tmp, obuf);
   charset_changed =
-    ascii_strcasecmp (charset, mutt_get_parameter ("charset", b->parameter));
+    ascii_strcasecmp (charset, parameter_getval(b->parameter, "charset"));
 
   /* if in send mode, check for conversion - current setting is default. */
 
@@ -872,7 +872,7 @@ void mutt_edit_content_type (HEADER * h, BODY * b, FILE * fp)
     int r;
 
     snprintf (tmp, sizeof (tmp), _("Convert to %s upon sending?"),
-              mutt_get_parameter ("charset", b->parameter));
+              parameter_getval(b->parameter, "charset"));
     if ((r = mutt_yesorno (tmp, !b->noconv)) != -1)
       b->noconv = (r == M_NO);
   }
@@ -886,7 +886,7 @@ void mutt_edit_content_type (HEADER * h, BODY * b, FILE * fp)
     if (type_changed)
       mutt_sleep (1);
     mutt_message (_("Character set changed to %s; %s."),
-                  mutt_get_parameter ("charset", b->parameter),
+                  parameter_getval(b->parameter, "charset"),
                   b->noconv ? _("not converting") : _("converting"));
   }
 
index e7ca176..5d9af6d 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -783,12 +783,10 @@ static int alternative_handler (BODY * a, STATE * s)
     fstat (fileno (s->fpin), &st);
     b = mutt_new_body ();
     b->length = (long) st.st_size;
-    b->parts = mutt_parse_multipart (s->fpin,
-                                     mutt_get_parameter ("boundary",
-                                                         a->parameter),
-                                     (long) st.st_size,
-                                     ascii_strcasecmp ("digest",
-                                                       a->subtype) == 0);
+    b->parts = mutt_parse_multipart(s->fpin,
+                                    parameter_getval(a->parameter, "boundary"),
+                                    (long)st.st_size,
+                                    !ascii_strcasecmp("digest", a->subtype));
   }
   else
     b = a;
@@ -999,12 +997,10 @@ static int multipart_handler (BODY * a, STATE * s)
     fstat (fileno (s->fpin), &st);
     b = mutt_new_body ();
     b->length = (long) st.st_size;
-    b->parts = mutt_parse_multipart (s->fpin,
-                                     mutt_get_parameter ("boundary",
-                                                         a->parameter),
-                                     (long) st.st_size,
-                                     ascii_strcasecmp ("digest",
-                                                       a->subtype) == 0);
+    b->parts = mutt_parse_multipart(s->fpin,
+                                    parameter_getval(a->parameter, "boundary"),
+                                    (long)st.st_size,
+                                    !ascii_strcasecmp("digest", a->subtype));
   }
   else
     b = a;
@@ -1179,7 +1175,7 @@ static int external_body_handler (BODY * b, STATE * s)
   const char *expiration;
   time_t expire;
 
-  access_type = mutt_get_parameter ("access-type", b->parameter);
+  access_type = parameter_getval(b->parameter, "access-type");
   if (!access_type) {
     if (s->flags & M_DISPLAY) {
       state_mark_attach (s);
@@ -1188,7 +1184,7 @@ static int external_body_handler (BODY * b, STATE * s)
     return (-1);
   }
 
-  expiration = mutt_get_parameter ("expiration", b->parameter);
+  expiration = parameter_getval(b->parameter, "expiration");
   if (expiration)
     expire = mutt_parse_date (expiration, NULL);
   else
@@ -1202,7 +1198,7 @@ static int external_body_handler (BODY * b, STATE * s)
       state_mark_attach (s);
       state_printf (s, _("[-- This %s/%s attachment "),
                     TYPE (b->parts), b->parts->subtype);
-      length = mutt_get_parameter ("length", b->parameter);
+      length = parameter_getval(b->parameter, "length");
       if (length) {
         mutt_pretty_size (pretty_size, sizeof (pretty_size),
                           strtol (length, NULL, 10));
@@ -1265,7 +1261,7 @@ void mutt_decode_attachment (BODY * b, STATE * s)
 
   if (istext) {
     if (s->flags & M_CHARCONV) {
-      const char *charset = mutt_get_parameter ("charset", b->parameter);
+      const char *charset = parameter_getval(b->parameter, "charset");
 
       if (!option (OPTSTRICTMIME) && !charset)
         charset = charset_getfirst(AssumedCharset);
@@ -1336,9 +1332,8 @@ int mutt_body_handler (BODY * b, STATE * s)
       if (mutt_is_application_pgp (b))
         handler = crypt_pgp_application_pgp_handler;
       else
-        if (ascii_strcasecmp
-            ("flowed", mutt_get_parameter ("format", b->parameter)) == 0)
-        handler = rfc3676_handler;
+        if (!ascii_strcasecmp("flowed", parameter_getval(b->parameter, "format")))
+          handler = rfc3676_handler;
       else
         plaintext = 1;
     }
@@ -1361,7 +1356,7 @@ int mutt_body_handler (BODY * b, STATE * s)
     if (ascii_strcasecmp ("alternative", b->subtype) == 0)
       handler = alternative_handler;
     else if (ascii_strcasecmp ("signed", b->subtype) == 0) {
-      p = mutt_get_parameter ("protocol", b->parameter);
+      p = parameter_getval(b->parameter, "protocol");
 
       if (!p)
         mutt_error (_("Error: multipart/signed has no protocol."));
@@ -1370,7 +1365,7 @@ int mutt_body_handler (BODY * b, STATE * s)
         handler = mutt_signed_handler;
     }
     else if (m_strcasecmp("encrypted", b->subtype) == 0) {
-      p = mutt_get_parameter ("protocol", b->parameter);
+      p = parameter_getval(b->parameter, "protocol");
 
       if (!p)
         mutt_error (_
index af29c47..57021b1 100644 (file)
@@ -242,7 +242,7 @@ int mutt_is_multipart_signed (BODY * b)
       !b->subtype || ascii_strcasecmp (b->subtype, "signed"))
     return 0;
 
-  if (!(p = mutt_get_parameter ("protocol", b->parameter)))
+  if (!(p = parameter_getval(b->parameter, "protocol")))
     return 0;
 
   if (!(ascii_strcasecmp (p, "multipart/mixed")))
@@ -266,7 +266,7 @@ int mutt_is_multipart_encrypted (BODY * b)
 
   if (!b || b->type != TYPEMULTIPART ||
       !b->subtype || ascii_strcasecmp (b->subtype, "encrypted") ||
-      !(p = mutt_get_parameter ("protocol", b->parameter)) ||
+      !(p = parameter_getval(b->parameter, "protocol")) ||
       ascii_strcasecmp (p, "application/pgp-encrypted"))
     return 0;
 
@@ -282,12 +282,12 @@ int mutt_is_application_pgp (BODY * m)
   if (m->type == TYPEAPPLICATION) {
     if (!ascii_strcasecmp (m->subtype, "pgp")
         || !ascii_strcasecmp (m->subtype, "x-pgp-message")) {
-      if ((p = mutt_get_parameter ("x-action", m->parameter))
+      if ((p = parameter_getval(m->parameter, "x-action"))
           && (!ascii_strcasecmp (p, "sign")
               || !ascii_strcasecmp (p, "signclear")))
         t |= PGPSIGN;
 
-      if ((p = mutt_get_parameter ("format", m->parameter)) &&
+      if ((p = parameter_getval(m->parameter, "format")) &&
           !ascii_strcasecmp (p, "keys-only"))
         t |= PGPKEY;
 
@@ -302,9 +302,9 @@ int mutt_is_application_pgp (BODY * m)
       t |= PGPKEY;
   }
   else if (m->type == TYPETEXT && ascii_strcasecmp ("plain", m->subtype) == 0) {
-    if (((p = mutt_get_parameter ("x-mutt-action", m->parameter))
-         || (p = mutt_get_parameter ("x-action", m->parameter))
-         || (p = mutt_get_parameter ("action", m->parameter)))
+    if (((p = parameter_getval(m->parameter, "x-mutt-action"))
+         || (p = parameter_getval(m->parameter, "x-action"))
+         || (p = parameter_getval(m->parameter, "action")))
         && !ascii_strncasecmp ("pgp-sign", p, 8))
       t |= PGPSIGN;
     else if (p && !ascii_strncasecmp ("pgp-encrypt", p, 11))
@@ -330,7 +330,7 @@ int mutt_is_application_smime (BODY * m)
     /* S/MIME MIME types don't need x- anymore, see RFC2311 */
     if (!ascii_strcasecmp (m->subtype, "x-pkcs7-mime") ||
         !ascii_strcasecmp (m->subtype, "pkcs7-mime")) {
-      if ((t = mutt_get_parameter ("smime-type", m->parameter))) {
+      if ((t = parameter_getval(m->parameter, "smime-type"))) {
         if (!ascii_strcasecmp (t, "enveloped-data"))
           return SMIMEENCRYPT;
         else if (!ascii_strcasecmp (t, "signed-data"))
@@ -349,7 +349,7 @@ int mutt_is_application_smime (BODY * m)
     else if (ascii_strcasecmp (m->subtype, "octet-stream"))
       return 0;
 
-    t = mutt_get_parameter ("name", m->parameter);
+    t = parameter_getval(m->parameter, "name");
 
     if (!t)
       t = m->d_filename;
@@ -679,7 +679,7 @@ int mutt_signed_handler (BODY * a, STATE * s)
   short goodsig = 1;
   int rc = 0;
 
-  protocol = mutt_get_parameter ("protocol", a->parameter);
+  protocol = parameter_getval(a->parameter, "protocol");
   a = a->parts;
 
   /* extract the protocol information */
index 513f121..de9ca87 100644 (file)
@@ -111,6 +111,7 @@ DO_NEW(PARAMETER, parameter);
 DO_DELETE(PARAMETER, parameter);
 DO_SLIST(PARAMETER, parameter, parameter_delete);
 
+char *parameter_getval(PARAMETER *, const char *);
 
 /****************************************************************************/
 /* rfc822 envelopes                                                         */
index 3a8a9ed..e923449 100644 (file)
@@ -48,6 +48,24 @@ const char *BodyEncodings[] = {
     "x-uuencoded",
 };
 
+/****************************************************************************/
+/* rfc822 header parameters                                                 */
+/****************************************************************************/
+
+char *parameter_getval(PARAMETER *parm, const char *s)
+{
+    while (parm) {
+        if (!ascii_strcasecmp(parm->attribute, s))
+            return parm->value;
+        parm = parm->next;
+    }
+    return NULL;
+}
+
+/****************************************************************************/
+/* XXX                                                                      */
+/****************************************************************************/
+
 void rfc1524_entry_wipe(rfc1524_entry *p)
 {
     p_delete(&p->command);
index c2c8058..4fe4f2b 100644 (file)
@@ -106,7 +106,7 @@ int rfc1524_expand_command(BODY *a, const char *filename, const char *mtype,
                 param[z] = '\0';
 
                 m_strcpy(pval, sizeof(pval),
-                         mutt_get_parameter(param, a->parameter));
+                         parameter_getval(a->parameter, param));
 
                 if (option(OPTMAILCAPSANITIZE))
                     mutt_sanitize_filename(pval, 0);
index b93a766..978fa1b 100644 (file)
@@ -138,7 +138,7 @@ int rfc3676_handler (BODY * a, STATE * s) {
   *curline='\0';
 
   /* respect DelSP of RfC3676 only with f=f parts */
-  if ((t = (char*) mutt_get_parameter ("delsp", a->parameter))) {
+  if ((t = parameter_getval(a->parameter, "delsp"))) {
     delsp = m_strlen(t) == 3 && ascii_strncasecmp (t, "yes", 3) == 0;
     t = NULL;
   }
index 3eafd9e..01e968a 100644 (file)
@@ -291,7 +291,7 @@ void mutt_parse_content_type(char *s, BODY *ct)
         /* Some pre-RFC1521 gateways still use the "name=filename" convention,
          * but if a filename has already been set in the content-disposition,
          * let that take precedence, and don't set it here */
-        pc = mutt_get_parameter("name", ct->parameter);
+        pc = parameter_getval(ct->parameter, "name");
         if (pc && !ct->filename)
             ct->filename = m_strdup(pc);
     }
@@ -343,7 +343,7 @@ void mutt_parse_content_type(char *s, BODY *ct)
 
     /* Default character set for text types. */
     if (ct->type == TYPETEXT) {
-        pc = mutt_get_parameter("charset", ct->parameter);
+        pc = parameter_getval(ct->parameter, "charset");
         if (!pc) {
             mutt_set_parameter("charset",
                                option(OPTSTRICTMIME) ? "us-ascii" :
@@ -353,7 +353,7 @@ void mutt_parse_content_type(char *s, BODY *ct)
     }
 }
 
-static void parse_content_disposition(char *s, BODY *ct)
+static void parse_content_disposition(const char *s, BODY *ct)
 {
     if (!ascii_strncasecmp(s, "inline", 6)) {
         ct->disposition = DISPINLINE;
@@ -367,9 +367,9 @@ static void parse_content_disposition(char *s, BODY *ct)
     if ((s = strchr (s, ';'))) {
         PARAMETER *parms = parse_parameters(vskipspaces(s));
 
-        if ((s = mutt_get_parameter("filename", parms)))
+        if ((s = parameter_getval(parms, "filename")))
             m_strreplace(&ct->filename, s);
-        if ((s = mutt_get_parameter ("name", parms)))
+        if ((s = parameter_getval(parms, "name")))
             ct->form_name = m_strdup(s);
 
         parameter_list_wipe(&parms);
@@ -445,7 +445,7 @@ void mutt_parse_part(FILE *fp, BODY *b)
 
     switch (b->type) {
       case TYPEMULTIPART:
-        bound = mutt_get_parameter("boundary", b->parameter);
+        bound = parameter_getval(b->parameter, "boundary");
         fseeko(fp, b->offset, SEEK_SET);
         b->parts = mutt_parse_multipart(fp, bound, b->offset + b->length,
                                         mime_which_token(b->subtype, -1) == MIME_DIGEST);
index 2a5fc3b..5ad138c 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -401,17 +401,6 @@ char *_mutt_expand_path (char *s, ssize_t slen, int rx)
   return (s);
 }
 
-char *mutt_get_parameter (const char *s, PARAMETER * p)
-{
-    while (p) {
-        if (!ascii_strcasecmp(s, p->attribute))
-            return (p->value);
-        p = p->next;
-    }
-
-    return NULL;
-}
-
 void mutt_set_parameter (const char *attribute, const char *value,
                          PARAMETER ** p)
 {
index 1436a84..548e0d1 100644 (file)
@@ -556,9 +556,8 @@ int mutt_prepare_template (FILE * fp, CONTEXT * ctx, HEADER * newhdr,
 
   if (mutt_is_multipart_signed (newhdr->content)) {
     newhdr->security |= SIGN;
-    if (ascii_strcasecmp (mutt_get_parameter
-                          ("protocol", newhdr->content->parameter),
-                          "application/pgp-signature") == 0)
+    if (ascii_strcasecmp(parameter_getval(newhdr->content->parameter, "protocol"),
+                         "application/pgp-signature") == 0)
       newhdr->security |= APPLICATION_PGP;
     else
       newhdr->security |= APPLICATION_SMIME;
@@ -607,7 +606,7 @@ int mutt_prepare_template (FILE * fp, CONTEXT * ctx, HEADER * newhdr,
 
     if (b->type == TYPETEXT) {
       if (!ascii_strcasecmp
-          ("yes", mutt_get_parameter ("x-mutt-noconv", b->parameter)))
+          ("yes", parameter_getval(b->parameter, "x-mutt-noconv")))
         b->noconv = 1;
       else {
         s.flags |= M_CHARCONV;
index 59d18f6..23c197c 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -83,7 +83,6 @@ char *mutt_find_hook (int, const char *);
 char *mutt_gen_msgid (void);
 char *mutt_get_body_charset (char *, ssize_t, BODY *);
 const char *mutt_get_name (address_t *);
-char *mutt_get_parameter (const char *, PARAMETER *);
 const char *mutt_crypt_hook (address_t *);
 char *mutt_make_date (char *, ssize_t);
 
index e92b825..0178db0 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -370,7 +370,8 @@ int mutt_write_mime_header (BODY * a, FILE * f)
 
 int mutt_write_mime_body (BODY * a, FILE * f)
 {
-  char *p, boundary[SHORT_STRING];
+  const char *p;
+  char boundary[SHORT_STRING];
   char send_charset[SHORT_STRING];
   FILE *fpin;
   BODY *t;
@@ -378,7 +379,7 @@ int mutt_write_mime_body (BODY * a, FILE * f)
 
   if (a->type == TYPEMULTIPART) {
     /* First, find the boundary to use */
-    if (!(p = mutt_get_parameter ("boundary", a->parameter))) {
+    if (!(p = parameter_getval(a->parameter, "boundary"))) {
       mutt_error _("No boundary parameter found! [report this error]");
 
       return (-1);
@@ -820,7 +821,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b)
   p_clear(&state, 1);
 
   if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset)) {
-    char *chs = mutt_get_parameter ("charset", b->parameter);
+    const char *chs = parameter_getval(b->parameter, "charset");
     char *fchs = b->use_disp ? ((FileCharset && *FileCharset) ?
                                 FileCharset : Charset) : Charset;
     if (Charset && (chs || SendCharset) &&
@@ -1128,16 +1129,16 @@ void mutt_stamp_attachment (BODY * a)
 
 char *mutt_get_body_charset (char *d, ssize_t dlen, BODY * b)
 {
-  char *p = NULL;
+  const char *p = NULL;
 
   if (b && b->type != TYPETEXT)
     return NULL;
 
   if (b)
-    p = mutt_get_parameter ("charset", b->parameter);
+    p = parameter_getval(b->parameter, "charset");
 
   if (p)
-    charset_canonicalize (d, dlen, NONULL (p));
+    charset_canonicalize (d, dlen, p);
   else
     m_strcpy(d, dlen, "us-ascii");