From: Denys Vlasenko Date: Mon, 18 Mar 2013 17:47:16 +0000 (+0100) Subject: sendmail: code shrink on top of previous patches X-Git-Tag: 1_22_0~218 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a42f530e034b673726a91ea5d8202254e677f066;p=oweals%2Fbusybox.git sendmail: code shrink on top of previous patches Signed-off-by: Denys Vlasenko --- diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c index d58f503a0..b5aa1d17b 100644 --- a/mailutils/sendmail.c +++ b/mailutils/sendmail.c @@ -92,47 +92,37 @@ static int smtp_check(const char *fmt, int code) // strip argument of bad chars static char *sane_address(char *str) { - char *s = str; - char *p = s; - int leading_space = 1; - int trailing_space = 0; + char *s; + trim(str); + s = str; while (*s) { - if (isspace(*s)) { - trailing_space = !leading_space; - } else { - *p++ = *s; - if ((!isalnum(*s) && !strchr("_-.@", *s)) || - trailing_space) { - *p = '\0'; - bb_error_msg("Bad address: %s", str); - *str = '\0'; - return str; - } - leading_space = 0; + if (!isalnum(*s) && !strchr("_-.@", *s)) { + bb_error_msg("bad address '%s'", str); + /* returning "": */ + str[0] = '\0'; + return str; } s++; } - *p = '\0'; return str; } // check for an address inside angle brackets, if not found fall back to normal static char *angle_address(char *str) { - char *s = str; - char *e = str + strlen(str); - - while (e != str && (isspace(*e) || *e == '\0')) - e--; - if (*e != '>') - goto done; - *e = '\0'; - e = strrchr(s, '<'); - if (e != NULL) - s = e + 1; -done: - return sane_address(s); + char *s, *e; + + trim(str); + e = last_char_is(str, '>'); + if (e) { + s = strrchr(str, '<'); + if (s) { + *e = '\0'; + str = s + 1; + } + } + return sane_address(str); } static void rcptto(const char *s) @@ -145,29 +135,27 @@ static void rcptto(const char *s) } // send to a list of comma separated addresses -static void rcptto_list(const char *_str) +static void rcptto_list(const char *list) { - char *str = xstrdup(_str); - int len = strlen(str); - int in_quote = 0; + char *str = xstrdup(list); char *s = str; char prev = 0; - int pos; + int in_quote = 0; - for (pos = 0; pos < len; pos++) { - char ch = str[pos]; + while (*s) { + char ch = *s++; if (ch == '"' && prev != '\\') { in_quote = !in_quote; } else if (!in_quote && ch == ',') { - str[pos] = '\0'; - rcptto(angle_address(s)); - s = str + pos + 1; + s[-1] = '\0'; + rcptto(angle_address(str)); + str = s; } prev = ch; } if (prev != ',') - rcptto(angle_address(s)); + rcptto(angle_address(str)); free(str); } @@ -349,7 +337,7 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) // analyze headers // To: or Cc: headers add recipients - check_hdr = 0 == strncasecmp("To:", s, 3); + check_hdr = (0 == strncasecmp("To:", s, 3)); has_to |= check_hdr; if (opts & OPT_t) { if (check_hdr || 0 == strncasecmp("Bcc:" + 1, s, 3)) {