aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaro Koskinen <aaro.koskinen@iki.fi>2013-02-25 00:45:09 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2013-03-18 18:45:14 +0100
commita8ba0a0d0ce4fa5f5afd0a8246e2378c2664c424 (patch)
tree60931edb0341043fa2ea624700fe32a7b89408dd
parent06ad964ae61591ef74313d7c1746367430d0d82b (diff)
downloadbusybox-w32-a8ba0a0d0ce4fa5f5afd0a8246e2378c2664c424.tar.gz
busybox-w32-a8ba0a0d0ce4fa5f5afd0a8246e2378c2664c424.tar.bz2
busybox-w32-a8ba0a0d0ce4fa5f5afd0a8246e2378c2664c424.zip
sendmail: support address lists
Headers To:, Cc: and Bcc: may have a list of comma-separated addresses. Add support for that. Commas inside double quotes are ignored. Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--mailutils/sendmail.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c
index 10a5a85d4..c5df5f5d3 100644
--- a/mailutils/sendmail.c
+++ b/mailutils/sendmail.c
@@ -144,6 +144,33 @@ static void rcptto(const char *s)
144 bb_error_msg("Bad recipient: <%s>", s); 144 bb_error_msg("Bad recipient: <%s>", s);
145} 145}
146 146
147// send to a list of comma separated addresses
148static void rcptto_list(const char *_str)
149{
150 char *str = xstrdup(_str);
151 int len = strlen(str);
152 int in_quote = 0;
153 char *s = str;
154 char prev = 0;
155 int pos;
156
157 for (pos = 0; pos < len; pos++) {
158 char ch = str[pos];
159
160 if (ch == '"' && prev != '\\') {
161 in_quote = !in_quote;
162 } else if (!in_quote && ch == ',') {
163 str[pos] = '\0';
164 rcptto(angle_address(s));
165 s = str + pos + 1;
166 }
167 prev = ch;
168 }
169 if (prev != ',')
170 rcptto(angle_address(s));
171 free(str);
172}
173
147int sendmail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 174int sendmail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
148int sendmail_main(int argc UNUSED_PARAM, char **argv) 175int sendmail_main(int argc UNUSED_PARAM, char **argv)
149{ 176{
@@ -317,14 +344,12 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
317 // To: or Cc: headers add recipients 344 // To: or Cc: headers add recipients
318 if (opts & OPT_t) { 345 if (opts & OPT_t) {
319 if (0 == strncasecmp("To:", s, 3) || 0 == strncasecmp("Bcc:" + 1, s, 3)) { 346 if (0 == strncasecmp("To:", s, 3) || 0 == strncasecmp("Bcc:" + 1, s, 3)) {
320 char *r = xstrdup(s+3); 347 rcptto_list(s+3);
321 rcptto(angle_address(r));
322 free(r);
323 goto addheader; 348 goto addheader;
324 } 349 }
325 // Bcc: header adds blind copy (hidden) recipient 350 // Bcc: header adds blind copy (hidden) recipient
326 if (0 == strncasecmp("Bcc:", s, 4)) { 351 if (0 == strncasecmp("Bcc:", s, 4)) {
327 rcptto(angle_address(s+4)); 352 rcptto_list(s+4);
328 free(s); 353 free(s);
329 continue; // N.B. Bcc: vanishes from headers! 354 continue; // N.B. Bcc: vanishes from headers!
330 } 355 }