mutt_*mktemp--
[apps/madmutt.git] / alias.c
diff --git a/alias.c b/alias.c
index e03536b..68afc25 100644 (file)
--- a/alias.c
+++ b/alias.c
  * please see the file GPL in the top level source directory.
  */
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <string.h>
-#include <ctype.h>
-
-#include <lib-lib/mem.h>
-#include <lib-lib/ascii.h>
-#include <lib-lib/str.h>
-#include <lib-lib/file.h>
-#include <lib-lib/macros.h>
-#include <lib-lib/mapping.h>
-#include <lib-lib/debug.h>
-#include <lib-lib/rx.h>
+#include <lib-lib/lib-lib.h>
 
 #include <lib-sys/unix.h>
 
 #include <lib-ui/enter.h>
 #include <lib-ui/menu.h>
 
-#include "mutt.h"
+#include "alias.h"
 #include "mutt_idna.h"
 #include "sort.h"
 
+char    *AliasFmt;
+char    *AliasFile;
+alias_t *Aliases;
+rx_t     GecosMask;
+
 #define RSORT(x) (SortAlias & SORT_REVERSE) ? -x : x
 
 static struct mapping_t AliasHelp[] = {
@@ -62,12 +53,15 @@ static struct mapping_t AliasHelp[] = {
     {NULL, OP_NULL}
 };
 
-const address_t *alias_lookup(const alias_t *list, const char *s)
+static void mutt_alias_menu(char *, size_t, alias_t *);
+
+const address_t *alias_lookup(const char *s)
 {
-    while (list) {
+    alias_t *list;
+
+    for (list = Aliases; list; list = list->next) {
         if (!m_strcasecmp(s, list->name))
             return list->addr;
-        list = list->next;
     }
 
     return NULL;
@@ -75,12 +69,14 @@ const address_t *alias_lookup(const alias_t *list, const char *s)
 
 /* This routine looks to see if the user has an alias defined for the given
    address.                                                                 */
-const address_t *alias_reverse_lookup(const alias_t *list, const address_t *a)
+const address_t *alias_reverse_lookup(const address_t *a)
 {
+    alias_t *list;
+
     if (!a || !a->mailbox)
         return NULL;
 
-    for (; list; list = list->next) {
+    for (list = Aliases; list; list = list->next) {
         address_t *ap;
 
         /* cycle through all addresses if this is a group alias */
@@ -225,7 +221,7 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr)
         return;
 
     /* check to see if the user already has an alias defined */
-    if (alias_lookup(Aliases, buf)) {
+    if (alias_lookup(buf)) {
         mutt_error _("You already have an alias defined with that name!");
         return;
     }
@@ -244,7 +240,7 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr)
     mutt_addrlist_to_idna(adr, NULL);
 
     do {
-        const char *err = NULL;
+        char *err = NULL;
 
         if (mutt_get_field(_("Address: "), buf, sizeof(buf), 0) || !buf[0]) {
             alias_list_wipe(&new);
@@ -257,6 +253,7 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr)
 
         if (mutt_addrlist_to_idna(new->addr, &err)) {
             mutt_error(_("Error: '%s' is a bad IDN."), err);
+            p_delete(&err);
             mutt_sleep(1);
             continue;
         }
@@ -303,7 +300,7 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr)
         buf[0] = '\0';
         rfc822_write_address(buf, sizeof(buf), new->addr, 0);
         write_safe_address(rc, buf);
-        fclose(rc);
+        m_fclose(&rc);
         mutt_message _("Alias added.");
     } else {
         mutt_perror(buf);
@@ -319,7 +316,7 @@ static address_t *mutt_expand_aliases_r(address_t *a, string_list_t **expn)
         if (!pop->group && !pop->personal
         &&  pop->mailbox && !strchr(pop->mailbox, '@'))
         {
-            const address_t *t = alias_lookup(Aliases, pop->mailbox);
+            const address_t *t = alias_lookup(pop->mailbox);
 
             if (t) {
                 string_list_t *u;
@@ -373,7 +370,8 @@ address_t *mutt_expand_aliases(address_t *a)
 
     t = mutt_expand_aliases_r(a, &expn);
     string_list_wipe(&expn);
-    return mutt_remove_duplicates(t);
+    address_list_uniq(t);
+    return t;
 }
 
 void mutt_expand_aliases_env(ENVELOPE *env)
@@ -673,5 +671,4 @@ new_aliases:
 
   mutt_menuDestroy (&menu);
   p_delete(&AliasTable);
-
 }