diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-12-20 05:12:39 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-12-20 05:12:39 +0100 |
commit | 5707b52fd4de0d9d5ebb496f459fa4fa66215226 (patch) | |
tree | 40ccc1ba8324ada382607c07e16203239043aa37 | |
parent | 27c6c00a7cf141aaa972c0f9691072db287a36ae (diff) | |
download | busybox-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>
-rw-r--r-- | include/usage.src.h | 30 | ||||
-rw-r--r-- | mailutils/mail.c | 11 | ||||
-rw-r--r-- | mailutils/mail.h | 18 | ||||
-rw-r--r-- | mailutils/mime.c | 32 | ||||
-rw-r--r-- | mailutils/popmaildir.c | 5 | ||||
-rw-r--r-- | mailutils/sendmail.c | 64 |
6 files changed, 106 insertions, 54 deletions
diff --git a/include/usage.src.h b/include/usage.src.h index cd37a892d..4640338e6 100644 --- a/include/usage.src.h +++ b/include/usage.src.h | |||
@@ -3211,36 +3211,6 @@ INSERT | |||
3211 | #define selinuxenabled_trivial_usage NOUSAGE_STR | 3211 | #define selinuxenabled_trivial_usage NOUSAGE_STR |
3212 | #define selinuxenabled_full_usage "" | 3212 | #define selinuxenabled_full_usage "" |
3213 | 3213 | ||
3214 | #define sendmail_trivial_usage \ | ||
3215 | "[OPTIONS] [RECIPIENT_EMAIL]..." | ||
3216 | #define sendmail_full_usage "\n\n" \ | ||
3217 | "Read email from stdin and send it\n" \ | ||
3218 | "\nStandard options:" \ | ||
3219 | "\n -t Read additional recipients from message body" \ | ||
3220 | "\n -f sender Sender (required)" \ | ||
3221 | "\n -o options Various options. -oi implied, others are ignored" \ | ||
3222 | "\n -i -oi synonym. implied and ignored" \ | ||
3223 | "\n" \ | ||
3224 | "\nBusybox specific options:" \ | ||
3225 | "\n -w seconds Network timeout" \ | ||
3226 | "\n -H 'PROG ARGS' Run connection helper" \ | ||
3227 | "\n Examples:" \ | ||
3228 | "\n -H 'exec openssl s_client -quiet -tls1 -starttls smtp" \ | ||
3229 | "\n -connect smtp.gmail.com:25' <email.txt" \ | ||
3230 | "\n [4<username_and_passwd.txt | -au<username> -ap<password>]" \ | ||
3231 | "\n -H 'exec openssl s_client -quiet -tls1" \ | ||
3232 | "\n -connect smtp.gmail.com:465' <email.txt" \ | ||
3233 | "\n [4<username_and_passwd.txt | -au<username> -ap<password>]" \ | ||
3234 | "\n -S server[:port] Server" \ | ||
3235 | "\n -au<username> Username for AUTH LOGIN" \ | ||
3236 | "\n -ap<password> Password for AUTH LOGIN" \ | ||
3237 | "\n -am<method> Authentication method. Ignored. LOGIN is implied" \ | ||
3238 | "\n" \ | ||
3239 | "\nOther options are silently ignored; -oi -t is implied" \ | ||
3240 | IF_MAKEMIME( \ | ||
3241 | "\nUse makemime applet to create message with attachments" \ | ||
3242 | ) | ||
3243 | |||
3244 | #define seq_trivial_usage \ | 3214 | #define seq_trivial_usage \ |
3245 | "[-w] [-s SEP] [FIRST [INC]] LAST" | 3215 | "[-w] [-s SEP] [FIRST [INC]] LAST" |
3246 | #define seq_full_usage "\n\n" \ | 3216 | #define seq_full_usage "\n\n" \ |
diff --git a/mailutils/mail.c b/mailutils/mail.c index 9b4bebce5..44957016f 100644 --- a/mailutils/mail.c +++ b/mailutils/mail.c | |||
@@ -75,13 +75,16 @@ void FAST_FUNC launch_helper(const char **argv) | |||
75 | atexit(kill_helper); | 75 | atexit(kill_helper); |
76 | } | 76 | } |
77 | 77 | ||
78 | const FAST_FUNC char *command(const char *fmt, const char *param) | 78 | char* FAST_FUNC send_mail_command(const char *fmt, const char *param) |
79 | { | 79 | { |
80 | const char *msg = fmt; | 80 | char *msg; |
81 | if (timeout) | 81 | if (timeout) |
82 | alarm(timeout); | 82 | alarm(timeout); |
83 | if (msg) { | 83 | msg = (char*)fmt; |
84 | if (fmt) { | ||
84 | msg = xasprintf(fmt, param); | 85 | msg = xasprintf(fmt, param); |
86 | if (verbose) | ||
87 | bb_error_msg("send:'%s'", msg); | ||
85 | printf("%s\r\n", msg); | 88 | printf("%s\r\n", msg); |
86 | } | 89 | } |
87 | fflush_all(); | 90 | fflush_all(); |
@@ -90,7 +93,7 @@ const FAST_FUNC char *command(const char *fmt, const char *param) | |||
90 | 93 | ||
91 | // NB: parse_url can modify url[] (despite const), but only if '@' is there | 94 | // NB: parse_url can modify url[] (despite const), but only if '@' is there |
92 | /* | 95 | /* |
93 | static char FAST_FUNC *parse_url(char *url, char **user, char **pass) | 96 | static char* FAST_FUNC parse_url(char *url, char **user, char **pass) |
94 | { | 97 | { |
95 | // parse [user[:pass]@]host | 98 | // parse [user[:pass]@]host |
96 | // return host | 99 | // return host |
diff --git a/mailutils/mail.h b/mailutils/mail.h index e0048fbfa..d1d783055 100644 --- a/mailutils/mail.h +++ b/mailutils/mail.h | |||
@@ -1,7 +1,16 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * helper routines | ||
4 | * | ||
5 | * Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com> | ||
6 | * | ||
7 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
8 | */ | ||
1 | 9 | ||
2 | struct globals { | 10 | struct globals { |
3 | pid_t helper_pid; | 11 | pid_t helper_pid; |
4 | unsigned timeout; | 12 | unsigned timeout; |
13 | unsigned verbose; | ||
5 | unsigned opts; | 14 | unsigned opts; |
6 | char *user; | 15 | char *user; |
7 | char *pass; | 16 | char *pass; |
@@ -12,6 +21,7 @@ struct globals { | |||
12 | 21 | ||
13 | #define G (*ptr_to_globals) | 22 | #define G (*ptr_to_globals) |
14 | #define timeout (G.timeout ) | 23 | #define timeout (G.timeout ) |
24 | #define verbose (G.verbose ) | ||
15 | #define opts (G.opts ) | 25 | #define opts (G.opts ) |
16 | //#define user (G.user ) | 26 | //#define user (G.user ) |
17 | //#define pass (G.pass ) | 27 | //#define pass (G.pass ) |
@@ -26,9 +36,9 @@ struct globals { | |||
26 | 36 | ||
27 | //char FAST_FUNC *parse_url(char *url, char **user, char **pass); | 37 | //char FAST_FUNC *parse_url(char *url, char **user, char **pass); |
28 | 38 | ||
29 | void FAST_FUNC launch_helper(const char **argv); | 39 | void launch_helper(const char **argv) FAST_FUNC; |
30 | void FAST_FUNC get_cred_or_die(int fd); | 40 | void get_cred_or_die(int fd) FAST_FUNC; |
31 | 41 | ||
32 | const FAST_FUNC char *command(const char *fmt, const char *param); | 42 | char *send_mail_command(const char *fmt, const char *param) FAST_FUNC; |
33 | 43 | ||
34 | void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol); | 44 | void encode_base64(char *fname, const char *text, const char *eol) FAST_FUNC; |
diff --git a/mailutils/mime.c b/mailutils/mime.c index 682cf4536..1e393ed31 100644 --- a/mailutils/mime.c +++ b/mailutils/mime.c | |||
@@ -99,6 +99,28 @@ Content-Transfer-Encoding: 7bit | |||
99 | ...random junk added by mailing list robots and such... | 99 | ...random junk added by mailing list robots and such... |
100 | */ | 100 | */ |
101 | 101 | ||
102 | /* man makemime: | ||
103 | |||
104 | * -c TYPE: create a (non-multipart) MIME section with Content-Type: TYPE | ||
105 | * makemime -c TYPE [-e ENCODING] [-o OUTFILE] [-C CHARSET] [-N NAME] [-a HEADER...] FILE | ||
106 | * The -C option sets the MIME charset attribute for text/plain content. | ||
107 | * The -N option sets the name attribute for Content-Type: | ||
108 | * Encoding must be one of the following: 7bit, 8bit, quoted-printable, or base64. | ||
109 | |||
110 | * -m multipart/TYPE: create a multipart MIME collection with Content-Type: multipart/TYPE | ||
111 | * makemime -m multipart/TYPE [-e ENCODING] [-o OUTFILE] [-a HEADER...] FILE | ||
112 | * Type must be either "multipart/mixed", "multipart/alternative", or some other MIME multipart content type. | ||
113 | * Additionally, encoding can only be "7bit" or "8bit", and will default to "8bit" if not specified. | ||
114 | * Finally, filename must be a MIME-formatted section, NOT a regular file. | ||
115 | * The -m option creates an initial multipart MIME collection, that contains only one MIME section, taken from filename. | ||
116 | * The collection is written to standard output, or the pipe or to outputfile. | ||
117 | |||
118 | * -j FILE1: add a section to a multipart MIME collection | ||
119 | * makemime -j FILE1 [-o OUTFILE] FILE2 | ||
120 | * FILE1 must be a MIME collection that was previously created by the -m option. | ||
121 | * FILE2 must be a MIME section that was previously created by the -c option. | ||
122 | * The -j options adds the MIME section in FILE2 to the MIME collection in FILE1. | ||
123 | */ | ||
102 | int makemime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 124 | int makemime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
103 | int makemime_main(int argc UNUSED_PARAM, char **argv) | 125 | int makemime_main(int argc UNUSED_PARAM, char **argv) |
104 | { | 126 | { |
@@ -107,14 +129,14 @@ int makemime_main(int argc UNUSED_PARAM, char **argv) | |||
107 | #define boundary opt_output | 129 | #define boundary opt_output |
108 | 130 | ||
109 | enum { | 131 | enum { |
110 | OPT_c = 1 << 0, // Content-Type: | 132 | OPT_c = 1 << 0, // create (non-multipart) section |
111 | OPT_e = 1 << 1, // Content-Transfer-Encoding. Ignored. Assumed base64 | 133 | OPT_e = 1 << 1, // Content-Transfer-Encoding. Ignored. Assumed base64 |
112 | OPT_o = 1 << 2, // output to | 134 | OPT_o = 1 << 2, // output to |
113 | OPT_C = 1 << 3, // charset | 135 | OPT_C = 1 << 3, // charset |
114 | OPT_N = 1 << 4, // COMPAT | 136 | OPT_N = 1 << 4, // COMPAT |
115 | OPT_a = 1 << 5, // additional headers | 137 | OPT_a = 1 << 5, // additional headers |
116 | OPT_m = 1 << 6, // COMPAT | 138 | //OPT_m = 1 << 6, // create mutipart section |
117 | OPT_j = 1 << 7, // COMPAT | 139 | //OPT_j = 1 << 7, // join section to multipart section |
118 | }; | 140 | }; |
119 | 141 | ||
120 | INIT_G(); | 142 | INIT_G(); |
@@ -122,8 +144,8 @@ int makemime_main(int argc UNUSED_PARAM, char **argv) | |||
122 | // parse options | 144 | // parse options |
123 | opt_complementary = "a::"; | 145 | opt_complementary = "a::"; |
124 | opts = getopt32(argv, | 146 | opts = getopt32(argv, |
125 | "c:e:o:C:N:a:m:j:", | 147 | "c:e:o:C:N:a", //:m:j:", |
126 | &G.content_type, NULL, &opt_output, &G.opt_charset, NULL, &opt_headers, NULL, NULL | 148 | &G.content_type, NULL, &opt_output, &G.opt_charset, NULL, &opt_headers //, NULL, NULL |
127 | ); | 149 | ); |
128 | //argc -= optind; | 150 | //argc -= optind; |
129 | argv += optind; | 151 | argv += optind; |
diff --git a/mailutils/popmaildir.c b/mailutils/popmaildir.c index 77ec71129..6b733441f 100644 --- a/mailutils/popmaildir.c +++ b/mailutils/popmaildir.c | |||
@@ -14,9 +14,10 @@ | |||
14 | 14 | ||
15 | static void pop3_checkr(const char *fmt, const char *param, char **ret) | 15 | static void pop3_checkr(const char *fmt, const char *param, char **ret) |
16 | { | 16 | { |
17 | const char *msg = command(fmt, param); | 17 | char *msg = send_mail_command(fmt, param); |
18 | char *answer = xmalloc_fgetline(stdin); | 18 | char *answer = xmalloc_fgetline(stdin); |
19 | if (answer && '+' == answer[0]) { | 19 | if (answer && '+' == answer[0]) { |
20 | free(msg); | ||
20 | if (timeout) | 21 | if (timeout) |
21 | alarm(0); | 22 | alarm(0); |
22 | if (ret) { | 23 | if (ret) { |
@@ -27,7 +28,7 @@ static void pop3_checkr(const char *fmt, const char *param, char **ret) | |||
27 | free(answer); | 28 | free(answer); |
28 | return; | 29 | return; |
29 | } | 30 | } |
30 | bb_error_msg_and_die("%s failed: %s", msg, answer); | 31 | bb_error_msg_and_die("%s failed, reply was: %s", msg, answer); |
31 | } | 32 | } |
32 | 33 | ||
33 | static void pop3_check(const char *fmt, const char *param) | 34 | static void pop3_check(const char *fmt, const char *param) |
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 | ||
48 | static 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 | |||
16 | static int smtp_checkp(const char *fmt, const char *param, int code) | 55 | static 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 |