small regressions.
[apps/madmutt.git] / send.c
diff --git a/send.c b/send.c
index 82579d5..acb01af 100644 (file)
--- a/send.c
+++ b/send.c
@@ -285,66 +285,85 @@ 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, ':');
+        if (!p)
+          continue;
+
+        switch (mime_which_token(uh->data, p++ - 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)
@@ -910,7 +929,7 @@ void mutt_set_followup_to (ENVELOPE * e)
    from field */
 static address_t *set_reverse_name (ENVELOPE * env)
 {
-    address_t *tmp;
+    address_t *tmp = NULL;
 
     for (tmp = env->to; tmp; tmp = tmp->next) {
         if (mutt_addr_is_user(tmp))
@@ -924,6 +943,8 @@ static address_t *set_reverse_name (ENVELOPE * env)
     if (!mutt_addr_is_user(env->from))
         return NULL;
 
+    tmp = env->from;
+
   found:
     tmp = address_dup(tmp);
     if (!option(OPTREVREAL) || !tmp->personal) {