aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-03-18 18:47:16 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2013-03-18 18:47:16 +0100
commita42f530e034b673726a91ea5d8202254e677f066 (patch)
treee15c9fa542146b4d56411e04b3af91f9afe21d92
parente82bfef8395bc0aff7c770bfadcd9e58a48ffc04 (diff)
downloadbusybox-w32-a42f530e034b673726a91ea5d8202254e677f066.tar.gz
busybox-w32-a42f530e034b673726a91ea5d8202254e677f066.tar.bz2
busybox-w32-a42f530e034b673726a91ea5d8202254e677f066.zip
sendmail: code shrink on top of previous patches
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--mailutils/sendmail.c72
1 files changed, 30 insertions, 42 deletions
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)
92// strip argument of bad chars 92// strip argument of bad chars
93static char *sane_address(char *str) 93static char *sane_address(char *str)
94{ 94{
95 char *s = str; 95 char *s;
96 char *p = s;
97 int leading_space = 1;
98 int trailing_space = 0;
99 96
97 trim(str);
98 s = str;
100 while (*s) { 99 while (*s) {
101 if (isspace(*s)) { 100 if (!isalnum(*s) && !strchr("_-.@", *s)) {
102 trailing_space = !leading_space; 101 bb_error_msg("bad address '%s'", str);
103 } else { 102 /* returning "": */
104 *p++ = *s; 103 str[0] = '\0';
105 if ((!isalnum(*s) && !strchr("_-.@", *s)) || 104 return str;
106 trailing_space) {
107 *p = '\0';
108 bb_error_msg("Bad address: %s", str);
109 *str = '\0';
110 return str;
111 }
112 leading_space = 0;
113 } 105 }
114 s++; 106 s++;
115 } 107 }
116 *p = '\0';
117 return str; 108 return str;
118} 109}
119 110
120// check for an address inside angle brackets, if not found fall back to normal 111// check for an address inside angle brackets, if not found fall back to normal
121static char *angle_address(char *str) 112static char *angle_address(char *str)
122{ 113{
123 char *s = str; 114 char *s, *e;
124 char *e = str + strlen(str); 115
125 116 trim(str);
126 while (e != str && (isspace(*e) || *e == '\0')) 117 e = last_char_is(str, '>');
127 e--; 118 if (e) {
128 if (*e != '>') 119 s = strrchr(str, '<');
129 goto done; 120 if (s) {
130 *e = '\0'; 121 *e = '\0';
131 e = strrchr(s, '<'); 122 str = s + 1;
132 if (e != NULL) 123 }
133 s = e + 1; 124 }
134done: 125 return sane_address(str);
135 return sane_address(s);
136} 126}
137 127
138static void rcptto(const char *s) 128static void rcptto(const char *s)
@@ -145,29 +135,27 @@ static void rcptto(const char *s)
145} 135}
146 136
147// send to a list of comma separated addresses 137// send to a list of comma separated addresses
148static void rcptto_list(const char *_str) 138static void rcptto_list(const char *list)
149{ 139{
150 char *str = xstrdup(_str); 140 char *str = xstrdup(list);
151 int len = strlen(str);
152 int in_quote = 0;
153 char *s = str; 141 char *s = str;
154 char prev = 0; 142 char prev = 0;
155 int pos; 143 int in_quote = 0;
156 144
157 for (pos = 0; pos < len; pos++) { 145 while (*s) {
158 char ch = str[pos]; 146 char ch = *s++;
159 147
160 if (ch == '"' && prev != '\\') { 148 if (ch == '"' && prev != '\\') {
161 in_quote = !in_quote; 149 in_quote = !in_quote;
162 } else if (!in_quote && ch == ',') { 150 } else if (!in_quote && ch == ',') {
163 str[pos] = '\0'; 151 s[-1] = '\0';
164 rcptto(angle_address(s)); 152 rcptto(angle_address(str));
165 s = str + pos + 1; 153 str = s;
166 } 154 }
167 prev = ch; 155 prev = ch;
168 } 156 }
169 if (prev != ',') 157 if (prev != ',')
170 rcptto(angle_address(s)); 158 rcptto(angle_address(str));
171 free(str); 159 free(str);
172} 160}
173 161
@@ -349,7 +337,7 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
349 337
350 // analyze headers 338 // analyze headers
351 // To: or Cc: headers add recipients 339 // To: or Cc: headers add recipients
352 check_hdr = 0 == strncasecmp("To:", s, 3); 340 check_hdr = (0 == strncasecmp("To:", s, 3));
353 has_to |= check_hdr; 341 has_to |= check_hdr;
354 if (opts & OPT_t) { 342 if (opts & OPT_t) {
355 if (check_hdr || 0 == strncasecmp("Bcc:" + 1, s, 3)) { 343 if (check_hdr || 0 == strncasecmp("Bcc:" + 1, s, 3)) {