]> granicus.if.org Git - neomutt/commitdiff
move address functions
authorRichard Russon <rich@flatcap.org>
Tue, 28 Nov 2017 20:21:44 +0000 (20:21 +0000)
committerRichard Russon <rich@flatcap.org>
Wed, 29 Nov 2017 00:29:10 +0000 (00:29 +0000)
address.c
address.h
commands.c
compose.c
edit.c
init.c
mbox.c
parse.c
protos.h
send.c

index 8e5f90e813430f8742c79628259e769de11b74aa..f95865c9606075f50fe008d900c81094fefbf9cc 100644 (file)
--- a/address.c
+++ b/address.c
  *
  * | Function                     | Description
  * | :--------------------------- | :---------------------------------------------------------
- * | addrcmp()                    | compare two e-mail addresses
- * | addrsrc()                    | Search for an e-mail address in a list
- * | has_recips()                 | Count the number of Addresses with valid recipients
- * | mutt_parse_adrlist()         | Parse a list of email addresses
+ * | mutt_addr_cmp()                    | compare two e-mail addresses
+ * | mutt_addr_search()                    | Search for an e-mail address in a list
+ * | mutt_addr_has_recips()                 | Count the number of Addresses with valid recipients
+ * | mutt_addr_parse_list2()         | Parse a list of email addresses
  * | mutt_addr_append()           | Append one list of addresses onto another
  * | mutt_addr_cat()              | Copy a string and escape the specified characters
  * | mutt_addr_copy_list()        | Copy an Address
@@ -642,6 +642,39 @@ struct Address *mutt_addr_parse_list(struct Address *top, const char *s)
   return top;
 }
 
+/**
+ * mutt_addr_parse_list2 - Parse a list of email addresses
+ * @param p Add to this List of Addresses
+ * @param s String to parse
+ * @retval ptr Head of the list of addresses
+ *
+ * The email addresses can be separated by whitespace or commas.
+ */
+struct Address *mutt_addr_parse_list2(struct Address *p, const char *s)
+{
+  const char *q = NULL;
+
+  /* check for a simple whitespace separated list of addresses */
+  q = strpbrk(s, "\"<>():;,\\");
+  if (!q)
+  {
+    char tmp[HUGE_STRING];
+    char *r = NULL;
+
+    mutt_str_strfcpy(tmp, s, sizeof(tmp));
+    r = tmp;
+    while ((r = strtok(r, " \t")) != NULL)
+    {
+      p = mutt_addr_parse_list(p, r);
+      r = NULL;
+    }
+  }
+  else
+    p = mutt_addr_parse_list(p, s);
+
+  return p;
+}
+
 /**
  * mutt_addr_qualify - Expand local names in an Address list using a hostname
  * @param addr Address list
@@ -823,3 +856,79 @@ bool mutt_addr_valid_msgid(const char *msgid)
 
   return true;
 }
+
+/**
+ * mutt_addr_cmp_strict - Strictly compare two Address lists
+ * @param a First Address
+ * @param b Second Address
+ * @retval true Address lists are strictly identical
+ */
+int mutt_addr_cmp_strict(const struct Address *a, const struct Address *b)
+{
+  while (a && b)
+  {
+    if ((mutt_str_strcmp(a->mailbox, b->mailbox) != 0) ||
+        (mutt_str_strcmp(a->personal, b->personal) != 0))
+    {
+      return 0;
+    }
+
+    a = a->next;
+    b = b->next;
+  }
+  if (a || b)
+    return 0;
+
+  return 1;
+}
+
+/**
+ * mutt_addr_has_recips - Count the number of Addresses with valid recipients
+ * @param a Address list
+ * @retval num Number of valid Addresses
+ *
+ * An Address has a recipient if the mailbox or group is set.
+ */
+int mutt_addr_has_recips(struct Address *a)
+{
+  int c = 0;
+
+  for (; a; a = a->next)
+  {
+    if (!a->mailbox || a->group)
+      continue;
+    c++;
+  }
+  return c;
+}
+
+/**
+ * mutt_addr_cmp - compare two e-mail addresses
+ * @param a Address 1
+ * @param b Address 2
+ * @retval true if they are equivalent
+ */
+bool mutt_addr_cmp(struct Address *a, struct Address *b)
+{
+  if (!a->mailbox || !b->mailbox)
+    return false;
+  if (mutt_str_strcasecmp(a->mailbox, b->mailbox) != 0)
+    return false;
+  return true;
+}
+
+/**
+ * mutt_addr_search - Search for an e-mail address in a list
+ * @param a   Address containing the search email
+ * @param lst Address List
+ * @retval true If the Address is in the list
+ */
+int mutt_addr_search(struct Address *a, struct Address *lst)
+{
+  for (; lst; lst = lst->next)
+  {
+    if (mutt_addr_cmp(a, lst))
+      return 1;
+  }
+  return 0;
+}
index 609491f3c13f996235d086ac590c77da7359aa0e..04ba47597237be850a6a33f2357a83bd040d476a 100644 (file)
--- a/address.h
+++ b/address.h
@@ -51,18 +51,21 @@ enum AddressError
   ERR_BAD_ADDR_SPEC
 };
 
-struct Address *mutt_addr_new(void);
-void mutt_addr_free(struct Address **p);
-void mutt_addr_qualify(struct Address *addr, const char *host);
-struct Address *mutt_addr_parse_list(struct Address *top, const char *s);
+struct Address *mutt_addr_append(struct Address **a, struct Address *b, int prune);
+void            mutt_addr_cat(char *buf, size_t buflen, const char *value, const char *specials);
+int             mutt_addr_cmp_strict(const struct Address *a, const struct Address *b);
+bool            mutt_addr_cmp(struct Address *a, struct Address *b);
 struct Address *mutt_addr_copy_list(struct Address *addr, int prune);
 struct Address *mutt_addr_copy(struct Address *addr);
-struct Address *mutt_addr_append(struct Address **a, struct Address *b, int prune);
-int rfc822_write_address(char *buf, size_t buflen, struct Address *addr, int display);
-void rfc822_write_address_single(char *buf, size_t buflen, struct Address *addr, int display);
-void mutt_addr_cat(char *buf, size_t buflen, const char *value, const char *specials);
-bool mutt_addr_valid_msgid(const char *msgid);
-int mutt_addr_remove_from_list(struct Address **a, const char *mailbox);
+void            mutt_addr_free(struct Address **p);
+int             mutt_addr_has_recips(struct Address *a);
+struct Address *mutt_addr_new(void);
+struct Address *mutt_addr_parse_list2(struct Address *p, const char *s);
+struct Address *mutt_addr_parse_list(struct Address *top, const char *s);
+void            mutt_addr_qualify(struct Address *addr, const char *host);
+int             mutt_addr_remove_from_list(struct Address **a, const char *mailbox);
+int             mutt_addr_search(struct Address *a, struct Address *lst);
+bool            mutt_addr_valid_msgid(const char *msgid);
 
 extern int RFC822Error;
 extern const char *const RFC822Errors[];
index b70fcc5c8a1f3735b917ce7bfc53efbe5171a68b..bc62250dfcccf3f63378afa626d33e86bd7e917f 100644 (file)
@@ -299,7 +299,7 @@ void ci_bounce_message(struct Header *h)
   if (rc || !buf[0])
     return;
 
-  adr = mutt_parse_adrlist(adr, buf);
+  adr = mutt_addr_parse_list2(adr, buf);
   if (!adr)
   {
     mutt_error(_("Error parsing address!"));
index c113ad20299e61c189e532e3d4cbaff07a78d9e0..310ee16fecffdbdd2ff0b1ecd1138d0e8d91e36e 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -475,7 +475,7 @@ static void edit_address_list(int line, struct Address **addr)
   if (mutt_get_field(_(Prompts[line]), buf, sizeof(buf), MUTT_ALIAS) == 0)
   {
     mutt_addr_free(addr);
-    *addr = mutt_parse_adrlist(*addr, buf);
+    *addr = mutt_addr_parse_list2(*addr, buf);
     *addr = mutt_expand_aliases(*addr);
   }
 
diff --git a/edit.c b/edit.c
index 66fbadd78cd8ee044928b1d084d1c0f32a95c738..80e07c6f228be7674d9d578cbc56febf3974dbdc 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -263,7 +263,7 @@ static void be_edit_header(struct Envelope *e, int force)
     if (mutt_enter_string(tmp, sizeof(tmp), 4, 0) == 0)
     {
       mutt_addr_free(&e->to);
-      e->to = mutt_parse_adrlist(e->to, tmp);
+      e->to = mutt_addr_parse_list2(e->to, tmp);
       e->to = mutt_expand_aliases(e->to);
       mutt_addrlist_to_intl(e->to, NULL); /* XXX - IDNA error reporting? */
       tmp[0] = '\0';
@@ -296,7 +296,7 @@ static void be_edit_header(struct Envelope *e, int force)
     if (mutt_enter_string(tmp, sizeof(tmp), 4, 0) == 0)
     {
       mutt_addr_free(&e->cc);
-      e->cc = mutt_parse_adrlist(e->cc, tmp);
+      e->cc = mutt_addr_parse_list2(e->cc, tmp);
       e->cc = mutt_expand_aliases(e->cc);
       tmp[0] = '\0';
       mutt_addrlist_to_intl(e->cc, NULL);
@@ -317,7 +317,7 @@ static void be_edit_header(struct Envelope *e, int force)
     if (mutt_enter_string(tmp, sizeof(tmp), 5, 0) == 0)
     {
       mutt_addr_free(&e->bcc);
-      e->bcc = mutt_parse_adrlist(e->bcc, tmp);
+      e->bcc = mutt_addr_parse_list2(e->bcc, tmp);
       e->bcc = mutt_expand_aliases(e->bcc);
       mutt_addrlist_to_intl(e->bcc, NULL);
       tmp[0] = '\0';
@@ -374,11 +374,11 @@ int mutt_builtin_editor(const char *path, struct Header *msg, struct Header *cur
           addstr(_(EditorHelp2));
           break;
         case 'b':
-          msg->env->bcc = mutt_parse_adrlist(msg->env->bcc, p);
+          msg->env->bcc = mutt_addr_parse_list2(msg->env->bcc, p);
           msg->env->bcc = mutt_expand_aliases(msg->env->bcc);
           break;
         case 'c':
-          msg->env->cc = mutt_parse_adrlist(msg->env->cc, p);
+          msg->env->cc = mutt_addr_parse_list2(msg->env->cc, p);
           msg->env->cc = mutt_expand_aliases(msg->env->cc);
           break;
         case 'h':
diff --git a/init.c b/init.c
index 9975a00ecbc0ae40dc84a95eebaed27eae764050..353e4bbf5467dba877d693fec2adf997825f1b2e 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1502,7 +1502,7 @@ static int parse_group(struct Buffer *buf, struct Buffer *s, unsigned long data,
           break;
 
         case GS_ADDR:
-          addr = mutt_parse_adrlist(NULL, buf->data);
+          addr = mutt_addr_parse_list2(NULL, buf->data);
           if (!addr)
             goto bail;
           if (mutt_addrlist_to_intl(addr, &estr))
@@ -1941,7 +1941,7 @@ static int parse_alias(struct Buffer *buf, struct Buffer *s, unsigned long data,
   mutt_extract_token(buf, s, MUTT_TOKEN_QUOTE | MUTT_TOKEN_SPACE | MUTT_TOKEN_SEMICOLON);
   mutt_debug(3, "Second token is '%s'.\n", buf->data);
 
-  tmp->addr = mutt_parse_adrlist(tmp->addr, buf->data);
+  tmp->addr = mutt_addr_parse_list2(tmp->addr, buf->data);
 
   if (last)
     last->next = tmp;
diff --git a/mbox.c b/mbox.c
index 72d9758d140b7801d4be3d5c9830626911f2b2b2..4714085b39629ca3e85c7769fc36073844e3e94a 100644 (file)
--- a/mbox.c
+++ b/mbox.c
@@ -552,31 +552,6 @@ static int mbox_open_new_message(struct Message *msg, struct Context *dest, stru
   return 0;
 }
 
-/**
- * strict_addrcmp - Strictly compare two Address lists
- * @param a First Address
- * @param b Second Address
- * @retval true Address lists are strictly identical
- */
-static int strict_addrcmp(const struct Address *a, const struct Address *b)
-{
-  while (a && b)
-  {
-    if ((mutt_str_strcmp(a->mailbox, b->mailbox) != 0) ||
-        (mutt_str_strcmp(a->personal, b->personal) != 0))
-    {
-      return 0;
-    }
-
-    a = a->next;
-    b = b->next;
-  }
-  if (a || b)
-    return 0;
-
-  return 1;
-}
-
 static int strict_cmp_envelopes(const struct Envelope *e1, const struct Envelope *e2)
 {
   if (e1 && e2)
@@ -584,10 +559,11 @@ static int strict_cmp_envelopes(const struct Envelope *e1, const struct Envelope
     if ((mutt_str_strcmp(e1->message_id, e2->message_id) != 0) ||
         (mutt_str_strcmp(e1->subject, e2->subject) != 0) ||
         !mutt_list_compare(&e1->references, &e2->references) ||
-        !strict_addrcmp(e1->from, e2->from) || !strict_addrcmp(e1->sender, e2->sender) ||
-        !strict_addrcmp(e1->reply_to, e2->reply_to) ||
-        !strict_addrcmp(e1->to, e2->to) || !strict_addrcmp(e1->cc, e2->cc) ||
-        !strict_addrcmp(e1->return_path, e2->return_path))
+        !mutt_addr_cmp_strict(e1->from, e2->from) ||
+        !mutt_addr_cmp_strict(e1->sender, e2->sender) ||
+        !mutt_addr_cmp_strict(e1->reply_to, e2->reply_to) ||
+        !mutt_addr_cmp_strict(e1->to, e2->to) || !mutt_addr_cmp_strict(e1->cc, e2->cc) ||
+        !mutt_addr_cmp_strict(e1->return_path, e2->return_path))
       return 0;
     else
       return 1;
diff --git a/parse.c b/parse.c
index 6b7b5dcbe12258007b4efd0f6a75c094c3fdfdd5..7a07e88a39aa226ac8188d62c8a64e3e0ae2e4ff 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -1301,39 +1301,6 @@ struct Envelope *mutt_read_rfc822_header(FILE *f, struct Header *hdr,
   return e;
 }
 
-/**
- * mutt_parse_adrlist - Parse a list of email addresses
- * @param p Add to this List of Addresses
- * @param s String to parse
- * @retval ptr Head of the list of addresses
- *
- * The email addresses can be separated by whitespace or commas.
- */
-struct Address *mutt_parse_adrlist(struct Address *p, const char *s)
-{
-  const char *q = NULL;
-
-  /* check for a simple whitespace separated list of addresses */
-  q = strpbrk(s, "\"<>():;,\\");
-  if (!q)
-  {
-    char tmp[HUGE_STRING];
-    char *r = NULL;
-
-    mutt_str_strfcpy(tmp, s, sizeof(tmp));
-    r = tmp;
-    while ((r = strtok(r, " \t")) != NULL)
-    {
-      p = mutt_addr_parse_list(p, r);
-      r = NULL;
-    }
-  }
-  else
-    p = mutt_addr_parse_list(p, s);
-
-  return p;
-}
-
 /**
  * count_body_parts_check - Compares mime types to the ok and except lists
  */
index d32d4a86bacd9be238304a6976724c185fc3f0d1..ce86da802ac18aa409272553415990e5c08a9439 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -103,7 +103,7 @@ char *mutt_extract_message_id(const char *s, const char **saveptr);
 struct Address *mutt_default_from(void);
 struct Address *mutt_remove_duplicates(struct Address *addr);
 struct Address *mutt_remove_xrefs(struct Address *a, struct Address *b);
-struct Address *mutt_parse_adrlist(struct Address *p, const char *s);
+struct Address *mutt_addr_parse_list2(struct Address *p, const char *s);
 
 struct Body *mutt_make_file_attach(const char *path);
 struct Body *mutt_make_message_attach(struct Context *ctx, struct Header *hdr, int attach_msg);
@@ -377,4 +377,7 @@ int wcscasecmp(const wchar_t *a, const wchar_t *b);
 bool message_is_tagged(struct Context *ctx, int index);
 bool message_is_visible(struct Context *ctx, int index);
 
+int rfc822_write_address(char *buf, size_t buflen, struct Address *addr, int display);
+void rfc822_write_address_single(char *buf, size_t buflen, struct Address *addr, int display);
+
 #endif /* _MUTT_PROTOS_H */
diff --git a/send.c b/send.c
index 6f0bf4c77b9940945b63680156335dc81bf5e3ef..911273ef3d251fe5c3ebb86a7278efa2d05d57bf 100644 (file)
--- a/send.c
+++ b/send.c
@@ -84,37 +84,6 @@ static void append_signature(FILE *f)
   }
 }
 
-/**
- * addrcmp - compare two e-mail addresses
- * @param a Address 1
- * @param b Address 2
- * @retval true if they are equivalent
- */
-static bool addrcmp(struct Address *a, struct Address *b)
-{
-  if (!a->mailbox || !b->mailbox)
-    return false;
-  if (mutt_str_strcasecmp(a->mailbox, b->mailbox) != 0)
-    return false;
-  return true;
-}
-
-/**
- * addrsrc - Search for an e-mail address in a list
- * @param a   Address containing the search email
- * @param lst Address List
- * @retval true If the Address is in the list
- */
-static int addrsrc(struct Address *a, struct Address *lst)
-{
-  for (; lst; lst = lst->next)
-  {
-    if (addrcmp(a, lst))
-      return 1;
-  }
-  return 0;
-}
-
 /**
  * mutt_remove_xrefs - Remove cross-references
  *
@@ -129,7 +98,7 @@ struct Address *mutt_remove_xrefs(struct Address *a, struct Address *b)
   {
     for (p = a; p; p = p->next)
     {
-      if (addrcmp(p, b))
+      if (mutt_addr_cmp(p, b))
         break;
     }
     if (p)
@@ -236,7 +205,7 @@ static int edit_address(struct Address **a, /* const */ char *field)
     if (mutt_get_field(field, buf, sizeof(buf), MUTT_ALIAS) != 0)
       return -1;
     mutt_addr_free(a);
-    *a = mutt_expand_aliases(mutt_parse_adrlist(NULL, buf));
+    *a = mutt_expand_aliases(mutt_addr_parse_list2(NULL, buf));
     idna_ok = mutt_addrlist_to_intl(*a, &err);
     if (idna_ok != 0)
     {
@@ -558,10 +527,11 @@ static int default_to(struct Address **to, struct Envelope *env, int flags, int
   }
   else if (env->reply_to)
   {
-    if ((addrcmp(env->from, env->reply_to) && !env->reply_to->next &&
+    if ((mutt_addr_cmp(env->from, env->reply_to) && !env->reply_to->next &&
          !env->reply_to->personal) ||
         (option(OPT_IGNORE_LIST_REPLY_TO) && mutt_is_mail_list(env->reply_to) &&
-         (addrsrc(env->reply_to, env->to) || addrsrc(env->reply_to, env->cc))))
+         (mutt_addr_search(env->reply_to, env->to) ||
+          mutt_addr_search(env->reply_to, env->cc))))
     {
       /* If the Reply-To: address is a mailing list, assume that it was
        * put there by the mailing list, and use the From: address
@@ -573,7 +543,7 @@ static int default_to(struct Address **to, struct Envelope *env, int flags, int
        */
       mutt_addr_append(to, env->from, 0);
     }
-    else if (!(addrcmp(env->from, env->reply_to) && !env->reply_to->next) &&
+    else if (!(mutt_addr_cmp(env->from, env->reply_to) && !env->reply_to->next) &&
              quadoption(OPT_REPLY_TO) != MUTT_YES)
     {
       /* There are quite a few mailing lists which set the Reply-To:
@@ -1270,26 +1240,6 @@ static int is_reply(struct Header *reply, struct Header *orig)
          mutt_list_find(&orig->env->in_reply_to, reply->env->message_id);
 }
 
-/**
- * has_recips - Count the number of Addresses with valid recipients
- * @param a Address list
- * @retval num Number of valid Addresses
- *
- * An Address has a recipient if the mailbox or group is set.
- */
-static int has_recips(struct Address *a)
-{
-  int c = 0;
-
-  for (; a; a = a->next)
-  {
-    if (!a->mailbox || a->group)
-      continue;
-    c++;
-  }
-  return c;
-}
-
 static int search_attach_keyword(char *filename)
 {
   /* Search for the regex in AttachKeyword within a file */
@@ -1944,8 +1894,8 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile,
 #ifdef USE_NNTP
   if (!(flags & SENDNEWS))
 #endif
-    if (!has_recips(msg->env->to) && !has_recips(msg->env->cc) &&
-        !has_recips(msg->env->bcc))
+    if (!mutt_addr_has_recips(msg->env->to) && !mutt_addr_has_recips(msg->env->cc) &&
+        !mutt_addr_has_recips(msg->env->bcc))
     {
       if (!(flags & SENDBATCH))
       {