]> granicus.if.org Git - neomutt/commitdiff
Change gossip header address comparison to use normalized addresses
authorKevin McCarthy <kevin@8t8.us>
Thu, 18 Jul 2019 20:22:52 +0000 (13:22 -0700)
committerRichard Russon <rich@flatcap.org>
Mon, 19 Aug 2019 23:14:27 +0000 (00:14 +0100)
Co-authored-by: Richard Russon <rich@flatcap.org>
autocrypt/autocrypt.c
autocrypt/autocrypt_db.c
autocrypt/autocrypt_private.h

index 3ecebcf2038c533b28b049b55b58c915a8b17374..feb204e8b480d57ae8bd1b44218d1a7205191c37 100644 (file)
@@ -310,31 +310,6 @@ cleanup:
   return rv;
 }
 
-static struct Address *matching_gossip_address(struct Envelope *env, const char *addr)
-{
-  struct Address *np = NULL;
-
-  TAILQ_FOREACH(np, &env->to, entries)
-  {
-    if (!mutt_str_strcasecmp(np->mailbox, addr))
-      return np;
-  }
-
-  TAILQ_FOREACH(np, &env->cc, entries)
-  {
-    if (!mutt_str_strcasecmp(np->mailbox, addr))
-      return np;
-  }
-
-  TAILQ_FOREACH(np, &env->reply_to, entries)
-  {
-    if (!mutt_str_strcasecmp(np->mailbox, addr))
-      return np;
-  }
-
-  return NULL;
-}
-
 int mutt_autocrypt_process_gossip_header(struct Email *hdr, struct Envelope *env)
 {
   struct AutocryptHeader *ac_hdr;
@@ -342,6 +317,7 @@ int mutt_autocrypt_process_gossip_header(struct Email *hdr, struct Envelope *env
   struct AutocryptPeer *peer = NULL;
   struct AutocryptGossipHistory *gossip_hist = NULL;
   struct Address *peer_addr;
+  struct Address ac_hdr_addr = { 0 };
   struct Buffer *keyid = NULL;
   int update_db = 0, insert_db = 0, insert_db_history = 0, import_gpg = 0;
   int rv = -1;
@@ -367,19 +343,37 @@ int mutt_autocrypt_process_gossip_header(struct Email *hdr, struct Envelope *env
 
   keyid = mutt_buffer_pool_get();
 
-  /* To ensure the address headers match the gossip header format */
-  mutt_env_to_intl(env, NULL, NULL);
+  struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
+
+  /* Normalize the recipient list for comparison */
+  mutt_addrlist_copy(&recips, &env->to, false);
+  mutt_addrlist_copy(&recips, &env->cc, false);
+  mutt_addrlist_copy(&recips, &env->reply_to, false);
+  mutt_autocrypt_db_normalize_addrlist(&recips);
 
   for (ac_hdr = env->autocrypt_gossip; ac_hdr; ac_hdr = ac_hdr->next)
   {
     if (ac_hdr->invalid)
       continue;
 
-    peer_addr = matching_gossip_address(env, ac_hdr->addr);
+    /* normalize for comparison against recipient list */
+    mutt_str_replace(&ac_hdr_addr.mailbox, ac_hdr->addr);
+    ac_hdr_addr.is_intl = 1;
+    ac_hdr_addr.intl_checked = 1;
+    mutt_autocrypt_db_normalize_addr(&ac_hdr_addr);
+
+    /* Check to make sure the address is in the recipient list.  Since the
+     * addresses are normalized we use strcmp, not mutt_str_strcasecmp. */
+    TAILQ_FOREACH(peer_addr, &recips, entries)
+    {
+      if (!mutt_str_strcmp(peer_addr->mailbox, ac_hdr_addr.mailbox))
+        break;
+    }
+
     if (!peer_addr)
       continue;
 
-    if (mutt_autocrypt_db_peer_get(from, &peer) < 0)
+    if (mutt_autocrypt_db_peer_get(peer_addr, &peer) < 0)
       goto cleanup;
 
     if (peer)
@@ -446,6 +440,8 @@ int mutt_autocrypt_process_gossip_header(struct Email *hdr, struct Envelope *env
   rv = 0;
 
 cleanup:
+  FREE(&ac_hdr_addr.mailbox);
+  mutt_addrlist_clear(&recips);
   mutt_autocrypt_db_peer_free(&peer);
   mutt_autocrypt_db_gossip_history_free(&gossip_hist);
   mutt_buffer_pool_release(&keyid);
index 7526387ced1e9db52686e85ab5c9d9114e03c69c..2e628ef0d3a9f511266894309334b3fd2f0c857f 100644 (file)
@@ -120,15 +120,24 @@ void mutt_autocrypt_db_close(void)
   AutocryptDB = NULL;
 }
 
-void mutt_autocrypt_db_normalize_addrlist(struct Address *addrlist)
+void mutt_autocrypt_db_normalize_addr(struct Address *a)
 {
-  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
-  mutt_addrlist_append(&al, addrlist);
+  mutt_addr_to_local(a);
+  mutt_str_strlower(a->mailbox);
+  mutt_addr_to_intl(a);
+}
+
+void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al)
+{
+  mutt_addrlist_to_local(al);
 
-  mutt_addrlist_to_local(&al);
-  mutt_addrlist_to_intl(&al, NULL);
+  struct Address *np = NULL;
+  TAILQ_FOREACH(np, al, entries)
+  {
+    mutt_str_strlower(np->mailbox);
+  }
 
-  TAILQ_REMOVE(&al, addrlist, entries);
+  mutt_addrlist_to_intl(al, NULL);
 }
 
 /* The autocrypt spec says email addresses should be
@@ -155,7 +164,7 @@ static struct Address *copy_normalize_addr(struct Address *addr)
   norm_addr->is_intl = addr->is_intl;
   norm_addr->intl_checked = addr->intl_checked;
 
-  mutt_autocrypt_db_normalize_addrlist(norm_addr);
+  mutt_autocrypt_db_normalize_addr(norm_addr);
   return norm_addr;
 }
 
index 661b8c40f90691a9e10814edbbe489077a80ed60..258e4d0850f5c53c81e960f0d806fc3bb48a3490 100644 (file)
@@ -26,6 +26,7 @@
 #include <sqlite3.h>
 
 struct Address;
+struct AddressList;
 struct Buffer;
 
 int mutt_autocrypt_account_init (void);
@@ -33,7 +34,8 @@ int mutt_autocrypt_account_init (void);
 int mutt_autocrypt_db_init (int can_create);
 void mutt_autocrypt_db_close (void);
 
-void mutt_autocrypt_db_normalize_addrlist (struct Address *addrlist);
+void mutt_autocrypt_db_normalize_addr(struct Address *a);
+void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al);
 
 struct AutocryptAccount *mutt_autocrypt_db_account_new (void);
 void mutt_autocrypt_db_account_free (struct AutocryptAccount **account);