From 25575bbdaea8a736cd3013401cba05a375dd0cf0 Mon Sep 17 00:00:00 2001 From: Rocco Rutte Date: Wed, 13 May 2009 12:52:37 +0200 Subject: [PATCH] Prune empty address groups when preparing replies. Closes #2875. --- ChangeLog | 13 +++++++++++++ alias.c | 2 +- crypt-gpgme.c | 2 +- group.c | 2 +- mbox.c | 4 ++-- pgp.c | 2 +- query.c | 6 +++--- rfc822.c | 13 +++++++++---- rfc822.h | 4 ++-- send.c | 28 ++++++++++++++-------------- smime.c | 2 +- 11 files changed, 48 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index b18b645ba..45db1ed7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2009-05-13 12:21 +0200 Rocco Rutte (ce0e5c895032) + + * mbox.c: Actually reopen mbox/mmdf files in case we find + modifications. Closes #2725. + + Since the file is changed while we have it open in ctx->fp, we + likely get wrong information when parsing the mailbox. Now we + explicitely close and (re)open it. + +2009-05-12 16:26 +0200 Rocco Rutte (06e318bfe8f2) + + * ChangeLog, mbox.c: Backout errorneously commited mbox atime fix + 2009-05-12 15:21 +0200 Rocco Rutte (644cfc8070f7) * OPS, mbox.c: Fix description for diff --git a/alias.c b/alias.c index c5651037c..a8fa61f75 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; diff --git a/crypt-gpgme.c b/crypt-gpgme.c index 244293f5a..2dc4f0ad6 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -4237,7 +4237,7 @@ static char *find_keys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc, default: abort (); } - *last = rfc822_cpy_adr (p); + *last = rfc822_cpy_adr (p, 0); while (*last) last = &((*last)->next); } diff --git a/group.c b/group.c index 030c451c4..7f8206bac 100644 --- a/group.c +++ b/group.c @@ -86,7 +86,7 @@ void mutt_group_add_adrlist (group_t *g, ADDRESS *a) for (p = &g->as; *p; p = &((*p)->next)) ; - q = rfc822_cpy_adr (a); + q = rfc822_cpy_adr (a, 0); q = mutt_remove_xrefs (g->as, q); *p = q; } diff --git a/mbox.c b/mbox.c index bab8ce9ee..06fdea998 100644 --- a/mbox.c +++ b/mbox.c @@ -208,7 +208,7 @@ int mmdf_parse_mailbox (CONTEXT *ctx) hdr->env->return_path = rfc822_parse_adrlist (hdr->env->return_path, return_path); if (!hdr->env->from) - hdr->env->from = rfc822_cpy_adr (hdr->env->return_path); + hdr->env->from = rfc822_cpy_adr (hdr->env->return_path, 0); ctx->msgcount++; } @@ -383,7 +383,7 @@ int mbox_parse_mailbox (CONTEXT *ctx) curhdr->env->return_path = rfc822_parse_adrlist (curhdr->env->return_path, return_path); if (!curhdr->env->from) - curhdr->env->from = rfc822_cpy_adr (curhdr->env->return_path); + curhdr->env->from = rfc822_cpy_adr (curhdr->env->return_path, 0); lines = 0; } diff --git a/pgp.c b/pgp.c index c03627f21..6aa473ecd 100644 --- a/pgp.c +++ b/pgp.c @@ -1175,7 +1175,7 @@ char *pgp_findKeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) default: abort (); } - *last = rfc822_cpy_adr (p); + *last = rfc822_cpy_adr (p, 0); while (*last) last = &((*last)->next); } diff --git a/query.c b/query.c index 6a3ca0790..283aad75c 100644 --- a/query.c +++ b/query.c @@ -60,7 +60,7 @@ static ADDRESS *result_to_addr (QUERY *r) { static ADDRESS *tmp; - if (!(tmp = rfc822_cpy_adr (r->addr))) + if (!(tmp = rfc822_cpy_adr (r->addr, 0))) return NULL; if(!tmp->next && !tmp->personal) @@ -426,7 +426,7 @@ static void query_menu (char *buf, size_t buflen, QUERY *results, int retbuf) if (QueryTable[i].tagged) { ADDRESS *a = result_to_addr(QueryTable[i].data); - rfc822_append (&naddr, a); + rfc822_append (&naddr, a, 0); rfc822_free_address (&a); } @@ -461,7 +461,7 @@ static void query_menu (char *buf, size_t buflen, QUERY *results, int retbuf) if (QueryTable[i].tagged) { ADDRESS *a = result_to_addr(QueryTable[i].data); - rfc822_append (&msg->env->to, a); + rfc822_append (&msg->env->to, a, 0); rfc822_free_address (&a); } } diff --git a/rfc822.c b/rfc822.c index 6676d1d5b..3a04bd407 100644 --- a/rfc822.c +++ b/rfc822.c @@ -757,12 +757,17 @@ ADDRESS *rfc822_cpy_adr_real (ADDRESS *addr) } /* this should be rfc822_cpy_adrlist */ -ADDRESS *rfc822_cpy_adr (ADDRESS *addr) +ADDRESS *rfc822_cpy_adr (ADDRESS *addr, int prune) { ADDRESS *top = NULL, *last = NULL; for (; addr; addr = addr->next) { + if (prune && addr->group && (!addr->next || !addr->next->mailbox)) + { + addr = addr->next; + continue; + } if (last) { last->next = rfc822_cpy_adr_real (addr); @@ -775,7 +780,7 @@ ADDRESS *rfc822_cpy_adr (ADDRESS *addr) } /* append list 'b' to list 'a' and return the last element in the new list */ -ADDRESS *rfc822_append (ADDRESS **a, ADDRESS *b) +ADDRESS *rfc822_append (ADDRESS **a, ADDRESS *b, int prune) { ADDRESS *tmp = *a; @@ -784,9 +789,9 @@ ADDRESS *rfc822_append (ADDRESS **a, ADDRESS *b) if (!b) return tmp; if (tmp) - tmp->next = rfc822_cpy_adr (b); + tmp->next = rfc822_cpy_adr (b, prune); else - tmp = *a = rfc822_cpy_adr (b); + tmp = *a = rfc822_cpy_adr (b, prune); while (tmp && tmp->next) tmp = tmp->next; return tmp; diff --git a/rfc822.h b/rfc822.h index 65b7a5cd1..b645cc2fa 100644 --- a/rfc822.h +++ b/rfc822.h @@ -47,9 +47,9 @@ ADDRESS; void rfc822_free_address (ADDRESS **); void rfc822_qualify (ADDRESS *, const char *); ADDRESS *rfc822_parse_adrlist (ADDRESS *, const char *s); -ADDRESS *rfc822_cpy_adr (ADDRESS *addr); +ADDRESS *rfc822_cpy_adr (ADDRESS *addr, int); ADDRESS *rfc822_cpy_adr_real (ADDRESS *addr); -ADDRESS *rfc822_append (ADDRESS **a, ADDRESS *b); +ADDRESS *rfc822_append (ADDRESS **a, ADDRESS *b, int); int rfc822_write_address (char *, size_t, ADDRESS *, int); void rfc822_write_address_single (char *, size_t, ADDRESS *, int); void rfc822_free_address (ADDRESS **addr); diff --git a/send.c b/send.c index af91a6b22..768fc2357 100644 --- a/send.c +++ b/send.c @@ -451,7 +451,7 @@ static int default_to (ADDRESS **to, ENVELOPE *env, int flags, int hmfupto) if (flags && env->mail_followup_to && hmfupto == M_YES) { - rfc822_append (to, env->mail_followup_to); + rfc822_append (to, env->mail_followup_to, 1); return 0; } @@ -464,7 +464,7 @@ static int default_to (ADDRESS **to, ENVELOPE *env, int flags, int hmfupto) if (!option(OPTREPLYSELF) && mutt_addr_is_user (env->from)) { /* mail is from the user, assume replying to recipients */ - rfc822_append (to, env->to); + rfc822_append (to, env->to, 1); } else if (env->reply_to) { @@ -482,7 +482,7 @@ static int default_to (ADDRESS **to, ENVELOPE *env, int flags, int hmfupto) * in his From header. * */ - rfc822_append (to, env->from); + rfc822_append (to, env->from, 0); } else if (!(mutt_addrcmp (env->from, env->reply_to) && !env->reply_to->next) && @@ -499,11 +499,11 @@ static int default_to (ADDRESS **to, ENVELOPE *env, int flags, int hmfupto) switch (query_quadoption (OPT_REPLYTO, prompt)) { case M_YES: - rfc822_append (to, env->reply_to); + rfc822_append (to, env->reply_to, 0); break; case M_NO: - rfc822_append (to, env->from); + rfc822_append (to, env->from, 0); break; default: @@ -511,10 +511,10 @@ static int default_to (ADDRESS **to, ENVELOPE *env, int flags, int hmfupto) } } else - rfc822_append (to, env->reply_to); + rfc822_append (to, env->reply_to, 0); } else - rfc822_append (to, env->from); + rfc822_append (to, env->from, 0); return (0); } @@ -538,7 +538,7 @@ int mutt_fetch_recips (ENVELOPE *out, ENVELOPE *in, int flags) if (flags & SENDLISTREPLY) { tmp = find_mailing_lists (in->to, in->cc); - rfc822_append (&out->to, tmp); + rfc822_append (&out->to, tmp, 0); rfc822_free_address (&tmp); if (in->mail_followup_to && hmfupto == M_YES && @@ -553,8 +553,8 @@ int mutt_fetch_recips (ENVELOPE *out, ENVELOPE *in, int flags) if ((flags & SENDGROUPREPLY) && (!in->mail_followup_to || hmfupto != M_YES)) { /* if(!mutt_addr_is_user(in->to)) */ - rfc822_append (&out->cc, in->to); - rfc822_append (&out->cc, in->cc); + rfc822_append (&out->cc, in->to, 1); + rfc822_append (&out->cc, in->cc, 1); } } return 0; @@ -869,8 +869,8 @@ void mutt_set_followup_to (ENVELOPE *e) * mail-followup-to header */ - t = rfc822_append (&e->mail_followup_to, e->to); - rfc822_append (&t, e->cc); + t = rfc822_append (&e->mail_followup_to, e->to, 0); + rfc822_append (&t, e->cc, 1); } /* remove ourselves from the mail-followup-to header */ @@ -886,9 +886,9 @@ void mutt_set_followup_to (ENVELOPE *e) if (e->mail_followup_to && !mutt_is_list_recipient (0, e->to, e->cc)) { if (e->reply_to) - from = rfc822_cpy_adr (e->reply_to); + from = rfc822_cpy_adr (e->reply_to, 0); else if (e->from) - from = rfc822_cpy_adr (e->from); + from = rfc822_cpy_adr (e->from, 0); else from = mutt_default_from (); diff --git a/smime.c b/smime.c index 997ff757e..d66949381 100644 --- a/smime.c +++ b/smime.c @@ -767,7 +767,7 @@ char *smime_findKeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) default: abort (); } - *last = rfc822_cpy_adr (p); + *last = rfc822_cpy_adr (p, 0); while (*last) last = &((*last)->next); } -- 2.40.0