From 22116d7063ab4d7de33946d74ab8b9cbc0f3f6ef Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Wed, 29 Nov 2006 02:10:17 +0100 Subject: [PATCH] various code simplifications. Signed-off-by: Pierre Habouzit --- alias.c | 4 +- lib-crypt/crypt-gpgme.c | 7 +-- lib-crypt/pgp.c | 6 +- lib-crypt/smime.c | 5 +- lib-mime/rfc822address.c | 5 +- remailer.c | 13 ++--- send.c | 123 +++++++++++++++++++-------------------- sendlib.c | 4 +- 8 files changed, 75 insertions(+), 92 deletions(-) diff --git a/alias.c b/alias.c index 68afc25..8d48a78 100644 --- a/alias.c +++ b/alias.c @@ -355,9 +355,7 @@ static address_t *mutt_expand_aliases_r(address_t *a, string_list_t **expn) if (option(OPTUSEDOMAIN)) { /* now qualify all local addresses */ - const char *fqdn = mutt_fqdn(1); - if (fqdn) - rfc822_qualify(head, fqdn); + rfc822_qualify(head, mutt_fqdn(1)); } return head; diff --git a/lib-crypt/crypt-gpgme.c b/lib-crypt/crypt-gpgme.c index 7e3495b..9790164 100644 --- a/lib-crypt/crypt-gpgme.c +++ b/lib-crypt/crypt-gpgme.c @@ -3649,9 +3649,7 @@ static char *find_keys (address_t * to, address_t * cc, address_t * bcc, last = &((*last)->next); } - if (fqdn) - rfc822_qualify (tmp, fqdn); - + rfc822_qualify(tmp, fqdn); address_list_uniq(tmp); for (p = tmp; p; p = p->next) { @@ -3670,8 +3668,7 @@ static char *find_keys (address_t * to, address_t * cc, address_t * bcc, /* check for e-mail address */ if ((t = strchr (keyID, '@')) && (addr = rfc822_parse_adrlist (NULL, keyID))) { - if (fqdn) - rfc822_qualify (addr, fqdn); + rfc822_qualify(addr, fqdn); q = addr; } else { diff --git a/lib-crypt/pgp.c b/lib-crypt/pgp.c index 7a23728..c58664c 100644 --- a/lib-crypt/pgp.c +++ b/lib-crypt/pgp.c @@ -1022,8 +1022,7 @@ char *pgp_findKeys (address_t * to, address_t * cc, address_t * bcc) last = &((*last)->next); } - if (fqdn) - rfc822_qualify (tmp, fqdn); + rfc822_qualify (tmp, fqdn); address_list_uniq(tmp); @@ -1048,8 +1047,7 @@ char *pgp_findKeys (address_t * to, address_t * cc, address_t * bcc) /* check for e-mail address */ if ((t = strchr (keyID, '@')) && (addr = rfc822_parse_adrlist (NULL, keyID))) { - if (fqdn) - rfc822_qualify (addr, fqdn); + rfc822_qualify (addr, fqdn); q = addr; } else diff --git a/lib-crypt/smime.c b/lib-crypt/smime.c index 1248f31..4a4f89c 100644 --- a/lib-crypt/smime.c +++ b/lib-crypt/smime.c @@ -708,8 +708,6 @@ char *smime_findKeys (address_t * to, address_t * cc, address_t * bcc) address_t *p, *q; int i; - const char *fqdn = mutt_fqdn (1); - for (i = 0; i < 3; i++) { switch (i) { case 0: @@ -730,8 +728,7 @@ char *smime_findKeys (address_t * to, address_t * cc, address_t * bcc) last = &((*last)->next); } - if (fqdn) - rfc822_qualify (tmp, fqdn); + rfc822_qualify(tmp, mutt_fqdn(1)); address_list_uniq(tmp); diff --git a/lib-mime/rfc822address.c b/lib-mime/rfc822address.c index ad4e117..36485d3 100644 --- a/lib-mime/rfc822address.c +++ b/lib-mime/rfc822address.c @@ -32,11 +32,12 @@ void rfc822_qualify(address_t *addr, const char *host) { - char *p; + if (!host) + return; for (; addr; addr = addr->next) { if (!addr->group && addr->mailbox && !strchr(addr->mailbox, '@')) { - p = p_new(char, m_strlen(addr->mailbox) + m_strlen(host) + 2); + char *p = p_new(char, m_strlen(addr->mailbox) + m_strlen(host) + 2); sprintf(p, "%s@%s", addr->mailbox, host); p_delete(&addr->mailbox); addr->mailbox = p; diff --git a/remailer.c b/remailer.c index 226953d..b17ec82 100644 --- a/remailer.c +++ b/remailer.c @@ -672,17 +672,16 @@ int mix_check_message (HEADER * msg) if (need_hostname) { - if (!(fqdn = mutt_fqdn (1))) { + if (!(fqdn = mutt_fqdn(1))) { mutt_error - _ - ("Please set the hostname variable to a proper value when using mixmaster!"); - return (-1); + _("Please set the hostname variable to a proper value when using mixmaster!"); + return -1; } /* Cc and Bcc are empty at this point. */ - rfc822_qualify (msg->env->to, fqdn); - rfc822_qualify (msg->env->reply_to, fqdn); - rfc822_qualify (msg->env->mail_followup_to, fqdn); + rfc822_qualify(msg->env->to, fqdn); + rfc822_qualify(msg->env->reply_to, fqdn); + rfc822_qualify(msg->env->mail_followup_to, fqdn); } return 0; diff --git a/send.c b/send.c index 1773589..f5ffa26 100644 --- a/send.c +++ b/send.c @@ -849,62 +849,59 @@ static int generate_body (FILE * tempfp, /* stream for outgoing message * void mutt_set_followup_to (ENVELOPE * e) { - address_t *from; - - /* - * Only generate the Mail-Followup-To if the user has requested it, and - * it hasn't already been set - */ + /* + * Only generate the Mail-Followup-To if the user has requested it, and + * it hasn't already been set + */ + if (!option(OPTFOLLOWUPTO)) + return; - if (!option (OPTFOLLOWUPTO)) - return; #ifdef USE_NNTP - if (option (OPTNEWSSEND)) { - if (!e->followup_to && e->newsgroups && (strrchr (e->newsgroups, ','))) - e->followup_to = m_strdup(e->newsgroups); - return; - } + if (option(OPTNEWSSEND)) { + if (!e->followup_to && e->newsgroups && strrchr(e->newsgroups, ',')) + e->followup_to = m_strdup(e->newsgroups); + return; + } #endif - if (!e->mail_followup_to) { + if (e->mail_followup_to) + return; + if (mutt_is_list_cc (0, e->to, e->cc)) { - address_t **tmp; - /* - * this message goes to known mailing lists, so create a proper - * mail-followup-to header - */ + address_t **tmp; - tmp = address_list_append(&e->mail_followup_to, address_list_dup(e->to)); - address_list_append(tmp, address_list_dup(e->cc)); + /* + * this message goes to known mailing lists, so create a proper + * mail-followup-to header + */ + tmp = address_list_append(&e->mail_followup_to, address_list_dup(e->to)); + address_list_append(tmp, address_list_dup(e->cc)); } /* remove ourselves from the mail-followup-to header */ - e->mail_followup_to = remove_user (e->mail_followup_to, 0); + e->mail_followup_to = remove_user(e->mail_followup_to, 0); /* * If we are not subscribed to any of the lists in question, - * re-add ourselves to the mail-followup-to header. The + * re-add ourselves to the mail-followup-to header. The * mail-followup-to header generated is a no-op with group-reply, * but makes sure list-reply has the desired effect. */ + if (e->mail_followup_to && !mutt_is_list_recipient(0, e->to, e->cc)) { + address_t *from; - if (e->mail_followup_to && !mutt_is_list_recipient (0, e->to, e->cc)) { - if (e->reply_to) - from = address_list_dup (e->reply_to); - else if (e->from) - from = address_list_dup (e->from); - else - from = mutt_default_from (); + if (e->reply_to) + from = address_list_dup(e->reply_to); + else if (e->from) + from = address_list_dup(e->from); + else + from = mutt_default_from(); - if (from) { - address_list_append(&from->next, e->mail_followup_to); + address_list_append(&from, e->mail_followup_to); e->mail_followup_to = from; - } } address_list_uniq(e->mail_followup_to); - - } } @@ -913,50 +910,48 @@ void mutt_set_followup_to (ENVELOPE * e) from field */ static address_t *set_reverse_name (ENVELOPE * env) { - address_t *tmp; + address_t *tmp; - for (tmp = env->to; tmp; tmp = tmp->next) { - if (mutt_addr_is_user (tmp)) - break; - } - if (!tmp) { + for (tmp = env->to; tmp; tmp = tmp->next) { + if (mutt_addr_is_user(tmp)) + goto found; + } for (tmp = env->cc; tmp; tmp = tmp->next) { - if (mutt_addr_is_user (tmp)) - break; + if (mutt_addr_is_user(tmp)) + goto found; } - } - if (!tmp && mutt_addr_is_user (env->from)) - tmp = env->from; - if (tmp) { - tmp = address_dup (tmp); - if (!option (OPTREVREAL)) - p_delete(&tmp->personal); - if (!tmp->personal) - tmp->personal = m_strdup(Realname); - } - return (tmp); + + if (!mutt_addr_is_user(env->from)) + return NULL; + + found: + tmp = address_dup(tmp); + if (!option(OPTREVREAL) || !tmp->personal) { + p_delete(&tmp->personal); + tmp->personal = m_strdup(Realname); + } + return tmp; } address_t *mutt_default_from (void) { address_t *adr; - const char *fqdn = mutt_fqdn (1); - /* - * Note: We let $from override $realname here. Is this the right - * thing to do? + /* + * Note: We let $from override $realname here. + * Is this the right thing to do? */ if (From) - adr = address_dup (From); + adr = address_dup(From); else if (option (OPTUSEDOMAIN)) { - adr = address_new (); + const char *fqdn = mutt_fqdn (1); + adr = address_new(); adr->mailbox = p_new(char, m_strlen(Username) + m_strlen(fqdn) + 2); - sprintf (adr->mailbox, "%s@%s", NONULL (Username), NONULL (fqdn)); - } - else { + sprintf(adr->mailbox, "%s@%s", NONULL(Username), NONULL(fqdn)); + } else { adr = address_new (); - adr->mailbox = m_strdup(NONULL (Username)); + adr->mailbox = m_strdup(NONULL(Username)); } return (adr); diff --git a/sendlib.c b/sendlib.c index 0f676b9..6cd48b5 100644 --- a/sendlib.c +++ b/sendlib.c @@ -2078,7 +2078,6 @@ static int _mutt_bounce_message (FILE * fp, HEADER * h, address_t * to, int mutt_bounce_message (FILE * fp, HEADER * h, address_t * to) { address_t *from; - const char *fqdn = mutt_fqdn (1); char resent_from[STRING]; int ret; char *err; @@ -2086,8 +2085,7 @@ int mutt_bounce_message (FILE * fp, HEADER * h, address_t * to) resent_from[0] = '\0'; from = mutt_default_from (); - if (fqdn) - rfc822_qualify (from, fqdn); + rfc822_qualify(from, mutt_fqdn(1)); rfc2047_encode_adrlist (from, "Resent-From"); if (mutt_addrlist_to_idna (from, &err)) { -- 2.20.1