]> granicus.if.org Git - mutt/commitdiff
Add some debugging code, and rewrite the previously-ununderstandable
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 12 Jul 2004 13:22:24 +0000 (13:22 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 12 Jul 2004 13:22:24 +0000 (13:22 +0000)
mutt_remove_duplicates.  (All this done on the search for a problem
that ultimately turned out to be a configuration issue. Still, the
changed code could come in handy some day.)

init.c
sendlib.c

diff --git a/init.c b/init.c
index 3d1c13a0496ba6a4e4b2b5e7f5a862314790aa2b..764c23edd36e75d3343c79c3e59147b18f24eea3 100644 (file)
--- a/init.c
+++ b/init.c
@@ -614,6 +614,9 @@ static int parse_alias (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
 
   mutt_extract_token (buf, s, 0);
 
+  dprint (2, (debugfile, "parse_alias: First token is '%s'.\n",
+             buf->data));
+  
   /* check to see if an alias with this name already exists */
   for (; tmp; tmp = tmp->next)
   {
@@ -641,6 +644,8 @@ static int parse_alias (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
   }
 
   mutt_extract_token (buf, s, M_TOKEN_QUOTE | M_TOKEN_SPACE | M_TOKEN_SEMICOLON);
+  dprint (2, (debugfile, "parse_alias: Second token is '%s'.\n",
+             buf->data));
   tmp->addr = mutt_parse_adrlist (tmp->addr, buf->data);
   if (last)
     last->next = tmp;
@@ -652,6 +657,21 @@ static int parse_alias (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
              estr, tmp->name);
     return -1;
   }
+#ifdef DEBUG
+  if (debuglevel >= 2) 
+  {
+    ADDRESS *a;
+    for (a = tmp->addr; a; a = a->next)
+    {
+      if (!a->group)
+       dprint (2, (debugfile, "parse_alias:   %s\n",
+                   a->mailbox));
+      else
+       dprint (2, (debugfile, "parse_alias:   Group %s\n",
+                   a->mailbox));
+    }
+  }
+#endif
   return 0;
 }
 
@@ -1370,6 +1390,9 @@ static int source_rc (const char *rcfile, BUFFER *err)
   size_t buflen;
   pid_t pid;
 
+  dprint (2, (debugfile, "Reading configuration file '%s'.\n",
+         rcfile));
+  
   if ((f = mutt_open_read (rcfile, &pid)) == NULL)
   {
     snprintf (err->data, err->dsize, "%s: %s", rcfile, strerror (errno));
index 54b9e54e653d8c9c873d5ca7c821885a59819b41..f273e26f6106ad796889699799a0e244be0353d3 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -2277,40 +2277,42 @@ int mutt_bounce_message (FILE *fp, HEADER *h, ADDRESS *to)
 /* given a list of addresses, return a list of unique addresses */
 ADDRESS *mutt_remove_duplicates (ADDRESS *addr)
 {
-  ADDRESS *top = NULL;
+  ADDRESS *top = addr;
+  ADDRESS **last = &top;
   ADDRESS *tmp;
-  
-  if ((top = addr) == NULL)
-    return (NULL);
-  addr = addr->next;
-  top->next = NULL;
+  int dup;
+
   while (addr)
   {
-    tmp = top;
-    do {
-      if (addr->mailbox && tmp->mailbox &&
+    for (tmp = top, dup = 0; tmp && tmp != addr; tmp = tmp->next)
+    {
+      if (tmp->mailbox && addr->mailbox && 
          !ascii_strcasecmp (addr->mailbox, tmp->mailbox))
       {
-       /* duplicate address, just ignore it */
-       tmp = addr;
-       addr = addr->next;
-       tmp->next = NULL;
-       rfc822_free_address (&tmp);
-      }
-      else if (!tmp->next)
-      {
-       /* unique address.  add it to the list */
-       tmp->next = addr;
-       addr = addr->next;
-       tmp = tmp->next;
-       tmp->next = NULL;
-       tmp = NULL; /* so we exit the loop */
+       dup = 1;
+       break;
       }
-      else
-       tmp = tmp->next;
-    } while (tmp);
-  }
+    }
+    
+    if (dup)
+    {
+      dprint (2, (debugfile, "mutt_remove_duplicates: Removing %s\n",
+                 addr->mailbox));
+      
+      *last = addr->next;
 
+      addr->next = NULL;
+      rfc822_free_address(&addr);
+      
+      addr = *last;
+    }
+    else 
+    {
+      last = &addr->next;
+      addr = addr->next;
+    }
+  }
+  
   return (top);
 }