Always resort, redraw, ... whatever when we change settings.
[apps/madmutt.git] / alias.cpkg
1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or (at
5  *  your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful, but
8  *  WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10  *  General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15  *  MA 02110-1301, USA.
16  *
17  *  Copyright © 2006 Pierre Habouzit
18  */
19 /*
20  * Copyright notice from original mutt:
21  * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
22  *
23  * This file is part of mutt-ng, see http://www.muttng.org/.
24  * It's licensed under the GNU General Public License,
25  * please see the file GPL in the top level source directory.
26  */
27
28 #include <lib-lib/lib-lib.h>
29
30 #include <lib-sys/unix.h>
31
32 #include <lib-ui/lib-ui.h>
33 #include <lib-ui/enter.h>
34 #include <lib-ui/menu.h>
35
36 #include "alias.h"
37 #include "mutt_idna.h"
38 #include "sort.h"
39 @import  "lib-lua/base.cpkg"
40
41 static rx_t *Alternates = NULL, *UnAlternates = NULL;
42 rx_t *MailLists = NULL, *UnMailLists = NULL;
43 rx_t *SubscribedLists = NULL, *UnSubscribedLists = NULL;
44
45 @package MAlias {
46     /*
47      ** .pp
48      ** Specifies the format of the data displayed for the ``alias'' menu. The
49      ** following \fTprintf(3)\fP-style sequences are available:
50      ** .pp
51      ** .dl
52      ** .dt %a .dd alias name
53      ** .dt %f .dd flags - currently, a "d" for an alias marked for deletion
54      ** .dt %n .dd index number
55      ** .dt %r .dd address which alias expands to
56      ** .dt %t .dd character which indicates if the alias is tagged for inclusion
57      ** .de
58      */
59     string_t alias_format = m_strdup("%4n %2f %t %-10a   %r");
60     /*
61      ** .pp
62      ** The default file in which to save aliases created by the
63      ** ``$create-alias'' function.
64      ** .pp
65      ** \fBNote:\fP Madmutt will not automatically source this file; you must
66      ** explicitly use the ``$source'' command for it to be executed.
67      */
68     path_t alias_file = m_strdup("~/.madmutt/aliases");
69
70     /*
71      ** .pp
72      ** Specifies the filename of your signature, which is appended to all
73      ** outgoing messages.   If the filename ends with a pipe (``\fT|\fP''), it is
74      ** assumed that filename is a shell command and input should be read from
75      ** its stdout.
76      */
77     path_t signature = m_strdup("~/.signature");
78
79     /*
80      ** .pp
81      ** This specifies the file into which your outgoing messages should be
82      ** appended.  (This is meant as the primary method for saving a copy of
83      ** your messages, but another way to do this is using the ``$my_hdr''
84      ** command to create a \fTBcc:\fP header field with your email address in it.)
85      ** .pp
86      ** The value of \fI$$record\fP is overridden by the ``$$force_name'' and
87      ** ``$$save_name'' variables, and the ``$fcc-hook'' command.
88      */
89     path_t record = NULL;
90
91     /*
92      ** .pp
93      ** This variable contains a default from address.  It
94      ** can be overridden using my_hdr (including from send-hooks) and
95      ** ``$$reverse_name''.  This variable is ignored if ``$$use_from''
96      ** is unset.
97      ** .pp
98      ** E.g. you can use
99      ** \fTsend-hook Madmutt-devel@lists.berlios.de 'my_hdr From: Foo Bar <foo@bar.fb>'\fP
100      ** when replying to the Madmutt developer's mailing list and Madmutt takes this email address.
101      ** .pp
102      ** Defaults to the contents of the environment variable \fT$$$EMAIL\fP.
103      */
104     address_t from = rfc822_parse_adrlist(NULL, NONULL(getenv("EMAIL")));
105
106     void alternates(rx_t rx) {
107         rx_list_remove(&UnAlternates, rx);
108         rx_list_add(&Alternates, rx);
109         RETURN();
110     };
111     void unalternates(rx_t rx) {
112         rx_list_remove(&Alternates, rx);
113         rx_list_add(&UnAlternates, rx);
114         RETURN();
115     };
116
117     void lists(rx_t rx) {
118         rx_list_remove(&UnMailLists, rx);
119         rx_list_add(&MailLists, rx);
120         RETURN();
121     };
122     void unlists(rx_t rx) {
123         rx_list_remove(&MailLists, rx);
124         rx_list_remove(&SubscribedLists, rx);
125         rx_list_add(&UnMailLists, rx);
126         RETURN();
127     };
128
129     void subscribe(rx_t rx) {
130         rx_list_remove(&UnMailLists, rx);
131         rx_list_remove(&UnSubscribedLists, rx);
132         rx_list_add(&MailLists, rx);
133         rx_list_add(&SubscribedLists, rx_dup(rx));
134         RETURN();
135     };
136     void unsubscribe(rx_t rx) {
137         rx_list_remove(&SubscribedLists, rx);
138         rx_list_add(&UnSubscribedLists, rx);
139         RETURN();
140     };
141 };
142
143 alias_t *Aliases;
144
145 #define RSORT(x) (SortAlias & SORT_REVERSE) ? -x : x
146
147 static void mutt_alias_menu(char *, size_t, alias_t *);
148
149 const address_t *alias_lookup(const char *s)
150 {
151     alias_t *list;
152
153     for (list = Aliases; list; list = list->next) {
154         if (!m_strcasecmp(s, list->name))
155             return list->addr;
156     }
157
158     return NULL;
159 }
160
161 /* This routine looks to see if the user has an alias defined for the given
162    address.                                                                 */
163 const address_t *alias_reverse_lookup(const address_t *a)
164 {
165     alias_t *list;
166
167     if (!a || !a->mailbox)
168         return NULL;
169
170     for (list = Aliases; list; list = list->next) {
171         address_t *ap;
172
173         /* cycle through all addresses if this is a group alias */
174         for (ap = list->addr; ap; ap = ap->next) {
175             if (!ap->group && ap->mailbox
176             &&  !ascii_strcasecmp(ap->mailbox, a->mailbox))
177                 return ap;
178         }
179     }
180
181     return NULL;
182 }
183
184 static int string_is_address(const char *str, const char *u, const char *d)
185 {
186     char buf[LONG_STRING];
187     snprintf(buf, sizeof (buf), "%s@%s", NONULL(u), NONULL(d));
188     return !ascii_strcasecmp(str, buf);
189 }
190
191 /* returns TRUE if the given address belongs to the user. */
192 int mutt_addr_is_user(address_t *addr)
193 {
194     /* NULL address is assumed to be the user. */
195     if (!addr)
196         return 1;
197
198     if (!addr->mailbox)
199         return 0;
200
201     if (!ascii_strcasecmp(addr->mailbox, mod_core.username)
202     ||  string_is_address(addr->mailbox, mod_core.username, mod_core.shorthost)
203     ||  string_is_address(addr->mailbox, mod_core.username, mutt_fqdn(0))
204     ||  string_is_address(addr->mailbox, mod_core.username, mutt_fqdn(1))
205     ||  (MAlias.from && !ascii_strcasecmp(MAlias.from->mailbox, addr->mailbox)))
206     {
207         return 1;
208     }
209
210     return rx_list_match(Alternates, addr->mailbox)
211         && !rx_list_match(UnAlternates, addr->mailbox);
212 }
213
214 address_t *mutt_get_address(ENVELOPE *env, const char **pfxp)
215 {
216 #define RETURN(s, adr)  do { if (pfxp) *pfxp = s; return adr; } while (0)
217
218     if (mutt_addr_is_user(env->from)) {
219         if (env->to && !mutt_is_mail_list(env->to)) {
220             RETURN("To", env->to);
221         } else {
222             RETURN("Cc", env->cc);
223         }
224     } else {
225         if (env->reply_to && !mutt_is_mail_list(env->reply_to)) {
226             RETURN("Reply-To", env->reply_to);
227         } else {
228             RETURN("From", env->from);
229         }
230     }
231
232 #undef RETURN
233 }
234
235 /* Only characters which are non-special to both the RFC 822 and the mutt
236    configuration parser are permitted.                                      */
237 static int alias_sanitize(const char *s, char *d)
238 {
239     int rv = 0;
240
241     while (*s) {
242         if (isalnum((unsigned char)(*s)) || strchr("-_+=.", *s)) {
243             if (d)
244                 *d++ = *s;
245         } else {
246             if (!d)
247                 return -1;
248             *d++ = '_';
249             rv = -1;
250         }
251         s++;
252     }
253
254     if (d)
255         *d = '\0';
256     return rv;
257 }
258
259 /* 
260  * if someone has an address like
261  *      From: Michael `/bin/rm -f ~` Elkins <me@mutt.org>
262  * and the user creates an alias for this, Mutt could wind up executing
263  * the backtics because it writes aliases like
264  *      alias me Michael `/bin/rm -f ~` Elkins <me@mutt.org>
265  * To avoid this problem, use a backslash (\) to quote any backtics.  We also
266  * need to quote backslashes as well, since you could defeat the above by
267  * doing
268  *      From: Michael \`/bin/rm -f ~\` Elkins <me@mutt.org>
269  * since that would get aliased as
270  *      alias me Michael \\`/bin/rm -f ~\\` Elkins <me@mutt.org>
271  * which still gets evaluated because the double backslash is not a quote.
272  * 
273  * Additionally, we need to quote ' and " characters - otherwise, mutt will
274  * interpret them on the wrong parsing step.
275  * 
276  * $ wants to be quoted since it may indicate the start of an environment
277  * variable.
278  */
279 static void write_safe_address(FILE *fp, const char *s)
280 {
281     while (*s) {
282         if (strchr("\\`'\"$", *s)) {
283             fputc('\\', fp);
284         }
285         fputc(*s++, fp);
286     }
287     fputc('\n', fp);
288 }
289
290 void mutt_create_alias(ENVELOPE *cur, address_t *iadr)
291 {
292     char buf[LONG_STRING], prompt[STRING];
293     address_t *adr = iadr;
294     alias_t *new;
295     FILE *rc;
296
297     if (cur) {
298         adr = mutt_get_address(cur, NULL);
299     }
300
301     if (adr && adr->mailbox) {
302         const char *p = m_strchrnul(adr->mailbox, '@');
303         m_strncpy(buf, sizeof(buf), adr->mailbox, p - adr->mailbox);
304     } else {
305         buf[0] = '\0';
306     }
307
308     /* Don't suggest a bad alias name in the event of a strange local part. */
309     alias_sanitize(buf, buf);
310
311     /* add a new alias */
312     if (mutt_get_field(_("Alias as: "), buf, sizeof(buf), 0) || !buf[0])
313         return;
314
315     /* check to see if the user already has an alias defined */
316     if (alias_lookup(buf)) {
317         mutt_error _("You already have an alias defined with that name!");
318         return;
319     }
320
321     alias_sanitize(buf, buf);
322     new = alias_new();
323     new->name = m_strdup(buf);
324
325     mutt_addrlist_to_local(adr);
326     if (adr) {
327         m_strcpy(buf, sizeof(buf), adr->mailbox);
328     } else {
329         buf[0] = 0;
330     }
331
332     mutt_addrlist_to_idna(adr, NULL);
333
334     do {
335         char *err = NULL;
336
337         if (mutt_get_field(_("Address: "), buf, sizeof(buf), 0) || !buf[0]) {
338             alias_list_wipe(&new);
339             return;
340         }
341
342         new->addr = rfc822_parse_adrlist(new->addr, buf);
343         if (!new->addr)
344             BEEP();
345
346         if (mutt_addrlist_to_idna(new->addr, &err)) {
347             mutt_error(_("Error: '%s' is a bad IDN."), err);
348             p_delete(&err);
349             mutt_sleep(1);
350             continue;
351         }
352     } while (!new->addr);
353
354     if (adr && adr->personal && !mutt_is_mail_list(adr)) {
355         m_strcpy(buf, sizeof(buf), adr->personal);
356     } else {
357         buf[0] = '\0';
358     }
359
360     if (mutt_get_field(_("Personal name: "), buf, sizeof(buf), 0)) {
361         alias_list_wipe(&new);
362         return;
363     }
364     new->addr->personal = m_strdup(buf);
365
366     buf[0] = '\0';
367     rfc822_addrcat(buf, sizeof(buf), new->addr, 1);
368     snprintf(prompt, sizeof(prompt), _("[%s = %s] Accept?"), new->name, buf);
369     if (mutt_yesorno(prompt, M_YES) != M_YES) {
370         alias_list_wipe(&new);
371         return;
372     }
373
374     alias_list_push(&Aliases, new);
375
376     m_strcpy(buf, sizeof(buf), NONULL(MAlias.alias_file));
377     if (mutt_get_field(_("Save to file: "), buf, sizeof(buf), M_FILE)) {
378         return;
379     }
380
381     mutt_expand_path(buf, sizeof(buf));
382     rc = safe_fopen (buf, "a");
383
384     if (rc) {
385         if (alias_sanitize(new->name, NULL)) {
386             mutt_quote_filename(buf, sizeof(buf), new->name);
387             fprintf(rc, "alias %s ", buf);
388         } else {
389             fprintf(rc, "alias %s ", new->name);
390         }
391
392         buf[0] = '\0';
393         rfc822_addrcat(buf, sizeof(buf), new->addr, 0);
394         write_safe_address(rc, buf);
395         m_fclose(&rc);
396         mutt_message _("Alias added.");
397     } else {
398         mutt_perror(buf);
399     }
400 }
401
402 static address_t *mutt_expand_aliases_r(address_t *a, string_list_t **expn)
403 {
404     address_t *pop, *head = NULL;
405     address_t **last = &head;
406
407     while ((pop = address_list_pop(&a))) {
408         if (!pop->group && !pop->personal
409         &&  pop->mailbox && !strchr(pop->mailbox, '@'))
410         {
411             const address_t *t = alias_lookup(pop->mailbox);
412
413             if (t) {
414                 string_list_t *u;
415
416                 for (u = *expn; u; u = u->next) {
417                     if (!m_strcmp(pop->mailbox, u->data)) { /* alias already found */
418                         address_list_wipe(&pop);
419                         continue;
420                     }
421                 }
422
423                 /* save the fact we saw it */
424                 u = string_item_new();
425                 u->data = m_strdup(pop->mailbox);
426                 u->next = *expn;
427                 *expn = u;
428                 address_list_wipe(&pop);
429
430                 /* recurse */
431                 last  = address_list_last(last);
432                 *last = mutt_expand_aliases_r(address_list_dup(t), expn);
433                 continue;
434             } else {
435                 struct passwd *pw = getpwnam(pop->mailbox);
436
437                 if (pw) {
438                     char namebuf[STRING];
439                     mutt_gecos_name(namebuf, sizeof(namebuf), pw, mod_core.gecos_mask);
440                     m_strreplace(&pop->personal, namebuf);
441                 }
442             }
443         }
444
445         last = address_list_append(last, pop);
446     }
447
448     if (mod_core.use_domain) {
449         /* now qualify all local addresses */
450         rfc822_qualify(head, mutt_fqdn(1));
451     }
452
453     return head;
454 }
455
456 address_t *mutt_expand_aliases(address_t *a)
457 {
458     address_t *t;
459     string_list_t *expn = NULL;            /* previously expanded aliases to avoid loops */
460
461     t = mutt_expand_aliases_r(a, &expn);
462     string_list_wipe(&expn);
463     address_list_uniq(t);
464     return t;
465 }
466
467 void mutt_expand_aliases_env(ENVELOPE *env)
468 {
469     env->from = mutt_expand_aliases(env->from);
470     env->to = mutt_expand_aliases(env->to);
471     env->cc = mutt_expand_aliases(env->cc);
472     env->bcc = mutt_expand_aliases(env->bcc);
473     env->reply_to = mutt_expand_aliases(env->reply_to);
474     env->mail_followup_to = mutt_expand_aliases(env->mail_followup_to);
475 }
476
477 /************* READ MARK *********************/
478
479 /* alias_complete() -- alias completion routine
480  *
481  * given a partial alias, this routine attempts to fill in the alias
482  * from the alias list as much as possible. if given empty search string
483  * or found nothing, present all aliases
484  */
485 int mutt_alias_complete (char *s, size_t buflen)
486 {
487   alias_t *a = Aliases;
488   alias_t *a_list = NULL, *a_cur = NULL;
489   char bestname[HUGE_STRING];
490   int i;
491
492 #define min(a,b)        ((a<b)?a:b)
493
494   if (s[0] != 0) {              /* avoid empty string as strstr argument */
495     p_clear(bestname, countof(bestname));
496
497     while (a) {
498       if (a->name && strstr (a->name, s) == a->name) {
499         if (!bestname[0])       /* init */
500           m_strcpy(bestname, MIN(m_strlen(a->name) + 1, ssizeof(bestname)),
501                    a->name);
502         else {
503           for (i = 0; a->name[i] && a->name[i] == bestname[i]; i++);
504           bestname[i] = 0;
505         }
506       }
507       a = a->next;
508     }
509
510     if (bestname[0] != 0) {
511       if (m_strcmp(bestname, s) != 0) {
512         /* we are adding something to the completion */
513         m_strcpy(s, m_strlen(bestname) + 1, bestname);
514         return 1;
515       }
516
517       /* build alias list and show it */
518
519       a = Aliases;
520       while (a) {
521         if (a->name && (strstr (a->name, s) == a->name)) {
522           if (!a_list)          /* init */
523             a_cur = a_list = alias_new();
524           else {
525             a_cur->next = alias_new();
526             a_cur = a_cur->next;
527           }
528           *a_cur = *a;
529           a_cur->next = NULL;
530         }
531         a = a->next;
532       }
533     }
534   }
535
536   bestname[0] = 0;
537   mutt_alias_menu (bestname, sizeof (bestname), a_list ? a_list : Aliases);
538   if (bestname[0] != 0)
539     m_strcpy(s, buflen, bestname);
540
541   /* free the alias list */
542   while (a_list) {
543     a_cur = a_list;
544     a_list = a_list->next;
545     p_delete(&a_cur);
546   }
547
548   /* remove any aliases marked for deletion */
549   a_list = NULL;
550   for (a_cur = Aliases; a_cur;) {
551     if (a_cur->del) {
552       if (a_list)
553         a_list->next = a_cur->next;
554       else
555         Aliases = a_cur->next;
556
557       a_cur->next = NULL;
558       alias_list_wipe(&a_cur);
559
560       if (a_list)
561         a_cur = a_list;
562       else
563         a_cur = Aliases;
564     }
565     else {
566       a_list = a_cur;
567       a_cur = a_cur->next;
568     }
569   }
570
571   return 0;
572 }
573
574 static const char *
575 alias_format_str(char *dest, ssize_t destlen, char op, const char *src,
576                  const char *fmt, const char *ifstr __attribute__ ((unused)),
577                  const char *elstr __attribute__ ((unused)),
578                  anytype data, format_flag flags __attribute__ ((unused)))
579 {
580   char tmp[STRING], adr[STRING];
581   alias_t *alias = data.ptr;
582
583   switch (op) {
584   case 'f':
585     m_strputc(dest, destlen, alias->del ? 'D' : ' ');
586     break;
587   case 'a':
588     mutt_format_s(dest, destlen, fmt, alias->name);
589     break;
590   case 'r':
591     adr[0] = '\0';
592     rfc822_addrcat(adr, sizeof(adr), alias->addr, 1);
593     snprintf(tmp, sizeof(tmp), "%%%ss", fmt);
594     snprintf(dest, destlen, tmp, adr);
595     break;
596   case 'n':
597     snprintf(tmp, sizeof(tmp), "%%%sd", fmt);
598     snprintf(dest, destlen, tmp, alias->num + 1);
599     break;
600   case 't':
601     m_strputc(dest, destlen, alias->tagged ? '*' : ' ');
602     break;
603   }
604
605   return src;
606 }
607
608 static void alias_entry(char *s, ssize_t slen, MUTTMENU *m, int num)
609 {
610     m_strformat(s, slen, getmaxx(main_w), MAlias.alias_format, alias_format_str,
611                 ((alias_t **)m->data)[num], 0);
612 }
613
614 static int alias_tag (MUTTMENU * menu, int n, int m)
615 {
616   alias_t *cur = ((alias_t **) menu->data)[n];
617   int ot = cur->tagged;
618
619   cur->tagged = (m >= 0 ? m : !cur->tagged);
620
621   return cur->tagged - ot;
622 }
623
624 static int alias_SortAlias (const void *a, const void *b)
625 {
626   alias_t *pa = *(alias_t **) a;
627   alias_t *pb = *(alias_t **) b;
628   int r = m_strcasecmp(pa->name, pb->name);
629
630   return (RSORT (r));
631 }
632
633 static int alias_SortAddress (const void *a, const void *b)
634 {
635   address_t *pa = (*(alias_t **) a)->addr;
636   address_t *pb = (*(alias_t **) b)->addr;
637   int r;
638
639   if (pa == pb)
640     r = 0;
641   else if (pa == NULL)
642     r = -1;
643   else if (pb == NULL)
644     r = 1;
645   else if (pa->personal) {
646     if (pb->personal)
647       r = m_strcasecmp(pa->personal, pb->personal);
648     else
649       r = 1;
650   }
651   else if (pb->personal)
652     r = -1;
653   else
654     r = ascii_strcasecmp (pa->mailbox, pb->mailbox);
655   return (RSORT (r));
656 }
657
658 void mutt_alias_menu (char *buf, size_t buflen, alias_t * aliases)
659 {
660   alias_t *aliasp;
661   MUTTMENU *menu;
662   alias_t **AliasTable = NULL;
663   int t = -1;
664   int i, done = 0;
665   int op;
666
667   int omax;
668
669   if (!aliases) {
670     mutt_error _("You have no aliases!");
671
672     return;
673   }
674
675   /* tell whoever called me to redraw the screen when I return */
676   set_option (OPTNEEDREDRAW);
677
678   menu = mutt_new_menu ();
679   menu->make_entry = alias_entry;
680   menu->tag = alias_tag;
681   menu->menu = MENU_ALIAS;
682   menu->title = _("Aliases");
683
684 new_aliases:
685
686   omax = menu->max;
687
688   /* count the number of aliases */
689   for (aliasp = aliases; aliasp; aliasp = aliasp->next) {
690     aliasp->del = 0;
691     aliasp->tagged = 0;
692     menu->max++;
693   }
694
695   p_realloc(&AliasTable, menu->max);
696   menu->data = AliasTable;
697
698   for (i = omax, aliasp = aliases; aliasp; aliasp = aliasp->next, i++) {
699     AliasTable[i] = aliasp;
700     aliases = aliasp;
701   }
702
703   if ((SortAlias & SORT_MASK) != SORT_ORDER) {
704     qsort (AliasTable, i, sizeof (alias_t *),
705            (SortAlias & SORT_MASK) ==
706            SORT_ADDRESS ? alias_SortAddress : alias_SortAlias);
707   }
708
709   for (i = 0; i < menu->max; i++)
710     AliasTable[i]->num = i;
711
712   while (!done) {
713     if (aliases->next) {
714       menu->redraw |= REDRAW_FULL;
715       aliases = aliases->next;
716       goto new_aliases;
717     }
718
719     switch ((op = mutt_menuLoop (menu))) {
720     case OP_DELETE:
721     case OP_UNDELETE:
722       if (menu->tagprefix) {
723         for (i = 0; i < menu->max; i++)
724           if (AliasTable[i]->tagged)
725             AliasTable[i]->del = (op == OP_DELETE) ? 1 : 0;
726         menu->redraw |= REDRAW_INDEX;
727       }
728       else {
729         AliasTable[menu->current]->del = (op == OP_DELETE) ? 1 : 0;
730         menu->redraw |= REDRAW_CURRENT;
731         if (option (OPTRESOLVE) && menu->current < menu->max - 1) {
732           menu->current++;
733           menu->redraw |= REDRAW_INDEX;
734         }
735       }
736       break;
737     case OP_GENERIC_SELECT_ENTRY:
738       t = menu->current;
739     case OP_EXIT:
740       done = 1;
741       break;
742     }
743   }
744
745   for (i = 0; i < menu->max; i++) {
746     if (AliasTable[i]->tagged) {
747       mutt_addrlist_to_local (AliasTable[i]->addr);
748       rfc822_addrcat(buf, buflen, AliasTable[i]->addr, 0);
749       t = -1;
750     }
751   }
752
753   if (t != -1) {
754     mutt_addrlist_to_local (AliasTable[t]->addr);
755     rfc822_addrcat(buf, buflen, AliasTable[t]->addr, 0);
756   }
757
758   mutt_menuDestroy (&menu);
759   p_delete(&AliasTable);
760 }
761
762 /* vim:set ft=c: */