X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=alias.c;h=fdf74c0a8bcd0f4fda692fef1d385d0c7f1cfefc;hp=e03536bf39eb7c144f9cc4ddbd68b38c0ad82ad8;hb=3f35b8874fb10587ce43e2853a1ef95573222015;hpb=7d6add87dcf687d93906c297d335029effbed909 diff --git a/alias.c b/alias.c index e03536b..fdf74c0 100644 --- a/alias.c +++ b/alias.c @@ -25,21 +25,7 @@ * please see the file GPL in the top level source directory. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include +#include #include @@ -47,10 +33,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[] = { @@ -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 */ @@ -201,7 +197,7 @@ static void write_safe_address(FILE *fp, const char *s) void mutt_create_alias(ENVELOPE *cur, address_t *iadr) { - char buf[LONG_STRING], prompt[SHORT_STRING]; + char buf[LONG_STRING], prompt[STRING]; address_t *adr = iadr; alias_t *new; FILE *rc; @@ -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; } @@ -275,7 +272,7 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr) new->addr->personal = m_strdup(buf); buf[0] = '\0'; - rfc822_write_address(buf, sizeof(buf), new->addr, 1); + rfc822_addrcat(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_list_wipe(&new); @@ -301,9 +298,9 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr) } buf[0] = '\0'; - rfc822_write_address(buf, sizeof(buf), new->addr, 0); + rfc822_addrcat(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; @@ -358,9 +355,7 @@ static address_t *mutt_expand_aliases_r(address_t *a, string_list_t **expn) if (option(OPTUSEDOMAIN)) { /* now qualify all local addresses */ - const char *fqdn = mutt_fqdn(1); - if (fqdn) - rfc822_qualify(head, fqdn); + rfc822_qualify(head, mutt_fqdn(1)); } return head; @@ -373,7 +368,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) @@ -483,25 +479,25 @@ int mutt_alias_complete (char *s, size_t buflen) return 0; } -static const format_t *alias_format_str (char *dest, size_t destlen, char op, - const format_t *src, const char *fmt, - const char *ifstring __attribute__ ((unused)), - const char *elsestring __attribute__ ((unused)), - unsigned long data, format_flag flags __attribute__ ((unused))) +static const char * +alias_format_str(char *dest, ssize_t destlen, char op, const char *src, + const char *fmt, const char *ifstr __attribute__ ((unused)), + const char *elstr __attribute__ ((unused)), + anytype data, format_flag flags __attribute__ ((unused))) { - char tmp[SHORT_STRING], adr[SHORT_STRING]; - alias_t *alias = (alias_t *) data; + char tmp[STRING], adr[STRING]; + alias_t *alias = data.ptr; switch (op) { case 'f': - m_strcpy(dest, destlen, alias->del ? "D" : " "); + m_strputc(dest, destlen, alias->del ? 'D' : ' '); break; case 'a': mutt_format_s(dest, destlen, fmt, alias->name); break; case 'r': adr[0] = '\0'; - rfc822_write_address(adr, sizeof(adr), alias->addr, 1); + rfc822_addrcat(adr, sizeof(adr), alias->addr, 1); snprintf(tmp, sizeof(tmp), "%%%ss", fmt); snprintf(dest, destlen, tmp, adr); break; @@ -510,18 +506,18 @@ static const format_t *alias_format_str (char *dest, size_t destlen, char op, snprintf(dest, destlen, tmp, alias->num + 1); break; case 't': - m_strcpy(dest, destlen, alias->tagged ? "*" : " "); + m_strputc(dest, destlen, alias->tagged ? '*' : ' '); break; } - return (src); + return src; } -static void alias_entry (char *s, ssize_t slen, MUTTMENU * m, int num) +static void alias_entry(char *s, ssize_t slen, MUTTMENU *m, int num) { - mutt_FormatString (s, slen, NONULL (AliasFmt), (format_t *)alias_format_str, - (unsigned long)((alias_t **)m->data)[num], - M_FORMAT_ARROWCURSOR); + m_strformat(s, slen, COLS - SW, AliasFmt, alias_format_str, + ((alias_t **)m->data)[num], + option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0); } static int alias_tag (MUTTMENU * menu, int n, int m) @@ -576,7 +572,7 @@ void mutt_alias_menu (char *buf, size_t buflen, alias_t * aliases) int t = -1; int i, done = 0; int op; - char helpstr[SHORT_STRING]; + char helpstr[STRING]; int omax; @@ -661,17 +657,16 @@ new_aliases: for (i = 0; i < menu->max; i++) { if (AliasTable[i]->tagged) { mutt_addrlist_to_local (AliasTable[i]->addr); - rfc822_write_address (buf, buflen, AliasTable[i]->addr, 0); + rfc822_addrcat(buf, buflen, AliasTable[i]->addr, 0); t = -1; } } if (t != -1) { mutt_addrlist_to_local (AliasTable[t]->addr); - rfc822_write_address (buf, buflen, AliasTable[t]->addr, 0); + rfc822_addrcat(buf, buflen, AliasTable[t]->addr, 0); } mutt_menuDestroy (&menu); p_delete(&AliasTable); - }