X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/14c29200cb58d3c4a0830265f2433849781858d0..57dfa08c90608b82597b77862a69f6ed083c772c:/alias.c?ds=sidebyside diff --git a/alias.c b/alias.c index 50ec5a3..a8fa61f 100644 --- a/alias.c +++ b/alias.c @@ -70,7 +70,7 @@ static ADDRESS *mutt_expand_aliases_r (ADDRESS *a, LIST **expn) u->data = safe_strdup (a->mailbox); u->next = *expn; *expn = u; - w = rfc822_cpy_adr (t); + w = rfc822_cpy_adr (t, 0); w = mutt_expand_aliases_r (w, expn); if (head) last->next = w; @@ -148,9 +148,9 @@ void mutt_expand_aliases_env (ENVELOPE *env) * if someone has an address like * From: Michael `/bin/rm -f ~` Elkins * and the user creates an alias for this, Mutt could wind up executing - * the backtics because it writes aliases like + * the backticks because it writes aliases like * alias me Michael `/bin/rm -f ~` Elkins - * To avoid this problem, use a backslash (\) to quote any backtics. We also + * To avoid this problem, use a backslash (\) to quote any backticks. We also * need to quote backslashes as well, since you could defeat the above by * doing * From: Michael \`/bin/rm -f ~\` Elkins @@ -211,6 +211,20 @@ ADDRESS *mutt_get_address (ENVELOPE *env, char **pfxp) return adr; } +static void recode_buf (char *buf, size_t buflen) +{ + char *s; + + if (!ConfigCharset || !*ConfigCharset || !Charset) + return; + s = safe_strdup (buf); + if (!s) + return; + if (mutt_convert_string (&s, Charset, ConfigCharset, 0) == 0) + strfcpy (buf, s, buflen); + FREE(&s); +} + void mutt_create_alias (ENVELOPE *cur, ADDRESS *iadr) { ALIAS *new, *t; @@ -318,6 +332,8 @@ retry_name: return; } + mutt_alias_add_reverse (new); + if ((t = Aliases)) { while (t->next) @@ -340,9 +356,10 @@ retry_name: { if (fseek (rc, -1, SEEK_CUR) < 0) goto fseek_err; - if (fread(buf, 1, 1, rc) < 0) + if (fread(buf, 1, 1, rc) != 1) { mutt_perror (_("Error reading alias file")); + safe_fclose (&rc); return; } if (fseek (rc, 0, SEEK_END) < 0) @@ -355,12 +372,14 @@ retry_name: mutt_quote_filename (buf, sizeof (buf), new->name); else strfcpy (buf, new->name, sizeof (buf)); + recode_buf (buf, sizeof (buf)); fprintf (rc, "alias %s ", buf); buf[0] = 0; rfc822_write_address (buf, sizeof (buf), new->addr, 0); + recode_buf (buf, sizeof (buf)); write_safe_address (rc, buf); fputc ('\n', rc); - fclose (rc); + safe_fclose (&rc); mutt_message _("Alias added."); } else @@ -370,7 +389,7 @@ retry_name: fseek_err: mutt_perror (_("Error seeking in alias file")); - fclose(rc); + safe_fclose (&rc); return; } @@ -424,23 +443,36 @@ int mutt_check_alias_name (const char *s, char *dest, size_t destlen) */ ADDRESS *alias_reverse_lookup (ADDRESS *a) { - ALIAS *t = Aliases; - ADDRESS *ap; - if (!a || !a->mailbox) - return NULL; + return NULL; + + return hash_find (ReverseAlias, a->mailbox); +} - for (; t; t = t->next) +void mutt_alias_add_reverse (ALIAS *t) +{ + ADDRESS *ap; + if (!t) + return; + + for (ap = t->addr; ap; ap = ap->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; - } + if (!ap->group && ap->mailbox) + hash_insert (ReverseAlias, ap->mailbox, ap, 1); + } +} + +void mutt_alias_delete_reverse (ALIAS *t) +{ + ADDRESS *ap; + if (!t) + return; + + for (ap = t->addr; ap; ap = ap->next) + { + if (!ap->group && ap->mailbox) + hash_delete (ReverseAlias, ap->mailbox, ap, NULL); } - return 0; } /* alias_complete() -- alias completion routine @@ -456,7 +488,9 @@ int mutt_alias_complete (char *s, size_t buflen) char bestname[HUGE_STRING]; int i; +#ifndef min #define min(a,b) ((amailbox, Username, Hostname)); return 1; } - if (string_is_address(addr->mailbox, Username, mutt_fqdn(0))) + fqdn = mutt_fqdn (0); + if (string_is_address(addr->mailbox, Username, fqdn)) { - dprint (5, (debugfile, "mutt_addr_is_user: yes, %s = %s @ %s \n", addr->mailbox, Username, mutt_fqdn (0))); + dprint (5, (debugfile, "mutt_addr_is_user: yes, %s = %s @ %s \n", addr->mailbox, Username, NONULL(fqdn))); return 1; } - if (string_is_address(addr->mailbox, Username, mutt_fqdn(1))) + fqdn = mutt_fqdn (1); + if (string_is_address(addr->mailbox, Username, fqdn)) { - dprint (5, (debugfile, "mutt_addr_is_user: yes, %s = %s @ %s \n", addr->mailbox, Username, mutt_fqdn (1))); + dprint (5, (debugfile, "mutt_addr_is_user: yes, %s = %s @ %s \n", addr->mailbox, Username, NONULL(fqdn))); return 1; }