diff options
Diffstat (limited to 'mailutils/sendmail.c')
-rw-r--r-- | mailutils/sendmail.c | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c index fb4dbb3da..1242795b8 100644 --- a/mailutils/sendmail.c +++ b/mailutils/sendmail.c | |||
@@ -10,7 +10,8 @@ | |||
10 | //kbuild:lib-$(CONFIG_SENDMAIL) += sendmail.o mail.o | 10 | //kbuild:lib-$(CONFIG_SENDMAIL) += sendmail.o mail.o |
11 | 11 | ||
12 | //usage:#define sendmail_trivial_usage | 12 | //usage:#define sendmail_trivial_usage |
13 | //usage: "[OPTIONS] [RECIPIENT_EMAIL]..." | 13 | //usage: "[-tv] [-f SENDER] [-amLOGIN 4<user_pass.txt | -auUSER -apPASS]" |
14 | //usage: "\n [-w SECS] [-H 'PROG ARGS' | -S HOST] [RECIPIENT_EMAIL]..." | ||
14 | //usage:#define sendmail_full_usage "\n\n" | 15 | //usage:#define sendmail_full_usage "\n\n" |
15 | //usage: "Read email from stdin and send it\n" | 16 | //usage: "Read email from stdin and send it\n" |
16 | //usage: "\nStandard options:" | 17 | //usage: "\nStandard options:" |
@@ -18,27 +19,25 @@ | |||
18 | //usage: "\n -f SENDER For use in MAIL FROM:<sender>. Can be empty string" | 19 | //usage: "\n -f SENDER For use in MAIL FROM:<sender>. Can be empty string" |
19 | //usage: "\n Default: -auUSER, or username of current UID" | 20 | //usage: "\n Default: -auUSER, or username of current UID" |
20 | //usage: "\n -o OPTIONS Various options. -oi implied, others are ignored" | 21 | //usage: "\n -o OPTIONS Various options. -oi implied, others are ignored" |
21 | //usage: "\n -i -oi synonym. implied and ignored" | 22 | //usage: "\n -i -oi synonym, implied and ignored" |
22 | //usage: "\n" | 23 | //usage: "\n" |
23 | //usage: "\nBusybox specific options:" | 24 | //usage: "\nBusybox specific options:" |
24 | //usage: "\n -v Verbose" | 25 | //usage: "\n -v Verbose" |
25 | //usage: "\n -w SECS Network timeout" | 26 | //usage: "\n -w SECS Network timeout" |
26 | //usage: "\n -H 'PROG ARGS' Run connection helper" | 27 | //usage: "\n -H 'PROG ARGS' Run connection helper. Examples:" |
27 | //usage: "\n Examples:" | 28 | //usage: "\n openssl s_client -quiet -tls1 -starttls smtp -connect smtp.gmail.com:25" |
28 | //usage: "\n -H 'exec openssl s_client -quiet -tls1 -starttls smtp" | 29 | //usage: "\n openssl s_client -quiet -tls1 -connect smtp.gmail.com:465" |
29 | //usage: "\n -connect smtp.gmail.com:25' <email.txt" | 30 | //usage: "\n $SMTP_ANTISPAM_DELAY: seconds to wait after helper connect" |
30 | //usage: "\n [4<username_and_passwd.txt | -auUSER -apPASS]" | 31 | //usage: "\n -S HOST[:PORT] Server (default $SMTPHOST or 127.0.0.1)" |
31 | //usage: "\n -H 'exec openssl s_client -quiet -tls1" | 32 | //usage: "\n -amLOGIN Log in using AUTH LOGIN (-amCRAM-MD5 not supported)" |
32 | //usage: "\n -connect smtp.gmail.com:465' <email.txt" | 33 | //usage: "\n -auUSER Username for AUTH" |
33 | //usage: "\n [4<username_and_passwd.txt | -auUSER -apPASS]" | 34 | //usage: "\n -apPASS Password for AUTH" |
34 | //usage: "\n -S HOST[:PORT] Server" | ||
35 | //usage: "\n -auUSER Username for AUTH LOGIN" | ||
36 | //usage: "\n -apPASS Password for AUTH LOGIN" | ||
37 | ////usage: "\n -amMETHOD Authentication method. Ignored. LOGIN is implied" | ||
38 | //usage: "\n" | 35 | //usage: "\n" |
39 | //usage: "\nOther options are silently ignored; -oi -t is implied" | 36 | //usage: "\nIf no -a options are given, authentication is not done." |
37 | //usage: "\nIf -amLOGIN is given but no -au/-ap, user/password is read from fd #4." | ||
38 | //usage: "\nOther options are silently ignored; -oi is implied." | ||
40 | //usage: IF_MAKEMIME( | 39 | //usage: IF_MAKEMIME( |
41 | //usage: "\nUse makemime to create emails with attachments" | 40 | //usage: "\nUse makemime to create emails with attachments." |
42 | //usage: ) | 41 | //usage: ) |
43 | 42 | ||
44 | /* Currently we don't sanitize or escape user-supplied SENDER and RECIPIENT_EMAILs. | 43 | /* Currently we don't sanitize or escape user-supplied SENDER and RECIPIENT_EMAILs. |
@@ -209,7 +208,7 @@ static void rcptto_list(const char *list) | |||
209 | int sendmail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 208 | int sendmail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
210 | int sendmail_main(int argc UNUSED_PARAM, char **argv) | 209 | int sendmail_main(int argc UNUSED_PARAM, char **argv) |
211 | { | 210 | { |
212 | char *opt_connect = opt_connect; | 211 | char *opt_connect; |
213 | char *opt_from = NULL; | 212 | char *opt_from = NULL; |
214 | char *s; | 213 | char *s; |
215 | llist_t *list = NULL; | 214 | llist_t *list = NULL; |
@@ -241,6 +240,11 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) | |||
241 | // init global variables | 240 | // init global variables |
242 | INIT_G(); | 241 | INIT_G(); |
243 | 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 | |||
244 | // save initial stdin since body is piped! | 248 | // save initial stdin since body is piped! |
245 | xdup2(STDIN_FILENO, 3); | 249 | xdup2(STDIN_FILENO, 3); |
246 | G.fp0 = xfdopen_for_read(3); | 250 | G.fp0 = xfdopen_for_read(3); |
@@ -276,6 +280,7 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) | |||
276 | 280 | ||
277 | // connection helper ordered? -> | 281 | // connection helper ordered? -> |
278 | if (opts & OPT_H) { | 282 | if (opts & OPT_H) { |
283 | const char *delay; | ||
279 | const char *args[] = { "sh", "-c", opt_connect, NULL }; | 284 | const char *args[] = { "sh", "-c", opt_connect, NULL }; |
280 | // plug it in | 285 | // plug it in |
281 | launch_helper(args); | 286 | launch_helper(args); |
@@ -294,7 +299,12 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) | |||
294 | // 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: |
295 | // in non-STARTTLSed case, we potentially send NOOP before 220 | 300 | // in non-STARTTLSed case, we potentially send NOOP before 220 |
296 | // is sent by server. | 301 | // is sent by server. |
297 | // 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)); | ||
298 | code = smtp_check("NOOP", -1); | 308 | code = smtp_check("NOOP", -1); |
299 | if (code == 220) | 309 | if (code == 220) |
300 | // we got 220 - this is not STARTTLSed connection, | 310 | // we got 220 - this is not STARTTLSed connection, |
@@ -306,14 +316,6 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) | |||
306 | } else { | 316 | } else { |
307 | // vanilla connection | 317 | // vanilla connection |
308 | int fd; | 318 | int fd; |
309 | // host[:port] not explicitly specified? -> use $SMTPHOST | ||
310 | // no $SMTPHOST? -> use localhost | ||
311 | if (!(opts & OPT_S)) { | ||
312 | opt_connect = getenv("SMTPHOST"); | ||
313 | if (!opt_connect) | ||
314 | opt_connect = (char *)"127.0.0.1"; | ||
315 | } | ||
316 | // do connect | ||
317 | fd = create_and_connect_stream_or_die(opt_connect, 25); | 319 | fd = create_and_connect_stream_or_die(opt_connect, 25); |
318 | // and make ourselves a simple IO filter | 320 | // and make ourselves a simple IO filter |
319 | xmove_fd(fd, STDIN_FILENO); | 321 | xmove_fd(fd, STDIN_FILENO); |