X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=alias.c;h=7706be0951f31d4ca91ba79e736a25aa352a6fa2;hp=32b6df3dc704886502a88fcfa27325626622619c;hb=a2a7836df164f0e198ad34dbc2f82baf7847fb94;hpb=0f6739c5be4203bec0fa32962e6ab13349da703b diff --git a/alias.c b/alias.c index 32b6df3..7706be0 100644 --- a/alias.c +++ b/alias.c @@ -1,3 +1,21 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * Copyright © 2006 Pierre Habouzit + */ /* * Copyright notice from original mutt: * Copyright (C) 1996-2002 Michael R. Elkins @@ -20,7 +38,6 @@ #include #include #include -#include #include #include @@ -29,10 +46,15 @@ #include #include -#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[] = { @@ -44,18 +66,36 @@ static struct mapping_t AliasHelp[] = { {NULL, OP_NULL} }; -void alias_wipe(alias_t *a) { - p_delete(&a->name); - address_delete(&a->addr); - alias_delete(&a->next); -} - -const address_t *alias_lookup(const alias_t *list, const char *s) +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; +} + +/* This routine looks to see if the user has an alias defined for the given + address. */ +const address_t *alias_reverse_lookup(const address_t *a) +{ + alias_t *list; + + if (!a || !a->mailbox) + return NULL; + + for (list = Aliases; list; list = list->next) { + address_t *ap; + + /* cycle through all addresses if this is a group alias */ + for (ap = list->addr; ap; ap = ap->next) { + if (!ap->group && ap->mailbox + && !ascii_strcasecmp(ap->mailbox, a->mailbox)) + return ap; + } } return NULL; @@ -192,7 +232,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; } @@ -214,7 +254,7 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr) const char *err = NULL; if (mutt_get_field(_("Address: "), buf, sizeof(buf), 0) || !buf[0]) { - alias_delete(&new); + alias_list_wipe(&new); return; } @@ -236,7 +276,7 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr) } if (mutt_get_field(_("Personal name: "), buf, sizeof(buf), 0)) { - alias_delete(&new); + alias_list_wipe(&new); return; } new->addr->personal = m_strdup(buf); @@ -245,7 +285,7 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr) rfc822_write_address(buf, sizeof(buf), new->addr, 1); snprintf(prompt, sizeof(prompt), _("[%s = %s] Accept?"), new->name, buf); if (mutt_yesorno(prompt, M_YES) != M_YES) { - alias_delete(&new); + alias_list_wipe(&new); return; } @@ -277,7 +317,7 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr) } } -static address_t *mutt_expand_aliases_r(address_t *a, LIST **expn) +static address_t *mutt_expand_aliases_r(address_t *a, string_list_t **expn) { address_t *pop, *head = NULL; address_t **last = &head; @@ -286,24 +326,24 @@ static address_t *mutt_expand_aliases_r(address_t *a, LIST **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) { - LIST *u; + string_list_t *u; for (u = *expn; u; u = u->next) { if (!m_strcmp(pop->mailbox, u->data)) { /* alias already found */ - address_delete(&pop); + address_list_wipe(&pop); continue; } } /* save the fact we saw it */ - u = mutt_new_list(); + u = string_item_new(); u->data = m_strdup(pop->mailbox); u->next = *expn; *expn = u; - address_delete(&pop); + address_list_wipe(&pop); /* recurse */ last = address_list_last(last); @@ -336,10 +376,10 @@ static address_t *mutt_expand_aliases_r(address_t *a, LIST **expn) address_t *mutt_expand_aliases(address_t *a) { address_t *t; - LIST *expn = NULL; /* previously expanded aliases to avoid loops */ + string_list_t *expn = NULL; /* previously expanded aliases to avoid loops */ t = mutt_expand_aliases_r(a, &expn); - mutt_free_list(&expn); + string_list_wipe(&expn); return mutt_remove_duplicates(t); } @@ -355,30 +395,6 @@ void mutt_expand_aliases_env(ENVELOPE *env) /************* READ MARK *********************/ - -/* - * This routine looks to see if the user has an alias defined for the given - * address. - */ -address_t *alias_reverse_lookup (address_t * a) -{ - alias_t *t = Aliases; - address_t *ap; - - if (!a || !a->mailbox) - return NULL; - - for (; t; t = t->next) { - /* cycle through all addresses if this is a group alias */ - for (ap = t->addr; ap; ap = ap->next) { - if (!ap->group && ap->mailbox && - ascii_strcasecmp (ap->mailbox, a->mailbox) == 0) - return ap; - } - } - return 0; -} - /* alias_complete() -- alias completion routine * * given a partial alias, this routine attempts to fill in the alias @@ -458,7 +474,7 @@ int mutt_alias_complete (char *s, size_t buflen) Aliases = a_cur->next; a_cur->next = NULL; - alias_delete(&a_cur); + alias_list_wipe(&a_cur); if (a_list) a_cur = a_list; @@ -664,5 +680,4 @@ new_aliases: mutt_menuDestroy (&menu); p_delete(&AliasTable); - }