aboutsummaryrefslogtreecommitdiff
path: root/mailutils/sendmail.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-12-20 05:12:39 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-12-20 05:12:39 +0100
commit5707b52fd4de0d9d5ebb496f459fa4fa66215226 (patch)
tree40ccc1ba8324ada382607c07e16203239043aa37 /mailutils/sendmail.c
parent27c6c00a7cf141aaa972c0f9691072db287a36ae (diff)
downloadbusybox-w32-5707b52fd4de0d9d5ebb496f459fa4fa66215226.tar.gz
busybox-w32-5707b52fd4de0d9d5ebb496f459fa4fa66215226.tar.bz2
busybox-w32-5707b52fd4de0d9d5ebb496f459fa4fa66215226.zip
mailutils/*: add verbose option to sendmail; remove -m and -j from makemime
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'mailutils/sendmail.c')
-rw-r--r--mailutils/sendmail.c64
1 files changed, 55 insertions, 9 deletions
diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c
index ec97cf8af..a2eda6937 100644
--- a/mailutils/sendmail.c
+++ b/mailutils/sendmail.c
@@ -6,6 +6,38 @@
6 * 6 *
7 * Licensed under GPLv2, see file LICENSE in this source tree. 7 * Licensed under GPLv2, see file LICENSE in this source tree.
8 */ 8 */
9
10//usage:#define sendmail_trivial_usage
11//usage: "[OPTIONS] [RECIPIENT_EMAIL]..."
12//usage:#define sendmail_full_usage "\n\n"
13//usage: "Read email from stdin and send it\n"
14//usage: "\nStandard options:"
15//usage: "\n -t Read additional recipients from message body"
16//usage: "\n -f SENDER Sender (required)"
17//usage: "\n -o OPTIONS Various options. -oi implied, others are ignored"
18//usage: "\n -i -oi synonym. implied and ignored"
19//usage: "\n"
20//usage: "\nBusybox specific options:"
21//usage: "\n -v Verbose"
22//usage: "\n -w SECS Network timeout"
23//usage: "\n -H 'PROG ARGS' Run connection helper"
24//usage: "\n Examples:"
25//usage: "\n -H 'exec openssl s_client -quiet -tls1 -starttls smtp"
26//usage: "\n -connect smtp.gmail.com:25' <email.txt"
27//usage: "\n [4<username_and_passwd.txt | -au<username> -ap<password>]"
28//usage: "\n -H 'exec openssl s_client -quiet -tls1"
29//usage: "\n -connect smtp.gmail.com:465' <email.txt"
30//usage: "\n [4<username_and_passwd.txt | -au<username> -ap<password>]"
31//usage: "\n -S HOST[:PORT] Server"
32//usage: "\n -au<username> Username for AUTH LOGIN"
33//usage: "\n -ap<password> Password for AUTH LOGIN"
34//usage: "\n -am<method> Authentication method. Ignored. LOGIN is implied"
35//usage: "\n"
36//usage: "\nOther options are silently ignored; -oi -t is implied"
37//usage: IF_MAKEMIME(
38//usage: "\nUse makemime applet to create message with attachments"
39//usage: )
40
9#include "libbb.h" 41#include "libbb.h"
10#include "mail.h" 42#include "mail.h"
11 43
@@ -13,23 +45,35 @@
13// set to 0 to not limit 45// set to 0 to not limit
14#define MAX_HEADERS 256 46#define MAX_HEADERS 256
15 47
48static void send_r_n(const char *s)
49{
50 if (verbose)
51 bb_error_msg("send:'%s'", s);
52 printf("%s\r\n", s);
53}
54
16static int smtp_checkp(const char *fmt, const char *param, int code) 55static int smtp_checkp(const char *fmt, const char *param, int code)
17{ 56{
18 char *answer; 57 char *answer;
19 const char *msg = command(fmt, param); 58 char *msg = send_mail_command(fmt, param);
20 // read stdin 59 // read stdin
21 // if the string has a form \d\d\d- -- read next string. E.g. EHLO response 60 // if the string has a form NNN- -- read next string. E.g. EHLO response
22 // parse first bytes to a number 61 // parse first bytes to a number
23 // if code = -1 then just return this number 62 // if code = -1 then just return this number
24 // if code != -1 then checks whether the number equals the code 63 // if code != -1 then checks whether the number equals the code
25 // if not equal -> die saying msg 64 // if not equal -> die saying msg
26 while ((answer = xmalloc_fgetline(stdin)) != NULL) 65 while ((answer = xmalloc_fgetline(stdin)) != NULL) {
66// if (verbose)
67 bb_error_msg("recv:'%.*s' %d", (int)(strchrnul(answer, '\r') - answer), answer, verbose);
27 if (strlen(answer) <= 3 || '-' != answer[3]) 68 if (strlen(answer) <= 3 || '-' != answer[3])
28 break; 69 break;
70 free(answer);
71 }
29 if (answer) { 72 if (answer) {
30 int n = atoi(answer); 73 int n = atoi(answer);
31 if (timeout) 74 if (timeout)
32 alarm(0); 75 alarm(0);
76 free(msg);
33 free(answer); 77 free(answer);
34 if (-1 == code || n == code) 78 if (-1 == code || n == code)
35 return n; 79 return n;
@@ -86,6 +130,7 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
86 OPT_H = 1 << 5, // use external connection helper 130 OPT_H = 1 << 5, // use external connection helper
87 OPT_S = 1 << 6, // specify connection string 131 OPT_S = 1 << 6, // specify connection string
88 OPT_a = 1 << 7, // authentication tokens 132 OPT_a = 1 << 7, // authentication tokens
133 OPT_v = 1 << 8, // verbosity
89 }; 134 };
90 135
91 // init global variables 136 // init global variables
@@ -96,12 +141,13 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
96 G.fp0 = xfdopen_for_read(3); 141 G.fp0 = xfdopen_for_read(3);
97 142
98 // parse options 143 // parse options
99 // -f is required. -H and -S are mutually exclusive 144 // -v is a counter, -f is required. -H and -S are mutually exclusive, -a is a list
100 opt_complementary = "f:w+:H--S:S--H:a::"; 145 opt_complementary = "vv:f:w+:H--S:S--H:a::";
101 // N.B. since -H and -S are mutually exclusive they do not interfere in opt_connect 146 // N.B. since -H and -S are mutually exclusive they do not interfere in opt_connect
102 // -a is for ssmtp (http://downloads.openwrt.org/people/nico/man/man8/ssmtp.8.html) compatibility, 147 // -a is for ssmtp (http://downloads.openwrt.org/people/nico/man/man8/ssmtp.8.html) compatibility,
103 // it is still under development. 148 // it is still under development.
104 opts = getopt32(argv, "tf:o:iw:H:S:a::", &opt_from, NULL, &timeout, &opt_connect, &opt_connect, &list); 149 opts = getopt32(argv, "tf:o:iw:H:S:a::v", &opt_from, NULL,
150 &timeout, &opt_connect, &opt_connect, &list, &verbose);
105 //argc -= optind; 151 //argc -= optind;
106 argv += optind; 152 argv += optind;
107 153
@@ -214,7 +260,7 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
214 if ('.' == s[0] /*&& '\0' == s[1] */) 260 if ('.' == s[0] /*&& '\0' == s[1] */)
215 printf("."); 261 printf(".");
216 // dump read line 262 // dump read line
217 printf("%s\r\n", s); 263 send_r_n(s);
218 free(s); 264 free(s);
219 continue; 265 continue;
220 } 266 }
@@ -261,14 +307,14 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
261 goto bail; 307 goto bail;
262 // dump the headers 308 // dump the headers
263 while (list) { 309 while (list) {
264 printf("%s\r\n", (char *) llist_pop(&list)); 310 send_r_n((char *) llist_pop(&list));
265 } 311 }
266 // stop analyzing headers 312 // stop analyzing headers
267 code++; 313 code++;
268 // N.B. !s means: we read nothing, and nothing to be read in the future. 314 // N.B. !s means: we read nothing, and nothing to be read in the future.
269 // just dump empty line and break the loop 315 // just dump empty line and break the loop
270 if (!s) { 316 if (!s) {
271 puts("\r"); 317 send_r_n("");
272 break; 318 break;
273 } 319 }
274 // go dump message body 320 // go dump message body