From: Pierre Habouzit Date: Sun, 12 Nov 2006 23:37:22 +0000 (+0100) Subject: make some functions a bit shorter. X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=2480626d883af3c291e94b90e1edc1ca40fca1c4 make some functions a bit shorter. Signed-off-by: Pierre Habouzit --- diff --git a/alias.c b/alias.c index add8028..7282a8c 100644 --- a/alias.c +++ b/alias.c @@ -61,6 +61,57 @@ address_t *alias_lookup(alias_t *list, const char *s) return NULL; } +static int string_is_address(const char *str, const char *u, const char *d) +{ + char buf[LONG_STRING]; + snprintf(buf, sizeof (buf), "%s@%s", NONULL(u), NONULL(d)); + return !ascii_strcasecmp(str, buf); +} + +/* returns TRUE if the given address belongs to the user. */ +int mutt_addr_is_user(address_t *addr) +{ + /* NULL address is assumed to be the user. */ + if (!addr) + return 1; + + if (!addr->mailbox) + return 0; + + if (!ascii_strcasecmp(addr->mailbox, Username) + || string_is_address(addr->mailbox, Username, Hostname) + || string_is_address(addr->mailbox, Username, mutt_fqdn(0)) + || string_is_address(addr->mailbox, Username, mutt_fqdn(1)) + || (From && !ascii_strcasecmp(From->mailbox, addr->mailbox))) + { + return 1; + } + + return rx_list_match(Alternates, addr->mailbox) + && !rx_list_match(UnAlternates, addr->mailbox); +} + +address_t *mutt_get_address(ENVELOPE *env, const char **pfxp) +{ +#define RETURN(s, adr) do { if (pfxp) *pfxp = s; return adr; } while (0) + + if (mutt_addr_is_user(env->from)) { + if (env->to && !mutt_is_mail_list(env->to)) { + RETURN("To", env->to); + } else { + RETURN("Cc", env->cc); + } + } else { + if (env->reply_to && !mutt_is_mail_list(env->reply_to)) { + RETURN("Reply-To", env->reply_to); + } else { + RETURN("From", env->from); + } + } + +#undef RETURN +} + /* Only characters which are non-special to both the RFC 822 and the mutt configuration parser are permitted. */ static int alias_sanitize(const char *s, char *d) @@ -228,7 +279,6 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr) /************* READ MARK *********************/ - static address_t *mutt_expand_aliases_r (address_t * a, LIST ** expn) { address_t *head = NULL, *last = NULL, *t, *w; @@ -322,36 +372,6 @@ void mutt_expand_aliases_env (ENVELOPE * env) } -address_t *mutt_get_address (ENVELOPE * env, const char **pfxp) -{ - address_t *adr; - const char *pfx = NULL; - - if (mutt_addr_is_user (env->from)) { - if (env->to && !mutt_is_mail_list (env->to)) { - pfx = "To"; - adr = env->to; - } - else { - pfx = "Cc"; - adr = env->cc; - } - } - else if (env->reply_to && !mutt_is_mail_list (env->reply_to)) { - pfx = "Reply-To"; - adr = env->reply_to; - } - else { - adr = env->from; - pfx = "From"; - } - - if (pfxp) - *pfxp = pfx; - - return adr; -} - /* * This routine looks to see if the user has an alias defined for the given * address. @@ -470,64 +490,6 @@ int mutt_alias_complete (char *s, size_t buflen) return 0; } -static int string_is_address (const char *str, const char *u, const char *d) -{ - char buf[LONG_STRING]; - - snprintf (buf, sizeof (buf), "%s@%s", NONULL (u), NONULL (d)); - if (ascii_strcasecmp (str, buf) == 0) - return 1; - - return 0; -} - -/* returns TRUE if the given address belongs to the user. */ -int mutt_addr_is_user (address_t * addr) -{ - /* NULL address is assumed to be the user. */ - if (!addr) { - debug_print(5, ("yes, NULL address\n")); - return 1; - } - if (!addr->mailbox) { - debug_print(5, ("no, no mailbox\n")); - return 0; - } - - if (ascii_strcasecmp (addr->mailbox, Username) == 0) { - debug_print(5, ("yes, %s = %s\n", addr->mailbox, Username)); - return 1; - } - if (string_is_address (addr->mailbox, Username, Hostname)) { - debug_print(5, ("yes, %s = %s @ %s \n", addr->mailbox, Username, Hostname)); - return 1; - } - if (string_is_address (addr->mailbox, Username, mutt_fqdn (0))) { - debug_print(5, ("yes, %s = %s @ %s \n", addr->mailbox, Username, mutt_fqdn (0))); - return 1; - } - if (string_is_address (addr->mailbox, Username, mutt_fqdn (1))) { - debug_print(5, ("yes, %s = %s @ %s \n", addr->mailbox, Username, mutt_fqdn (1))); - return 1; - } - - if (From && !ascii_strcasecmp (From->mailbox, addr->mailbox)) { - debug_print(5, ("yes, %s = %s\n", addr->mailbox, From->mailbox)); - return 1; - } - - if (rx_list_match (Alternates, addr->mailbox)) { - debug_print(5, ("yes, %s matched by alternates.\n", addr->mailbox)); - if (rx_list_match (UnAlternates, addr->mailbox)) - debug_print(5, ("but, %s matched by unalternates.\n", addr->mailbox)); - else - return 1; - } - - debug_print(5, ("no, all failed.\n")); - return 0; -} - static const format_t *alias_format_str (char *dest, size_t destlen, char op, const format_t *src, const char *fmt, const char *ifstring __attribute__ ((unused)), diff --git a/alias.h b/alias.h index cc0ee57..ec6afec 100644 --- a/alias.h +++ b/alias.h @@ -29,14 +29,14 @@ DO_DELETE(alias_t, alias); DO_SLIST(alias_t, alias); address_t *alias_lookup(alias_t *list, const char *s); +int mutt_addr_is_user(address_t *); +address_t *mutt_get_address(ENVELOPE *, const char **); +void mutt_create_alias(ENVELOPE *, address_t *); -void mutt_create_alias (ENVELOPE *, address_t *); -address_t *mutt_get_address (ENVELOPE *, const char **); address_t *mutt_expand_aliases (address_t *); void mutt_expand_aliases_env (ENVELOPE *); address_t *alias_reverse_lookup (address_t *); int mutt_alias_complete (char *, size_t); -int mutt_addr_is_user (address_t *); void mutt_alias_menu (char *, size_t, alias_t *); #endif /* !_MUTT_ALIAS_H */