simplifications around mutt_is_message_type
authorPierre Habouzit <madcoder@debian.org>
Wed, 29 Nov 2006 21:21:16 +0000 (22:21 +0100)
committerPierre Habouzit <madcoder@debian.org>
Wed, 29 Nov 2006 21:21:16 +0000 (22:21 +0100)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
attach.c
commands.c
handler.c
lib-mime/mime.c
lib-mime/mime.h
lib-mime/rfc822parse.c
recvattach.c
recvattach.h
recvcmd.c
sendlib.c

index 5d9b51f..ccc0a8d 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -375,7 +375,7 @@ int mutt_view_attachment (FILE * fp, BODY * a, int flag, HEADER * hdr,
   int unlink_tempfile = 0;
   int pagerfd = -1;
 
   int unlink_tempfile = 0;
   int pagerfd = -1;
 
-  is_message = mutt_is_message_type (a->type, a->subtype);
+  is_message = mutt_is_message_type(a);
   if (is_message && a->hdr && (a->hdr->security & ENCRYPT) &&
       !crypt_valid_passphrase (a->hdr->security))
     return (rc);
   if (is_message && a->hdr && (a->hdr->security & ENCRYPT) &&
       !crypt_valid_passphrase (a->hdr->security))
     return (rc);
@@ -683,7 +683,7 @@ int mutt_save_attachment (FILE * fp, BODY * m, char *path, int flags,
         m->hdr &&
         m->encoding != ENCBASE64 &&
         m->encoding != ENCQUOTEDPRINTABLE &&
         m->hdr &&
         m->encoding != ENCBASE64 &&
         m->encoding != ENCQUOTEDPRINTABLE &&
-        mutt_is_message_type (m->type, m->subtype)) {
+        mutt_is_message_type(m)) {
       /* message type attachments are written to mail folders. */
 
       char buf[HUGE_STRING];
       /* message type attachments are written to mail folders. */
 
       char buf[HUGE_STRING];
index 4a40dc9..7c7d869 100644 (file)
@@ -853,12 +853,12 @@ void mutt_edit_content_type (HEADER * h, BODY * b, FILE * fp)
 
   if (!is_multipart(b) && b->parts)
     body_list_wipe(&b->parts);
 
   if (!is_multipart(b) && b->parts)
     body_list_wipe(&b->parts);
-  if (!mutt_is_message_type (b->type, b->subtype) && b->hdr) {
+  if (!mutt_is_message_type(b) && b->hdr) {
     b->hdr->content = NULL;
     header_delete(&b->hdr);
   }
 
     b->hdr->content = NULL;
     header_delete(&b->hdr);
   }
 
-  if (fp && (is_multipart(b) || mutt_is_message_type(b->type, b->subtype)))
+  if (fp && (is_multipart(b) || mutt_is_message_type(b)))
     mutt_parse_part (fp, b);
 
   if (h) {
     mutt_parse_part (fp, b);
 
   if (h) {
index c72ddfc..2ecf577 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -1329,7 +1329,7 @@ int mutt_body_handler (BODY * b, STATE * s)
       plaintext = 1;
   }
   else if (b->type == TYPEMESSAGE) {
       plaintext = 1;
   }
   else if (b->type == TYPEMESSAGE) {
-    if (mutt_is_message_type (b->type, b->subtype))
+    if (mutt_is_message_type (b))
       handler = message_handler;
     else if (!ascii_strcasecmp ("delivery-status", b->subtype))
       plaintext = 1;
       handler = message_handler;
     else if (!ascii_strcasecmp ("delivery-status", b->subtype))
       plaintext = 1;
index 9abea0b..43ccfd3 100644 (file)
@@ -210,6 +210,17 @@ void header_wipe(HEADER *h)
 /* misc functions                                                           */
 /****************************************************************************/
 
 /* misc functions                                                           */
 /****************************************************************************/
 
+int mutt_is_message_type(BODY *b)
+{
+    int tok;
+
+    if (b->type != TYPEMESSAGE)
+        return 0;
+
+    tok = mime_which_token(b->subtype, -1);
+    return tok == MIME_RFC822 || tok == MIME_NEWS;
+}
+
 int mutt_is_text_part(BODY * b)
 {
     char *s = b->subtype;
 int mutt_is_text_part(BODY * b)
 {
     char *s = b->subtype;
index 10b4c86..8e0e0e7 100644 (file)
@@ -101,6 +101,7 @@ string_list_t **mutt_parse_rfc822_line(ENVELOPE *, HEADER *, char *line, char *p
 ENVELOPE *mutt_read_rfc822_header(FILE *, HEADER *, short, short);
 int mutt_count_body_parts (HEADER *hdr, int flags);
 
 ENVELOPE *mutt_read_rfc822_header(FILE *, HEADER *, short, short);
 int mutt_count_body_parts (HEADER *hdr, int flags);
 
+int mutt_is_message_type(BODY *);
 int mutt_is_multipart_encrypted(BODY *);
 int mutt_is_multipart_signed(BODY *);
 int mutt_is_application_pgp(BODY *);
 int mutt_is_multipart_encrypted(BODY *);
 int mutt_is_multipart_signed(BODY *);
 int mutt_is_application_pgp(BODY *);
index 269b43e..3897114 100644 (file)
@@ -438,7 +438,7 @@ void mutt_parse_part(FILE *fp, BODY *b)
         if (b->subtype) {
             fseeko(fp, b->offset, SEEK_SET);
 
         if (b->subtype) {
             fseeko(fp, b->offset, SEEK_SET);
 
-            if (mutt_is_message_type(b->type, b->subtype)) {
+            if (mutt_is_message_type(b)) {
                 b->parts = mutt_parse_messageRFC822(fp, b);
             } else
             if (mime_which_token(b->subtype, -1) == MIME_EXTERNAL_BODY) {
                 b->parts = mutt_parse_messageRFC822(fp, b);
             } else
             if (mime_which_token(b->subtype, -1) == MIME_EXTERNAL_BODY) {
index d4ebd3d..b76c43a 100644 (file)
@@ -142,7 +142,7 @@ ATTACHPTR **mutt_gen_attach_list (BODY * m,
       /* We don't support multipart messages in the compose menu yet */
       if (!compose && !m->collapsed
       &&  ((m->type == TYPEMULTIPART && !mutt_is_multipart_encrypted(m))
       /* We don't support multipart messages in the compose menu yet */
       if (!compose && !m->collapsed
       &&  ((m->type == TYPEMULTIPART && !mutt_is_multipart_encrypted(m))
-      ||  mutt_is_message_type (m->type, m->subtype)))
+      ||  mutt_is_message_type(m)))
       {
         idx = mutt_gen_attach_list (m->parts, m->type, idx, idxlen, idxmax,
                                     level + 1, compose);
       {
         idx = mutt_gen_attach_list (m->parts, m->type, idx, idxlen, idxmax,
                                     level + 1, compose);
@@ -217,8 +217,8 @@ const char *mutt_attach_fmt (char *dest,
         mutt_format_s (dest, destlen, prefix, aptr->content->description);
         break;
       }
         mutt_format_s (dest, destlen, prefix, aptr->content->description);
         break;
       }
-      if (mutt_is_message_type (aptr->content->type, aptr->content->subtype)
-          && MsgFmt && aptr->content->hdr) {
+      if (mutt_is_message_type(aptr->content) && MsgFmt && aptr->content->hdr)
+      {
         char s[SHORT_STRING];
 
         _mutt_make_string (s, sizeof (s), MsgFmt, NULL, aptr->content->hdr,
         char s[SHORT_STRING];
 
         _mutt_make_string (s, sizeof (s), MsgFmt, NULL, aptr->content->hdr,
@@ -235,8 +235,7 @@ const char *mutt_attach_fmt (char *dest,
       }
     }
     else if (aptr->content->description ||
       }
     }
     else if (aptr->content->description ||
-             (mutt_is_message_type
-              (aptr->content->type, aptr->content->subtype)
+             (mutt_is_message_type(aptr->content)
               && MsgFmt && aptr->content->hdr))
       break;
     /* FALLS THROUGH TO 'f' */
               && MsgFmt && aptr->content->hdr))
       break;
     /* FALLS THROUGH TO 'f' */
@@ -369,16 +368,6 @@ int mutt_tag_attach (MUTTMENU * menu, int n, int m)
   return cur->tagged - ot;
 }
 
   return cur->tagged - ot;
 }
 
-int mutt_is_message_type (int type, const char *subtype)
-{
-  if (type != TYPEMESSAGE)
-    return 0;
-
-  subtype = NONULL (subtype);
-  return (ascii_strcasecmp (subtype, "rfc822") == 0
-          || ascii_strcasecmp (subtype, "news") == 0);
-}
-
 static int mutt_query_save_attachment (FILE * fp, BODY * body, HEADER * hdr,
                                        char **directory)
 {
 static int mutt_query_save_attachment (FILE * fp, BODY * body, HEADER * hdr,
                                        char **directory)
 {
@@ -400,7 +389,7 @@ static int mutt_query_save_attachment (FILE * fp, BODY * body, HEADER * hdr,
   else if (body->hdr &&
            body->encoding != ENCBASE64 &&
            body->encoding != ENCQUOTEDPRINTABLE &&
   else if (body->hdr &&
            body->encoding != ENCBASE64 &&
            body->encoding != ENCQUOTEDPRINTABLE &&
-           mutt_is_message_type (body->type, body->subtype))
+           mutt_is_message_type(body))
     mutt_default_save (buf, sizeof (buf), body->hdr);
   else
     buf[0] = 0;
     mutt_default_save (buf, sizeof (buf), body->hdr);
   else
     buf[0] = 0;
@@ -435,7 +424,7 @@ static int mutt_query_save_attachment (FILE * fp, BODY * body, HEADER * hdr,
                   body->hdr &&
                   body->encoding != ENCBASE64 &&
                   body->encoding != ENCQUOTEDPRINTABLE &&
                   body->hdr &&
                   body->encoding != ENCBASE64 &&
                   body->encoding != ENCQUOTEDPRINTABLE &&
-                  mutt_is_message_type (body->type, body->subtype));
+                  mutt_is_message_type(body));
 
     if (is_message) {
       struct stat st;
 
     if (is_message) {
       struct stat st;
@@ -842,10 +831,9 @@ static void attach_collapse (BODY * b, short collapse, short init,
   for (; b; b = b->next) {
     i = init || b->collapsed;
     if (i && option (OPTDIGESTCOLLAPSE) && b->type == TYPEMULTIPART
   for (; b; b = b->next) {
     i = init || b->collapsed;
     if (i && option (OPTDIGESTCOLLAPSE) && b->type == TYPEMULTIPART
-        && !ascii_strcasecmp (b->subtype, "digest"))
+        && mime_which_token(b->subtype, -1) == MIME_DIGEST)
       attach_collapse (b->parts, 1, 1, 0);
       attach_collapse (b->parts, 1, 1, 0);
-    else if (b->type == TYPEMULTIPART
-             || mutt_is_message_type (b->type, b->subtype))
+    else if (b->type == TYPEMULTIPART || mutt_is_message_type(b))
       attach_collapse (b->parts, collapse, i, 0);
     b->collapsed = collapse;
     if (just_one)
       attach_collapse (b->parts, collapse, i, 0);
     b->collapsed = collapse;
     if (just_one)
@@ -863,19 +851,6 @@ void mutt_attach_init (BODY * b)
   }
 }
 
   }
 }
 
-static const char *Function_not_permitted =
-N_("Function not permitted in attach-message mode.");
-
-#define CHECK_ATTACH if(option(OPTATTACHMSG)) \
-                    {\
-                       mutt_flushinp (); \
-                       mutt_error _(Function_not_permitted); \
-                       break; \
-                    }
-
-
-
-
 void mutt_view_attachments (HEADER * hdr)
 {
   int secured = 0;
 void mutt_view_attachments (HEADER * hdr)
 {
   int secured = 0;
@@ -966,9 +941,16 @@ void mutt_view_attachments (HEADER * hdr)
   attach_collapse (cur, 0, 1, 0);
   mutt_update_attach_index (cur, &idx, &idxlen, &idxmax, menu);
 
   attach_collapse (cur, 0, 1, 0);
   mutt_update_attach_index (cur, &idx, &idxlen, &idxmax, menu);
 
+#define CHECK_ATTACH \
+    if (option(OPTATTACHMSG)) {                                         \
+        mutt_flushinp ();                                               \
+        mutt_error _("Function not permitted in attach-message mode."); \
+        break;                                                          \
+    }
+
   for (;;) {
     if (op == OP_NULL)
   for (;;) {
     if (op == OP_NULL)
-      op = mutt_menuLoop (menu);
+      op = mutt_menuLoop(menu);
     switch (op) {
     case OP_ATTACH_VIEW_MAILCAP:
       mutt_view_attachment (fp, idx[menu->current]->content, M_MAILCAP,
     switch (op) {
     case OP_ATTACH_VIEW_MAILCAP:
       mutt_view_attachment (fp, idx[menu->current]->content, M_MAILCAP,
@@ -1228,6 +1210,5 @@ void mutt_view_attachments (HEADER * hdr)
 
     op = OP_NULL;
   }
 
     op = OP_NULL;
   }
-
   /* not reached */
 }
   /* not reached */
 }
index 96b28d2..cb7c9a6 100644 (file)
@@ -31,8 +31,6 @@ const char *mutt_attach_fmt (char *dest,
 
 int mutt_tag_attach (MUTTMENU * menu, int n, int m);
 
 
 int mutt_tag_attach (MUTTMENU * menu, int n, int m);
 
-int mutt_is_message_type (int, const char *);
-
 void mutt_save_attachment_list (FILE * fp, int tag, BODY * top, HEADER * hdr,
                                 MUTTMENU * menu);
 
 void mutt_save_attachment_list (FILE * fp, int tag, BODY * top, HEADER * hdr,
                                 MUTTMENU * menu);
 
index 45dec59..0c99da8 100644 (file)
--- a/recvcmd.c
+++ b/recvcmd.c
@@ -32,7 +32,7 @@
 
 static short check_msg (BODY * b, short err)
 {
 
 static short check_msg (BODY * b, short err)
 {
-  if (!mutt_is_message_type (b->type, b->subtype)) {
+  if (!mutt_is_message_type(b)) {
     if (err)
       mutt_error _("You may only bounce message/rfc822 parts.");
 
     if (err)
       mutt_error _("You may only bounce message/rfc822 parts.");
 
@@ -239,8 +239,7 @@ static HEADER *find_common_parent (ATTACHPTR ** idx, short idxlen,
       break;
 
   while (--i >= 0) {
       break;
 
   while (--i >= 0) {
-    if (mutt_is_message_type
-        (idx[i]->content->type, idx[i]->content->subtype)) {
+    if (mutt_is_message_type(idx[i]->content)) {
       nchildren = count_tagged_children (idx, idxlen, i);
       if (nchildren == nattach)
         return idx[i]->content->hdr;
       nchildren = count_tagged_children (idx, idxlen, i);
       if (nchildren == nattach)
         return idx[i]->content->hdr;
@@ -278,8 +277,7 @@ static HEADER *find_parent (ATTACHPTR ** idx, short idxlen, BODY * cur,
 
   if (cur) {
     for (i = 0; i < idxlen; i++) {
 
   if (cur) {
     for (i = 0; i < idxlen; i++) {
-      if (mutt_is_message_type
-          (idx[i]->content->type, idx[i]->content->subtype)
+      if (mutt_is_message_type(idx[i]->content)
           && is_parent (i, idx, idxlen, cur))
         parent = idx[i]->content->hdr;
       if (idx[i]->content == cur)
           && is_parent (i, idx, idxlen, cur))
         parent = idx[i]->content->hdr;
       if (idx[i]->content == cur)
index 2f6c8d7..ff53c45 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -982,7 +982,7 @@ static void transform_to_7bit (BODY * a, FILE * fpin)
 
       transform_to_7bit (a->parts, fpin);
     }
 
       transform_to_7bit (a->parts, fpin);
     }
-    else if (mutt_is_message_type (a->type, a->subtype)) {
+    else if (mutt_is_message_type(a)) {
       mutt_message_to_7bit (a, fpin);
     }
     else {
       mutt_message_to_7bit (a, fpin);
     }
     else {