simplify newsrc parsing
[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/curses.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 struct mapping_t AliasHelp[] = {
148     {N_("Exit"), OP_EXIT},
149     {N_("Del"), OP_DELETE},
150     {N_("Undel"), OP_UNDELETE},
151     {N_("Select"), OP_GENERIC_SELECT_ENTRY},
152     {N_("Help"), OP_HELP},
153     {NULL, OP_NULL}
154 };
155
156 static void mutt_alias_menu(char *, size_t, alias_t *);
157
158 const address_t *alias_lookup(const char *s)
159 {
160     alias_t *list;
161
162     for (list = Aliases; list; list = list->next) {
163         if (!m_strcasecmp(s, list->name))
164             return list->addr;
165     }
166
167     return NULL;
168 }
169
170 /* This routine looks to see if the user has an alias defined for the given
171    address.                                                                 */
172 const address_t *alias_reverse_lookup(const address_t *a)
173 {
174     alias_t *list;
175
176     if (!a || !a->mailbox)
177         return NULL;
178
179     for (list = Aliases; list; list = list->next) {
180         address_t *ap;
181
182         /* cycle through all addresses if this is a group alias */
183         for (ap = list->addr; ap; ap = ap->next) {
184             if (!ap->group && ap->mailbox
185             &&  !ascii_strcasecmp(ap->mailbox, a->mailbox))
186                 return ap;
187         }
188     }
189
190     return NULL;
191 }
192
193 static int string_is_address(const char *str, const char *u, const char *d)
194 {
195     char buf[LONG_STRING];
196     snprintf(buf, sizeof (buf), "%s@%s", NONULL(u), NONULL(d));
197     return !ascii_strcasecmp(str, buf);
198 }
199
200 /* returns TRUE if the given address belongs to the user. */
201 int mutt_addr_is_user(address_t *addr)
202 {
203     /* NULL address is assumed to be the user. */
204     if (!addr)
205         return 1;
206
207     if (!addr->mailbox)
208         return 0;
209
210     if (!ascii_strcasecmp(addr->mailbox, mod_core.username)
211     ||  string_is_address(addr->mailbox, mod_core.username, mod_core.shorthost)
212     ||  string_is_address(addr->mailbox, mod_core.username, mutt_fqdn(0))
213     ||  string_is_address(addr->mailbox, mod_core.username, mutt_fqdn(1))
214     ||  (MAlias.from && !ascii_strcasecmp(MAlias.from->mailbox, addr->mailbox)))
215     {
216         return 1;
217     }
218
219     return rx_list_match(Alternates, addr->mailbox)
220         && !rx_list_match(UnAlternates, addr->mailbox);
221 }
222
223 address_t *mutt_get_address(ENVELOPE *env, const char **pfxp)
224 {
225 #define RETURN(s, adr)  do { if (pfxp) *pfxp = s; return adr; } while (0)
226
227     if (mutt_addr_is_user(env->from)) {
228         if (env->to && !mutt_is_mail_list(env->to)) {
229             RETURN("To", env->to);
230         } else {
231             RETURN("Cc", env->cc);
232         }
233     } else {
234         if (env->reply_to && !mutt_is_mail_list(env->reply_to)) {
235             RETURN("Reply-To", env->reply_to);
236         } else {
237             RETURN("From", env->from);
238         }
239     }
240
241 #undef RETURN
242 }
243
244 /* Only characters which are non-special to both the RFC 822 and the mutt
245    configuration parser are permitted.                                      */
246 static int alias_sanitize(const char *s, char *d)
247 {
248     int rv = 0;
249
250     while (*s) {
251         if (isalnum((unsigned char)(*s)) || strchr("-_+=.", *s)) {
252             if (d)
253                 *d++ = *s;
254         } else {
255             if (!d)
256                 return -1;
257             *d++ = '_';
258             rv = -1;
259         }
260         s++;
261     }
262
263     if (d)
264         *d = '\0';
265     return rv;
266 }
267
268 /* 
269  * if someone has an address like
270  *      From: Michael `/bin/rm -f ~` Elkins <me@mutt.org>
271  * and the user creates an alias for this, Mutt could wind up executing
272  * the backtics because it writes aliases like
273  *      alias me Michael `/bin/rm -f ~` Elkins <me@mutt.org>
274  * To avoid this problem, use a backslash (\) to quote any backtics.  We also
275  * need to quote backslashes as well, since you could defeat the above by
276  * doing
277  *      From: Michael \`/bin/rm -f ~\` Elkins <me@mutt.org>
278  * since that would get aliased as
279  *      alias me Michael \\`/bin/rm -f ~\\` Elkins <me@mutt.org>
280  * which still gets evaluated because the double backslash is not a quote.
281  * 
282  * Additionally, we need to quote ' and " characters - otherwise, mutt will
283  * interpret them on the wrong parsing step.
284  * 
285  * $ wants to be quoted since it may indicate the start of an environment
286  * variable.
287  */
288 static void write_safe_address(FILE *fp, const char *s)
289 {
290     while (*s) {
291         if (strchr("\\`'\"$", *s)) {
292             fputc('\\', fp);
293         }
294         fputc(*s++, fp);
295     }
296     fputc('\n', fp);
297 }
298
299 void mutt_create_alias(ENVELOPE *cur, address_t *iadr)
300 {
301     char buf[LONG_STRING], prompt[STRING];
302     address_t *adr = iadr;
303     alias_t *new;
304     FILE *rc;
305
306     if (cur) {
307         adr = mutt_get_address(cur, NULL);
308     }
309
310     if (adr && adr->mailbox) {
311         const char *p = m_strchrnul(adr->mailbox, '@');
312         m_strncpy(buf, sizeof(buf), adr->mailbox, p - adr->mailbox);
313     } else {
314         buf[0] = '\0';
315     }
316
317     /* Don't suggest a bad alias name in the event of a strange local part. */
318     alias_sanitize(buf, buf);
319
320     /* add a new alias */
321     if (mutt_get_field(_("Alias as: "), buf, sizeof(buf), 0) || !buf[0])
322         return;
323
324     /* check to see if the user already has an alias defined */
325     if (alias_lookup(buf)) {
326         mutt_error _("You already have an alias defined with that name!");
327         return;
328     }
329
330     alias_sanitize(buf, buf);
331     new = alias_new();
332     new->name = m_strdup(buf);
333
334     mutt_addrlist_to_local(adr);
335     if (adr) {
336         m_strcpy(buf, sizeof(buf), adr->mailbox);
337     } else {
338         buf[0] = 0;
339     }
340
341     mutt_addrlist_to_idna(adr, NULL);
342
343     do {
344         char *err = NULL;
345
346         if (mutt_get_field(_("Address: "), buf, sizeof(buf), 0) || !buf[0]) {
347             alias_list_wipe(&new);
348             return;
349         }
350
351         new->addr = rfc822_parse_adrlist(new->addr, buf);
352         if (!new->addr)
353             BEEP();
354
355         if (mutt_addrlist_to_idna(new->addr, &err)) {
356             mutt_error(_("Error: '%s' is a bad IDN."), err);
357             p_delete(&err);
358             mutt_sleep(1);
359             continue;
360         }
361     } while (!new->addr);
362
363     if (adr && adr->personal && !mutt_is_mail_list(adr)) {
364         m_strcpy(buf, sizeof(buf), adr->personal);
365     } else {
366         buf[0] = '\0';
367     }
368
369     if (mutt_get_field(_("Personal name: "), buf, sizeof(buf), 0)) {
370         alias_list_wipe(&new);
371         return;
372     }
373     new->addr->personal = m_strdup(buf);
374
375     buf[0] = '\0';
376     rfc822_addrcat(buf, sizeof(buf), new->addr, 1);
377     snprintf(prompt, sizeof(prompt), _("[%s = %s] Accept?"), new->name, buf);
378     if (mutt_yesorno(prompt, M_YES) != M_YES) {
379         alias_list_wipe(&new);
380         return;
381     }
382
383     alias_list_push(&Aliases, new);
384
385     m_strcpy(buf, sizeof(buf), NONULL(MAlias.alias_file));
386     if (mutt_get_field(_("Save to file: "), buf, sizeof(buf), M_FILE)) {
387         return;
388     }
389
390     mutt_expand_path(buf, sizeof(buf));
391     rc = safe_fopen (buf, "a");
392
393     if (rc) {
394         if (alias_sanitize(new->name, NULL)) {
395             mutt_quote_filename(buf, sizeof(buf), new->name);
396             fprintf(rc, "alias %s ", buf);
397         } else {
398             fprintf(rc, "alias %s ", new->name);
399         }
400
401         buf[0] = '\0';
402         rfc822_addrcat(buf, sizeof(buf), new->addr, 0);
403         write_safe_address(rc, buf);
404         m_fclose(&rc);
405         mutt_message _("Alias added.");
406     } else {
407         mutt_perror(buf);
408     }
409 }
410
411 static address_t *mutt_expand_aliases_r(address_t *a, string_list_t **expn)
412 {
413     address_t *pop, *head = NULL;
414     address_t **last = &head;
415
416     while ((pop = address_list_pop(&a))) {
417         if (!pop->group && !pop->personal
418         &&  pop->mailbox && !strchr(pop->mailbox, '@'))
419         {
420             const address_t *t = alias_lookup(pop->mailbox);
421
422             if (t) {
423                 string_list_t *u;
424
425                 for (u = *expn; u; u = u->next) {
426                     if (!m_strcmp(pop->mailbox, u->data)) { /* alias already found */
427                         address_list_wipe(&pop);
428                         continue;
429                     }
430                 }
431
432                 /* save the fact we saw it */
433                 u = string_item_new();
434                 u->data = m_strdup(pop->mailbox);
435                 u->next = *expn;
436                 *expn = u;
437                 address_list_wipe(&pop);
438
439                 /* recurse */
440                 last  = address_list_last(last);
441                 *last = mutt_expand_aliases_r(address_list_dup(t), expn);
442                 continue;
443             } else {
444                 struct passwd *pw = getpwnam(pop->mailbox);
445
446                 if (pw) {
447                     char namebuf[STRING];
448                     mutt_gecos_name(namebuf, sizeof(namebuf), pw, mod_core.gecos_mask);
449                     m_strreplace(&pop->personal, namebuf);
450                 }
451             }
452         }
453
454         last = address_list_append(last, pop);
455     }
456
457     if (mod_core.use_domain) {
458         /* now qualify all local addresses */
459         rfc822_qualify(head, mutt_fqdn(1));
460     }
461
462     return head;
463 }
464
465 address_t *mutt_expand_aliases(address_t *a)
466 {
467     address_t *t;
468     string_list_t *expn = NULL;            /* previously expanded aliases to avoid loops */
469
470     t = mutt_expand_aliases_r(a, &expn);
471     string_list_wipe(&expn);
472     address_list_uniq(t);
473     return t;
474 }
475
476 void mutt_expand_aliases_env(ENVELOPE *env)
477 {
478     env->from = mutt_expand_aliases(env->from);
479     env->to = mutt_expand_aliases(env->to);
480     env->cc = mutt_expand_aliases(env->cc);
481     env->bcc = mutt_expand_aliases(env->bcc);
482     env->reply_to = mutt_expand_aliases(env->reply_to);
483     env->mail_followup_to = mutt_expand_aliases(env->mail_followup_to);
484 }
485
486 /************* READ MARK *********************/
487
488 /* alias_complete() -- alias completion routine
489  *
490  * given a partial alias, this routine attempts to fill in the alias
491  * from the alias list as much as possible. if given empty search string
492  * or found nothing, present all aliases
493  */
494 int mutt_alias_complete (char *s, size_t buflen)
495 {
496   alias_t *a = Aliases;
497   alias_t *a_list = NULL, *a_cur = NULL;
498   char bestname[HUGE_STRING];
499   int i;
500
501 #define min(a,b)        ((a<b)?a:b)
502
503   if (s[0] != 0) {              /* avoid empty string as strstr argument */
504     p_clear(bestname, countof(bestname));
505
506     while (a) {
507       if (a->name && strstr (a->name, s) == a->name) {
508         if (!bestname[0])       /* init */
509           m_strcpy(bestname, MIN(m_strlen(a->name) + 1, ssizeof(bestname)),
510                    a->name);
511         else {
512           for (i = 0; a->name[i] && a->name[i] == bestname[i]; i++);
513           bestname[i] = 0;
514         }
515       }
516       a = a->next;
517     }
518
519     if (bestname[0] != 0) {
520       if (m_strcmp(bestname, s) != 0) {
521         /* we are adding something to the completion */
522         m_strcpy(s, m_strlen(bestname) + 1, bestname);
523         return 1;
524       }
525
526       /* build alias list and show it */
527
528       a = Aliases;
529       while (a) {
530         if (a->name && (strstr (a->name, s) == a->name)) {
531           if (!a_list)          /* init */
532             a_cur = a_list = alias_new();
533           else {
534             a_cur->next = alias_new();
535             a_cur = a_cur->next;
536           }
537           *a_cur = *a;
538           a_cur->next = NULL;
539         }
540         a = a->next;
541       }
542     }
543   }
544
545   bestname[0] = 0;
546   mutt_alias_menu (bestname, sizeof (bestname), a_list ? a_list : Aliases);
547   if (bestname[0] != 0)
548     m_strcpy(s, buflen, bestname);
549
550   /* free the alias list */
551   while (a_list) {
552     a_cur = a_list;
553     a_list = a_list->next;
554     p_delete(&a_cur);
555   }
556
557   /* remove any aliases marked for deletion */
558   a_list = NULL;
559   for (a_cur = Aliases; a_cur;) {
560     if (a_cur->del) {
561       if (a_list)
562         a_list->next = a_cur->next;
563       else
564         Aliases = a_cur->next;
565
566       a_cur->next = NULL;
567       alias_list_wipe(&a_cur);
568
569       if (a_list)
570         a_cur = a_list;
571       else
572         a_cur = Aliases;
573     }
574     else {
575       a_list = a_cur;
576       a_cur = a_cur->next;
577     }
578   }
579
580   return 0;
581 }
582
583 static const char *
584 alias_format_str(char *dest, ssize_t destlen, char op, const char *src,
585                  const char *fmt, const char *ifstr __attribute__ ((unused)),
586                  const char *elstr __attribute__ ((unused)),
587                  anytype data, format_flag flags __attribute__ ((unused)))
588 {
589   char tmp[STRING], adr[STRING];
590   alias_t *alias = data.ptr;
591
592   switch (op) {
593   case 'f':
594     m_strputc(dest, destlen, alias->del ? 'D' : ' ');
595     break;
596   case 'a':
597     mutt_format_s(dest, destlen, fmt, alias->name);
598     break;
599   case 'r':
600     adr[0] = '\0';
601     rfc822_addrcat(adr, sizeof(adr), alias->addr, 1);
602     snprintf(tmp, sizeof(tmp), "%%%ss", fmt);
603     snprintf(dest, destlen, tmp, adr);
604     break;
605   case 'n':
606     snprintf(tmp, sizeof(tmp), "%%%sd", fmt);
607     snprintf(dest, destlen, tmp, alias->num + 1);
608     break;
609   case 't':
610     m_strputc(dest, destlen, alias->tagged ? '*' : ' ');
611     break;
612   }
613
614   return src;
615 }
616
617 static void alias_entry(char *s, ssize_t slen, MUTTMENU *m, int num)
618 {
619     m_strformat(s, slen, COLS - SW, MAlias.alias_format, alias_format_str,
620                 ((alias_t **)m->data)[num], 0);
621 }
622
623 static int alias_tag (MUTTMENU * menu, int n, int m)
624 {
625   alias_t *cur = ((alias_t **) menu->data)[n];
626   int ot = cur->tagged;
627
628   cur->tagged = (m >= 0 ? m : !cur->tagged);
629
630   return cur->tagged - ot;
631 }
632
633 static int alias_SortAlias (const void *a, const void *b)
634 {
635   alias_t *pa = *(alias_t **) a;
636   alias_t *pb = *(alias_t **) b;
637   int r = m_strcasecmp(pa->name, pb->name);
638
639   return (RSORT (r));
640 }
641
642 static int alias_SortAddress (const void *a, const void *b)
643 {
644   address_t *pa = (*(alias_t **) a)->addr;
645   address_t *pb = (*(alias_t **) b)->addr;
646   int r;
647
648   if (pa == pb)
649     r = 0;
650   else if (pa == NULL)
651     r = -1;
652   else if (pb == NULL)
653     r = 1;
654   else if (pa->personal) {
655     if (pb->personal)
656       r = m_strcasecmp(pa->personal, pb->personal);
657     else
658       r = 1;
659   }
660   else if (pb->personal)
661     r = -1;
662   else
663     r = ascii_strcasecmp (pa->mailbox, pb->mailbox);
664   return (RSORT (r));
665 }
666
667 void mutt_alias_menu (char *buf, size_t buflen, alias_t * aliases)
668 {
669   alias_t *aliasp;
670   MUTTMENU *menu;
671   alias_t **AliasTable = NULL;
672   int t = -1;
673   int i, done = 0;
674   int op;
675   char helpstr[STRING];
676
677   int omax;
678
679   if (!aliases) {
680     mutt_error _("You have no aliases!");
681
682     return;
683   }
684
685   /* tell whoever called me to redraw the screen when I return */
686   set_option (OPTNEEDREDRAW);
687
688   menu = mutt_new_menu ();
689   menu->make_entry = alias_entry;
690   menu->tag = alias_tag;
691   menu->menu = MENU_ALIAS;
692   menu->title = _("Aliases");
693   menu->help = mutt_compile_help(helpstr, sizeof(helpstr),
694                                  MENU_ALIAS, AliasHelp);
695
696 new_aliases:
697
698   omax = menu->max;
699
700   /* count the number of aliases */
701   for (aliasp = aliases; aliasp; aliasp = aliasp->next) {
702     aliasp->del = 0;
703     aliasp->tagged = 0;
704     menu->max++;
705   }
706
707   p_realloc(&AliasTable, menu->max);
708   menu->data = AliasTable;
709
710   for (i = omax, aliasp = aliases; aliasp; aliasp = aliasp->next, i++) {
711     AliasTable[i] = aliasp;
712     aliases = aliasp;
713   }
714
715   if ((SortAlias & SORT_MASK) != SORT_ORDER) {
716     qsort (AliasTable, i, sizeof (alias_t *),
717            (SortAlias & SORT_MASK) ==
718            SORT_ADDRESS ? alias_SortAddress : alias_SortAlias);
719   }
720
721   for (i = 0; i < menu->max; i++)
722     AliasTable[i]->num = i;
723
724   while (!done) {
725     if (aliases->next) {
726       menu->redraw |= REDRAW_FULL;
727       aliases = aliases->next;
728       goto new_aliases;
729     }
730
731     switch ((op = mutt_menuLoop (menu))) {
732     case OP_DELETE:
733     case OP_UNDELETE:
734       if (menu->tagprefix) {
735         for (i = 0; i < menu->max; i++)
736           if (AliasTable[i]->tagged)
737             AliasTable[i]->del = (op == OP_DELETE) ? 1 : 0;
738         menu->redraw |= REDRAW_INDEX;
739       }
740       else {
741         AliasTable[menu->current]->del = (op == OP_DELETE) ? 1 : 0;
742         menu->redraw |= REDRAW_CURRENT;
743         if (option (OPTRESOLVE) && menu->current < menu->max - 1) {
744           menu->current++;
745           menu->redraw |= REDRAW_INDEX;
746         }
747       }
748       break;
749     case OP_GENERIC_SELECT_ENTRY:
750       t = menu->current;
751     case OP_EXIT:
752       done = 1;
753       break;
754     }
755   }
756
757   for (i = 0; i < menu->max; i++) {
758     if (AliasTable[i]->tagged) {
759       mutt_addrlist_to_local (AliasTable[i]->addr);
760       rfc822_addrcat(buf, buflen, AliasTable[i]->addr, 0);
761       t = -1;
762     }
763   }
764
765   if (t != -1) {
766     mutt_addrlist_to_local (AliasTable[t]->addr);
767     rfc822_addrcat(buf, buflen, AliasTable[t]->addr, 0);
768   }
769
770   mutt_menuDestroy (&menu);
771   p_delete(&AliasTable);
772 }
773
774 /* vim:set ft=c: */