diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-09-07 13:16:33 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-09-07 13:16:33 +0200 |
commit | b9f56e82da9a0821011e1e0924acd1d781643070 (patch) | |
tree | e6a5edcae1b4fb9365431690c80a892870f6735d | |
parent | d42cdc2222d08fcc5ad8251ecf7a00454cb0c419 (diff) | |
download | busybox-w32-b9f56e82da9a0821011e1e0924acd1d781643070.tar.gz busybox-w32-b9f56e82da9a0821011e1e0924acd1d781643070.tar.bz2 busybox-w32-b9f56e82da9a0821011e1e0924acd1d781643070.zip |
sendmail: make it possible to pause after connection helper is started
If a non-starttls helper is in use, initial 220 response is processed by us,
not by helper.
Some servers consider us to be a spammer if we don't wait for it.
It is not in protocol, but it is a real-life problem.
The workaround in this patch is a magic envvar, $SMTP_ANTISPAM_DELAY:
...
-H 'PROG ARGS' Run connection helper. Examples:
openssl s_client -quiet -tls1 -starttls smtp -connect smtp.gmail.com:25
openssl s_client -quiet -tls1 -connect smtp.gmail.com:465
$SMTP_ANTISPAM_DELAY: seconds to wait after helper connect
...
By using it, people can tweak sendmail behavior even if sendmail invocation
is buried in some scripts.
function old new delta
packed_usage 30464 30497 +33
sendmail_main 1185 1206 +21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 54/0) Total: 54 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | mailutils/sendmail.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c index cd27d676e..1242795b8 100644 --- a/mailutils/sendmail.c +++ b/mailutils/sendmail.c | |||
@@ -27,6 +27,7 @@ | |||
27 | //usage: "\n -H 'PROG ARGS' Run connection helper. Examples:" | 27 | //usage: "\n -H 'PROG ARGS' Run connection helper. Examples:" |
28 | //usage: "\n openssl s_client -quiet -tls1 -starttls smtp -connect smtp.gmail.com:25" | 28 | //usage: "\n openssl s_client -quiet -tls1 -starttls smtp -connect smtp.gmail.com:25" |
29 | //usage: "\n openssl s_client -quiet -tls1 -connect smtp.gmail.com:465" | 29 | //usage: "\n openssl s_client -quiet -tls1 -connect smtp.gmail.com:465" |
30 | //usage: "\n $SMTP_ANTISPAM_DELAY: seconds to wait after helper connect" | ||
30 | //usage: "\n -S HOST[:PORT] Server (default $SMTPHOST or 127.0.0.1)" | 31 | //usage: "\n -S HOST[:PORT] Server (default $SMTPHOST or 127.0.0.1)" |
31 | //usage: "\n -amLOGIN Log in using AUTH LOGIN (-amCRAM-MD5 not supported)" | 32 | //usage: "\n -amLOGIN Log in using AUTH LOGIN (-amCRAM-MD5 not supported)" |
32 | //usage: "\n -auUSER Username for AUTH" | 33 | //usage: "\n -auUSER Username for AUTH" |
@@ -207,7 +208,7 @@ static void rcptto_list(const char *list) | |||
207 | int sendmail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 208 | int sendmail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
208 | int sendmail_main(int argc UNUSED_PARAM, char **argv) | 209 | int sendmail_main(int argc UNUSED_PARAM, char **argv) |
209 | { | 210 | { |
210 | char *opt_connect = opt_connect; | 211 | char *opt_connect; |
211 | char *opt_from = NULL; | 212 | char *opt_from = NULL; |
212 | char *s; | 213 | char *s; |
213 | llist_t *list = NULL; | 214 | llist_t *list = NULL; |
@@ -239,6 +240,11 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) | |||
239 | // init global variables | 240 | // init global variables |
240 | INIT_G(); | 241 | INIT_G(); |
241 | 242 | ||
243 | // default HOST[:PORT] is $SMTPHOST, or localhost | ||
244 | opt_connect = getenv("SMTPHOST"); | ||
245 | if (!opt_connect) | ||
246 | opt_connect = (char *)"127.0.0.1"; | ||
247 | |||
242 | // save initial stdin since body is piped! | 248 | // save initial stdin since body is piped! |
243 | xdup2(STDIN_FILENO, 3); | 249 | xdup2(STDIN_FILENO, 3); |
244 | G.fp0 = xfdopen_for_read(3); | 250 | G.fp0 = xfdopen_for_read(3); |
@@ -274,6 +280,7 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) | |||
274 | 280 | ||
275 | // connection helper ordered? -> | 281 | // connection helper ordered? -> |
276 | if (opts & OPT_H) { | 282 | if (opts & OPT_H) { |
283 | const char *delay; | ||
277 | const char *args[] = { "sh", "-c", opt_connect, NULL }; | 284 | const char *args[] = { "sh", "-c", opt_connect, NULL }; |
278 | // plug it in | 285 | // plug it in |
279 | launch_helper(args); | 286 | launch_helper(args); |
@@ -292,7 +299,12 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) | |||
292 | // before 220 reached it. The code below is unsafe in this regard: | 299 | // before 220 reached it. The code below is unsafe in this regard: |
293 | // in non-STARTTLSed case, we potentially send NOOP before 220 | 300 | // in non-STARTTLSed case, we potentially send NOOP before 220 |
294 | // is sent by server. | 301 | // is sent by server. |
295 | // Ideas? (--delay SECS opt? --assume-starttls-helper opt?) | 302 | // |
303 | // If $SMTP_ANTISPAM_DELAY is set, we pause before sending NOOP. | ||
304 | // | ||
305 | delay = getenv("SMTP_ANTISPAM_DELAY"); | ||
306 | if (delay) | ||
307 | sleep(atoi(delay)); | ||
296 | code = smtp_check("NOOP", -1); | 308 | code = smtp_check("NOOP", -1); |
297 | if (code == 220) | 309 | if (code == 220) |
298 | // we got 220 - this is not STARTTLSed connection, | 310 | // we got 220 - this is not STARTTLSed connection, |
@@ -304,14 +316,6 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) | |||
304 | } else { | 316 | } else { |
305 | // vanilla connection | 317 | // vanilla connection |
306 | int fd; | 318 | int fd; |
307 | // host[:port] not explicitly specified? -> use $SMTPHOST | ||
308 | // no $SMTPHOST? -> use localhost | ||
309 | if (!(opts & OPT_S)) { | ||
310 | opt_connect = getenv("SMTPHOST"); | ||
311 | if (!opt_connect) | ||
312 | opt_connect = (char *)"127.0.0.1"; | ||
313 | } | ||
314 | // do connect | ||
315 | fd = create_and_connect_stream_or_die(opt_connect, 25); | 319 | fd = create_and_connect_stream_or_die(opt_connect, 25); |
316 | // and make ourselves a simple IO filter | 320 | // and make ourselves a simple IO filter |
317 | xmove_fd(fd, STDIN_FILENO); | 321 | xmove_fd(fd, STDIN_FILENO); |