summaryrefslogtreecommitdiff
path: root/mailutils
diff options
context:
space:
mode:
authorDenys Vlasenko2013-03-18 18:47:16 +0100
committerDenys Vlasenko2013-03-18 18:47:16 +0100
commita42f530e034b673726a91ea5d8202254e677f066 (patch)
treee15c9fa542146b4d56411e04b3af91f9afe21d92 /mailutils
parente82bfef8395bc0aff7c770bfadcd9e58a48ffc04 (diff)
downloadbusybox-a42f530e034b673726a91ea5d8202254e677f066.zip
busybox-a42f530e034b673726a91ea5d8202254e677f066.tar.gz
sendmail: code shrink on top of previous patches
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'mailutils')
-rw-r--r--mailutils/sendmail.c72
1 files changed, 30 insertions, 42 deletions
diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c
index d58f503..b5aa1d1 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)) {