From 024fe257a96f97619e236bbdafe57b63101eb17f Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Wed, 29 Nov 2006 22:21:16 +0100 Subject: [PATCH] simplifications around mutt_is_message_type Signed-off-by: Pierre Habouzit --- attach.c | 4 ++-- commands.c | 4 ++-- handler.c | 2 +- lib-mime/mime.c | 11 +++++++++ lib-mime/mime.h | 1 + lib-mime/rfc822parse.c | 2 +- recvattach.c | 51 +++++++++++++----------------------------- recvattach.h | 2 -- recvcmd.c | 8 +++---- sendlib.c | 2 +- 10 files changed, 38 insertions(+), 49 deletions(-) diff --git a/attach.c b/attach.c index 5d9b51f..ccc0a8d 100644 --- 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; - 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); @@ -683,7 +683,7 @@ int mutt_save_attachment (FILE * fp, BODY * m, char *path, int flags, 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]; diff --git a/commands.c b/commands.c index 4a40dc9..7c7d869 100644 --- a/commands.c +++ b/commands.c @@ -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 (!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); } - 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) { diff --git a/handler.c b/handler.c index c72ddfc..2ecf577 100644 --- 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) { - 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; diff --git a/lib-mime/mime.c b/lib-mime/mime.c index 9abea0b..43ccfd3 100644 --- a/lib-mime/mime.c +++ b/lib-mime/mime.c @@ -210,6 +210,17 @@ void header_wipe(HEADER *h) /* 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; diff --git a/lib-mime/mime.h b/lib-mime/mime.h index 10b4c86..8e0e0e7 100644 --- a/lib-mime/mime.h +++ b/lib-mime/mime.h @@ -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); +int mutt_is_message_type(BODY *); int mutt_is_multipart_encrypted(BODY *); int mutt_is_multipart_signed(BODY *); int mutt_is_application_pgp(BODY *); diff --git a/lib-mime/rfc822parse.c b/lib-mime/rfc822parse.c index 269b43e..3897114 100644 --- a/lib-mime/rfc822parse.c +++ b/lib-mime/rfc822parse.c @@ -438,7 +438,7 @@ void mutt_parse_part(FILE *fp, BODY *b) 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) { diff --git a/recvattach.c b/recvattach.c index d4ebd3d..b76c43a 100644 --- a/recvattach.c +++ b/recvattach.c @@ -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)) - || 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); @@ -217,8 +217,8 @@ const char *mutt_attach_fmt (char *dest, 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, @@ -235,8 +235,7 @@ const char *mutt_attach_fmt (char *dest, } } 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' */ @@ -369,16 +368,6 @@ int mutt_tag_attach (MUTTMENU * menu, int n, int m) 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) { @@ -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 && - 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; @@ -435,7 +424,7 @@ static int mutt_query_save_attachment (FILE * fp, BODY * body, HEADER * hdr, 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; @@ -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 - && !ascii_strcasecmp (b->subtype, "digest")) + && mime_which_token(b->subtype, -1) == MIME_DIGEST) 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) @@ -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; @@ -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); +#define CHECK_ATTACH \ + if (option(OPTATTACHMSG)) { \ + mutt_flushinp (); \ + mutt_error _("Function not permitted in attach-message mode."); \ + break; \ + } + 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, @@ -1228,6 +1210,5 @@ void mutt_view_attachments (HEADER * hdr) op = OP_NULL; } - /* not reached */ } diff --git a/recvattach.h b/recvattach.h index 96b28d2..cb7c9a6 100644 --- a/recvattach.h +++ b/recvattach.h @@ -31,8 +31,6 @@ const char *mutt_attach_fmt (char *dest, 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); diff --git a/recvcmd.c b/recvcmd.c index 45dec59..0c99da8 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -32,7 +32,7 @@ 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."); @@ -239,8 +239,7 @@ static HEADER *find_common_parent (ATTACHPTR ** idx, short idxlen, 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; @@ -278,8 +277,7 @@ static HEADER *find_parent (ATTACHPTR ** idx, short idxlen, BODY * cur, 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) diff --git a/sendlib.c b/sendlib.c index 2f6c8d7..ff53c45 100644 --- 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); } - else if (mutt_is_message_type (a->type, a->subtype)) { + else if (mutt_is_message_type(a)) { mutt_message_to_7bit (a, fpin); } else { -- 2.20.1