From: Pierre Habouzit Date: Sun, 3 Dec 2006 20:56:23 +0000 (+0100) Subject: code simplifications. X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=07ccefd6c97ddd433d8432f7b4596a5572e09b48 code simplifications. fix IMAP regression. use a lot more mime_which_token Signed-off-by: Pierre Habouzit --- diff --git a/handler.c b/handler.c index 27bfb08..5df2b21 100644 --- a/handler.c +++ b/handler.c @@ -769,7 +769,7 @@ static int alternative_handler (BODY * a, STATE * s) b->parts = mutt_parse_multipart(s->fpin, parameter_getval(a->parameter, "boundary"), (long)st.st_size, - !ascii_strcasecmp("digest", a->subtype)); + mime_which_token(a->subtype, -1) == MIME_DIGEST); } else b = a; @@ -839,18 +839,27 @@ static int alternative_handler (BODY * a, STATE * s) b = a; while (b) { if (b->type == TYPETEXT) { - if (!ascii_strcasecmp ("plain", b->subtype) && type <= TXTPLAIN) { - choice = b; - type = TXTPLAIN; - } - else if (!ascii_strcasecmp ("enriched", b->subtype) - && type <= TXTENRICHED) { - choice = b; - type = TXTENRICHED; - } - else if (!ascii_strcasecmp ("html", b->subtype) && type <= TXTHTML) { - choice = b; - type = TXTHTML; + switch (mime_which_token(b->subtype, -1)) { + case MIME_PLAIN: + if (type <= TXTPLAIN) { + choice = b; + type = TXTPLAIN; + } + break; + case MIME_ENRICHED: + if (type <= TXTENRICHED) { + choice = b; + type = TXTENRICHED; + } + break; + case MIME_HTML: + if (type <= TXTHTML) { + choice = b; + type = TXTHTML; + } + break; + default: + break; } } b = b->next; @@ -946,16 +955,15 @@ int mutt_can_decode (BODY * a) return (1); else if (a->type == TYPEMULTIPART) { BODY *p; + int tok = mime_which_token(a->subtype, -1); - if (ascii_strcasecmp (a->subtype, "signed") == 0 || - ascii_strcasecmp (a->subtype, "encrypted") == 0) - return (1); + if (tok == MIME_SIGNED || tok == MIME_ENCRYPTED) + return 1; for (p = a->parts; p; p = p->next) { if (mutt_can_decode (p)) return (1); } - } else if (a->type == TYPEAPPLICATION) { if (mutt_is_application_pgp(a)) @@ -983,10 +991,10 @@ static int multipart_handler (BODY * a, STATE * s) b->parts = mutt_parse_multipart(s->fpin, parameter_getval(a->parameter, "boundary"), (long)st.st_size, - !ascii_strcasecmp("digest", a->subtype)); - } - else + mime_which_token(a->subtype, -1) == MIME_DIGEST); + } else { b = a; + } for (p = b->parts, count = 1; p; p = p->next, count++) { if (s->flags & M_DISPLAY) { @@ -1171,7 +1179,7 @@ static int external_body_handler (BODY * b, STATE * s) else expire = -1; - if (!ascii_strcasecmp (access_type, "x-mutt-deleted")) { + if (mime_which_token(access_type, -1) == MIME_X_MUTT_DELETED) { if (s->flags & (M_DISPLAY | M_PRINTING)) { char *length; char pretty_size[10]; @@ -1290,6 +1298,7 @@ int mutt_body_handler (BODY * b, STATE * s) int rc = 0; int oflags = s->flags; + int tok = mime_which_token(b->subtype, -1); /* first determine which handler to use to process this part */ @@ -1304,7 +1313,7 @@ int mutt_body_handler (BODY * b, STATE * s) rfc1524_entry_delete(&entry); } else if (b->type == TYPETEXT) { - if (ascii_strcasecmp ("plain", b->subtype) == 0) { + if (tok == MIME_PLAIN) { /* avoid copying this part twice since removing the transfer-encoding is * the only operation needed. */ @@ -1316,7 +1325,7 @@ int mutt_body_handler (BODY * b, STATE * s) else plaintext = 1; } - else if (ascii_strcasecmp ("enriched", b->subtype) == 0) + else if (tok == MIME_ENRICHED) handler = text_enriched_handler; else /* text body type without a handler */ plaintext = 1; @@ -1324,17 +1333,17 @@ int mutt_body_handler (BODY * b, STATE * s) else if (b->type == TYPEMESSAGE) { if (mutt_is_message_type (b)) handler = message_handler; - else if (!ascii_strcasecmp ("delivery-status", b->subtype)) + else if (tok == MIME_DELIVERY_STATUS) plaintext = 1; - else if (!ascii_strcasecmp ("external-body", b->subtype)) + else if (tok == MIME_EXTERNAL_BODY) handler = external_body_handler; } else if (b->type == TYPEMULTIPART) { char *p; - if (ascii_strcasecmp ("alternative", b->subtype) == 0) + if (tok == MIME_ALTERNATIVE) handler = alternative_handler; - else if (ascii_strcasecmp ("signed", b->subtype) == 0) { + else if (tok == MIME_SIGNED) { p = parameter_getval(b->parameter, "protocol"); if (!p) @@ -1343,14 +1352,12 @@ int mutt_body_handler (BODY * b, STATE * s) else if (s->flags & M_VERIFY) handler = mutt_signed_handler; } - else if (m_strcasecmp("encrypted", b->subtype) == 0) { + else if (tok == MIME_ENCRYPTED) { p = parameter_getval(b->parameter, "protocol"); if (!p) - mutt_error (_ - ("Error: multipart/encrypted has no protocol parameter!")); - - else if (ascii_strcasecmp ("application/pgp-encrypted", p) == 0) + mutt_error(_("Error: multipart/encrypted has no protocol parameter!")); + else if (tok == MIME_APPLICATION_PGP_ENCRYPTED) handler = crypt_pgp_encrypted_handler; } @@ -1364,7 +1371,6 @@ int mutt_body_handler (BODY * b, STATE * s) handler = crypt_smime_application_smime_handler; } - if (plaintext || handler) { fseeko (s->fpin, b->offset, 0); diff --git a/imap/imap.c b/imap/imap.c index 4b85e28..a17cb8f 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -238,14 +238,14 @@ static int imap_get_delim (IMAP_DATA * idata) * than getting the delim wrong */ idata->delim = '/'; - imap_cmd_start (idata, "string_list_t \"\" \"\""); + imap_cmd_start (idata, "LIST\"\" \"\""); do { if ((rc = imap_cmd_step (idata)) != IMAP_CMD_CONTINUE) break; s = imap_next_word (idata->cmd.buf); - if (ascii_strncasecmp ("string_list_t", s, 4) == 0) { + if (ascii_strncasecmp ("LIST", s, 4) == 0) { s = imap_next_word (s); s = imap_next_word (s); if (s && s[0] == '\"' && s[1] && s[2] == '\"') diff --git a/lib-mime/mime-token.def b/lib-mime/mime-token.def index 5a638ba..0edef85 100644 --- a/lib-mime/mime-token.def +++ b/lib-mime/mime-token.def @@ -4,10 +4,10 @@ alternative apparently-from apparently-to application -application/postscript application/pgp-encrypted application/pgp-signature application/pkcs7-signature +application/postscript application/x-pkcs7-signature audio base64 @@ -35,6 +35,7 @@ expires external-body followup-to from +html image in-reply-to iso-2022-jp @@ -90,6 +91,7 @@ video x-comment-to x-convert x-label +x-mutt-deleted x-pgp-message x-pkcs7-mime xref diff --git a/send.c b/send.c index 3b51b00..86a6f35 100644 --- a/send.c +++ b/send.c @@ -285,66 +285,83 @@ static char *nntp_get_header(const char *s) static void process_user_recips (ENVELOPE * env) { - string_list_t *uh = UserHeader; + string_list_t *uh = UserHeader; - for (; uh; uh = uh->next) { - if (ascii_strncasecmp ("to:", uh->data, 3) == 0) - env->to = rfc822_parse_adrlist (env->to, uh->data + 3); - else if (ascii_strncasecmp ("cc:", uh->data, 3) == 0) - env->cc = rfc822_parse_adrlist (env->cc, uh->data + 3); - else if (ascii_strncasecmp ("bcc:", uh->data, 4) == 0) - env->bcc = rfc822_parse_adrlist (env->bcc, uh->data + 4); + for (; uh; uh = uh->next) { + const char *p = strchr(uh->data, ':'); + if (!p) + continue; + + switch (mime_which_token(uh->data, p - uh->data)) { + case MIME_TO: + env->to = rfc822_parse_adrlist(env->to, p); + break; + case MIME_CC: + env->cc = rfc822_parse_adrlist(env->cc, p); + break; + case MIME_BCC: + env->bcc = rfc822_parse_adrlist(env->bcc, p); + break; #ifdef USE_NNTP - else if (ascii_strncasecmp ("newsgroups:", uh->data, 11) == 0) - env->newsgroups = nntp_get_header (uh->data + 11); - else if (ascii_strncasecmp ("followup-to:", uh->data, 12) == 0) - env->followup_to = nntp_get_header (uh->data + 12); - else if (ascii_strncasecmp ("x-comment-to:", uh->data, 13) == 0) - env->x_comment_to = nntp_get_header (uh->data + 13); + case MIME_NEWSGROUPS: + env->newsgroups = nntp_get_header(p); + break; + case MIME_FOLLOWUP_TO: + env->followup_to = nntp_get_header(p); + break; + case MIME_X_COMMENT_TO: + env->x_comment_to = nntp_get_header(p); + break; #endif - } + default: break; + } + } } -static void process_user_header (ENVELOPE * env) +static void process_user_header(ENVELOPE * env) { - string_list_t *uh = UserHeader; - string_list_t *last = env->userhdrs; - - if (last) - while (last->next) - last = last->next; - - for (; uh; uh = uh->next) { - if (ascii_strncasecmp ("from:", uh->data, 5) == 0) { - /* User has specified a default From: address. Remove default address */ - address_list_wipe(&env->from); - env->from = rfc822_parse_adrlist (env->from, uh->data + 5); - } - else if (ascii_strncasecmp ("reply-to:", uh->data, 9) == 0) { - address_list_wipe(&env->reply_to); - env->reply_to = rfc822_parse_adrlist (env->reply_to, uh->data + 9); - } - else if (ascii_strncasecmp ("message-id:", uh->data, 11) == 0) - m_strreplace(&env->message_id, uh->data + 11); - else if (ascii_strncasecmp ("to:", uh->data, 3) != 0 && - ascii_strncasecmp ("cc:", uh->data, 3) != 0 && - ascii_strncasecmp ("bcc:", uh->data, 4) != 0 && + string_list_t *uh; + string_list_t **last = string_list_last(&env->userhdrs); + + for (uh = UserHeader; uh; uh = uh->next) { + const char *p = strchr(uh->data, ':'); + + switch (mime_which_token(uh->data, (p ?: uh->data) - uh->data)) { + case MIME_FROM: + /* User has specified a default From: address. Remove default address */ + address_list_wipe(&env->from); + env->from = rfc822_parse_adrlist(env->from, p); + break; + + case MIME_REPLY_TO: + address_list_wipe(&env->reply_to); + env->reply_to = rfc822_parse_adrlist (env->reply_to, p); + break; + + case MIME_MESSAGE_ID: + m_strreplace(&env->message_id, p); + break; + + case MIME_TO: + case MIME_CC: + case MIME_BCC: #ifdef USE_NNTP - ascii_strncasecmp ("newsgroups:", uh->data, 11) != 0 && - ascii_strncasecmp ("followup-to:", uh->data, 12) != 0 && - ascii_strncasecmp ("x-comment-to:", uh->data, 13) != 0 && + case MIME_NEWSGROUPS: + case MIME_FOLLOWUP_TO: + case MIME_X_COMMENT_TO: #endif - ascii_strncasecmp ("supersedes:", uh->data, 11) != 0 && - ascii_strncasecmp ("subject:", uh->data, 8) != 0) { - if (last) { - last->next = string_item_new(); - last = last->next; - } - else - last = env->userhdrs = string_item_new(); - last->data = m_strdup(uh->data); + case MIME_SUPERSEDES: + case MIME_SUPERCEDES: + case MIME_SUBJECT: + break; + + default: + *last = string_item_new(); + (*last)->data = m_strdup(uh->data); + last = &(*last)->next; + break; + } } - } } void mutt_forward_intro (FILE * fp, HEADER * cur)