+ address_t *pop, *head = NULL;
+ address_t **last = &head;
+
+ while ((pop = address_list_pop(&a))) {
+ if (!pop->group && !pop->personal
+ && pop->mailbox && !strchr(pop->mailbox, '@'))
+ {
+ const address_t *t = alias_lookup(pop->mailbox);
+
+ if (t) {
+ string_list_t *u;
+
+ for (u = *expn; u; u = u->next) {
+ if (!m_strcmp(pop->mailbox, u->data)) { /* alias already found */
+ address_list_wipe(&pop);
+ continue;
+ }
+ }
+
+ /* save the fact we saw it */
+ u = string_item_new();
+ u->data = m_strdup(pop->mailbox);
+ u->next = *expn;
+ *expn = u;
+ address_list_wipe(&pop);
+
+ /* recurse */
+ last = address_list_last(last);
+ *last = mutt_expand_aliases_r(address_list_dup(t), expn);
+ continue;
+ } else {
+ struct passwd *pw = getpwnam(pop->mailbox);
+
+ if (pw) {
+ char namebuf[STRING];
+ mutt_gecos_name(namebuf, sizeof(namebuf), pw, GecosMask.rx);
+ m_strreplace(&pop->personal, namebuf);
+ }
+ }
+ }