Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * bare bones sendmail |
| 4 | * |
| 5 | * Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com> |
| 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2, see file LICENSE in this source tree. |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 8 | */ |
Denys Vlasenko | 5707b52 | 2010-12-20 05:12:39 +0100 | [diff] [blame^] | 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 | |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 41 | #include "libbb.h" |
| 42 | #include "mail.h" |
| 43 | |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 44 | // limit maximum allowed number of headers to prevent overflows. |
| 45 | // set to 0 to not limit |
| 46 | #define MAX_HEADERS 256 |
| 47 | |
Denys Vlasenko | 5707b52 | 2010-12-20 05:12:39 +0100 | [diff] [blame^] | 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 | |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 55 | static int smtp_checkp(const char *fmt, const char *param, int code) |
| 56 | { |
| 57 | char *answer; |
Denys Vlasenko | 5707b52 | 2010-12-20 05:12:39 +0100 | [diff] [blame^] | 58 | char *msg = send_mail_command(fmt, param); |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 59 | // read stdin |
Denys Vlasenko | 5707b52 | 2010-12-20 05:12:39 +0100 | [diff] [blame^] | 60 | // if the string has a form NNN- -- read next string. E.g. EHLO response |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 61 | // parse first bytes to a number |
| 62 | // if code = -1 then just return this number |
| 63 | // if code != -1 then checks whether the number equals the code |
| 64 | // if not equal -> die saying msg |
Denys Vlasenko | 5707b52 | 2010-12-20 05:12:39 +0100 | [diff] [blame^] | 65 | while ((answer = xmalloc_fgetline(stdin)) != NULL) { |
| 66 | // if (verbose) |
| 67 | bb_error_msg("recv:'%.*s' %d", (int)(strchrnul(answer, '\r') - answer), answer, verbose); |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 68 | if (strlen(answer) <= 3 || '-' != answer[3]) |
| 69 | break; |
Denys Vlasenko | 5707b52 | 2010-12-20 05:12:39 +0100 | [diff] [blame^] | 70 | free(answer); |
| 71 | } |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 72 | if (answer) { |
| 73 | int n = atoi(answer); |
| 74 | if (timeout) |
| 75 | alarm(0); |
Denys Vlasenko | 5707b52 | 2010-12-20 05:12:39 +0100 | [diff] [blame^] | 76 | free(msg); |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 77 | free(answer); |
| 78 | if (-1 == code || n == code) |
| 79 | return n; |
| 80 | } |
| 81 | bb_error_msg_and_die("%s failed", msg); |
| 82 | } |
| 83 | |
| 84 | static int smtp_check(const char *fmt, int code) |
| 85 | { |
| 86 | return smtp_checkp(fmt, NULL, code); |
| 87 | } |
| 88 | |
| 89 | // strip argument of bad chars |
| 90 | static char *sane_address(char *str) |
| 91 | { |
| 92 | char *s = str; |
| 93 | char *p = s; |
| 94 | while (*s) { |
| 95 | if (isalnum(*s) || '_' == *s || '-' == *s || '.' == *s || '@' == *s) { |
| 96 | *p++ = *s; |
| 97 | } |
| 98 | s++; |
| 99 | } |
| 100 | *p = '\0'; |
| 101 | return str; |
| 102 | } |
| 103 | |
| 104 | static void rcptto(const char *s) |
| 105 | { |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 106 | // N.B. we don't die if recipient is rejected, for the other recipients may be accepted |
| 107 | if (250 != smtp_checkp("RCPT TO:<%s>", s, -1)) |
| 108 | bb_error_msg("Bad recipient: <%s>", s); |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | int sendmail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 112 | int sendmail_main(int argc UNUSED_PARAM, char **argv) |
| 113 | { |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 114 | char *opt_connect = opt_connect; |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 115 | char *opt_from; |
| 116 | char *s; |
| 117 | llist_t *list = NULL; |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 118 | char *domain = sane_address(safe_getdomainname()); |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 119 | unsigned nheaders = 0; |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 120 | int code; |
| 121 | |
| 122 | enum { |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 123 | //--- standard options |
| 124 | OPT_t = 1 << 0, // read message for recipients, append them to those on cmdline |
| 125 | OPT_f = 1 << 1, // sender address |
| 126 | OPT_o = 1 << 2, // various options. -oi IMPLIED! others are IGNORED! |
Vladimir Dronnikov | b618dba | 2009-10-04 01:34:54 +0200 | [diff] [blame] | 127 | OPT_i = 1 << 3, // IMPLIED! |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 128 | //--- BB specific options |
Vladimir Dronnikov | b618dba | 2009-10-04 01:34:54 +0200 | [diff] [blame] | 129 | OPT_w = 1 << 4, // network timeout |
| 130 | OPT_H = 1 << 5, // use external connection helper |
| 131 | OPT_S = 1 << 6, // specify connection string |
| 132 | OPT_a = 1 << 7, // authentication tokens |
Denys Vlasenko | 5707b52 | 2010-12-20 05:12:39 +0100 | [diff] [blame^] | 133 | OPT_v = 1 << 8, // verbosity |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | // init global variables |
| 137 | INIT_G(); |
| 138 | |
| 139 | // save initial stdin since body is piped! |
| 140 | xdup2(STDIN_FILENO, 3); |
Denys Vlasenko | a7ccdee | 2009-11-15 23:28:11 +0100 | [diff] [blame] | 141 | G.fp0 = xfdopen_for_read(3); |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 142 | |
| 143 | // parse options |
Denys Vlasenko | 5707b52 | 2010-12-20 05:12:39 +0100 | [diff] [blame^] | 144 | // -v is a counter, -f is required. -H and -S are mutually exclusive, -a is a list |
| 145 | opt_complementary = "vv:f:w+:H--S:S--H:a::"; |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 146 | // N.B. since -H and -S are mutually exclusive they do not interfere in opt_connect |
| 147 | // -a is for ssmtp (http://downloads.openwrt.org/people/nico/man/man8/ssmtp.8.html) compatibility, |
| 148 | // it is still under development. |
Denys Vlasenko | 5707b52 | 2010-12-20 05:12:39 +0100 | [diff] [blame^] | 149 | opts = getopt32(argv, "tf:o:iw:H:S:a::v", &opt_from, NULL, |
| 150 | &timeout, &opt_connect, &opt_connect, &list, &verbose); |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 151 | //argc -= optind; |
| 152 | argv += optind; |
| 153 | |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 154 | // process -a[upm]<token> options |
| 155 | if ((opts & OPT_a) && !list) |
| 156 | bb_show_usage(); |
| 157 | while (list) { |
| 158 | char *a = (char *) llist_pop(&list); |
| 159 | if ('u' == a[0]) |
| 160 | G.user = xstrdup(a+1); |
| 161 | if ('p' == a[0]) |
| 162 | G.pass = xstrdup(a+1); |
| 163 | // N.B. we support only AUTH LOGIN so far |
| 164 | //if ('m' == a[0]) |
| 165 | // G.method = xstrdup(a+1); |
| 166 | } |
| 167 | // N.B. list == NULL here |
| 168 | //bb_info_msg("OPT[%x] AU[%s], AP[%s], AM[%s], ARGV[%s]", opts, au, ap, am, *argv); |
| 169 | |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 170 | // connect to server |
| 171 | |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 172 | // connection helper ordered? -> |
| 173 | if (opts & OPT_H) { |
| 174 | const char *args[] = { "sh", "-c", opt_connect, NULL }; |
| 175 | // plug it in |
| 176 | launch_helper(args); |
| 177 | // vanilla connection |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 178 | } else { |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 179 | int fd; |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 180 | // host[:port] not explicitly specified? -> use $SMTPHOST |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 181 | // no $SMTPHOST ? -> use localhost |
| 182 | if (!(opts & OPT_S)) { |
| 183 | opt_connect = getenv("SMTPHOST"); |
| 184 | if (!opt_connect) |
| 185 | opt_connect = (char *)"127.0.0.1"; |
| 186 | } |
| 187 | // do connect |
| 188 | fd = create_and_connect_stream_or_die(opt_connect, 25); |
| 189 | // and make ourselves a simple IO filter |
| 190 | xmove_fd(fd, STDIN_FILENO); |
| 191 | xdup2(STDIN_FILENO, STDOUT_FILENO); |
| 192 | } |
| 193 | // N.B. from now we know nothing about network :) |
| 194 | |
| 195 | // wait for initial server OK |
| 196 | // N.B. if we used openssl the initial 220 answer is already swallowed during openssl TLS init procedure |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 197 | // so we need to kick the server to see whether we are ok |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 198 | code = smtp_check("NOOP", -1); |
| 199 | // 220 on plain connection, 250 on openssl-helped TLS session |
| 200 | if (220 == code) |
| 201 | smtp_check(NULL, 250); // reread the code to stay in sync |
| 202 | else if (250 != code) |
| 203 | bb_error_msg_and_die("INIT failed"); |
| 204 | |
| 205 | // we should start with modern EHLO |
| 206 | if (250 != smtp_checkp("EHLO %s", domain, -1)) { |
| 207 | smtp_checkp("HELO %s", domain, 250); |
| 208 | } |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 209 | if (ENABLE_FEATURE_CLEAN_UP) |
| 210 | free(domain); |
| 211 | |
| 212 | // perform authentication |
| 213 | if (opts & OPT_a) { |
| 214 | smtp_check("AUTH LOGIN", 334); |
| 215 | // we must read credentials unless they are given via -a[up] options |
| 216 | if (!G.user || !G.pass) |
| 217 | get_cred_or_die(4); |
| 218 | encode_base64(NULL, G.user, NULL); |
| 219 | smtp_check("", 334); |
| 220 | encode_base64(NULL, G.pass, NULL); |
| 221 | smtp_check("", 235); |
| 222 | } |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 223 | |
| 224 | // set sender |
| 225 | // N.B. we have here a very loosely defined algotythm |
| 226 | // since sendmail historically offers no means to specify secrets on cmdline. |
| 227 | // 1) server can require no authentication -> |
| 228 | // we must just provide a (possibly fake) reply address. |
| 229 | // 2) server can require AUTH -> |
| 230 | // we must provide valid username and password along with a (possibly fake) reply address. |
| 231 | // For the sake of security username and password are to be read either from console or from a secured file. |
| 232 | // Since reading from console may defeat usability, the solution is either to read from a predefined |
| 233 | // file descriptor (e.g. 4), or again from a secured file. |
| 234 | |
| 235 | // got no sender address? -> use system username as a resort |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 236 | // N.B. we marked -f as required option! |
| 237 | //if (!G.user) { |
| 238 | // // N.B. IMHO getenv("USER") can be way easily spoofed! |
| 239 | // G.user = xuid2uname(getuid()); |
| 240 | // opt_from = xasprintf("%s@%s", G.user, domain); |
| 241 | //} |
| 242 | //if (ENABLE_FEATURE_CLEAN_UP) |
| 243 | // free(domain); |
| 244 | smtp_checkp("MAIL FROM:<%s>", opt_from, 250); |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 245 | |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 246 | // process message |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 247 | |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 248 | // read recipients from message and add them to those given on cmdline. |
| 249 | // this means we scan stdin for To:, Cc:, Bcc: lines until an empty line |
| 250 | // and then use the rest of stdin as message body |
| 251 | code = 0; // set "analyze headers" mode |
| 252 | while ((s = xmalloc_fgetline(G.fp0)) != NULL) { |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 253 | dump: |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 254 | // put message lines doubling leading dots |
| 255 | if (code) { |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 256 | // escape leading dots |
| 257 | // N.B. this feature is implied even if no -i (-oi) switch given |
| 258 | // N.B. we need to escape the leading dot regardless of |
| 259 | // whether it is single or not character on the line |
| 260 | if ('.' == s[0] /*&& '\0' == s[1] */) |
| 261 | printf("."); |
| 262 | // dump read line |
Denys Vlasenko | 5707b52 | 2010-12-20 05:12:39 +0100 | [diff] [blame^] | 263 | send_r_n(s); |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 264 | free(s); |
| 265 | continue; |
| 266 | } |
| 267 | |
| 268 | // analyze headers |
| 269 | // To: or Cc: headers add recipients |
Vladimir Dronnikov | 5b34300 | 2010-10-05 01:21:32 +0200 | [diff] [blame] | 270 | if (0 == strncasecmp("To:", s, 3) || 0 == strncasecmp("Bcc:" + 1, s, 3)) { |
| 271 | rcptto(sane_address(s+3)); |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 272 | goto addheader; |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 273 | // Bcc: header adds blind copy (hidden) recipient |
Vladimir Dronnikov | 5b34300 | 2010-10-05 01:21:32 +0200 | [diff] [blame] | 274 | } else if (0 == strncasecmp("Bcc:", s, 4)) { |
| 275 | rcptto(sane_address(s+4)); |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 276 | free(s); |
| 277 | // N.B. Bcc: vanishes from headers! |
Vladimir Dronnikov | 8dbe9bb | 2009-10-17 03:35:10 +0200 | [diff] [blame] | 278 | |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 279 | // other headers go verbatim |
Vladimir Dronnikov | 8dbe9bb | 2009-10-17 03:35:10 +0200 | [diff] [blame] | 280 | |
| 281 | // N.B. RFC2822 2.2.3 "Long Header Fields" allows for headers to occupy several lines. |
| 282 | // Continuation is denoted by prefixing additional lines with whitespace(s). |
| 283 | // Thanks (stefan.seyfried at googlemail.com) for pointing this out. |
| 284 | } else if (strchr(s, ':') || (list && skip_whitespace(s) != s)) { |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 285 | addheader: |
Vladimir Dronnikov | 8dbe9bb | 2009-10-17 03:35:10 +0200 | [diff] [blame] | 286 | // N.B. we allow MAX_HEADERS generic headers at most to prevent attacks |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 287 | if (MAX_HEADERS && ++nheaders >= MAX_HEADERS) |
| 288 | goto bail; |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 289 | llist_add_to_end(&list, s); |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 290 | // a line without ":" (an empty line too, by definition) doesn't look like a valid header |
| 291 | // so stop "analyze headers" mode |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 292 | } else { |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 293 | reenter: |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 294 | // put recipients specified on cmdline |
| 295 | while (*argv) { |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 296 | char *t = sane_address(*argv); |
| 297 | rcptto(t); |
| 298 | //if (MAX_HEADERS && ++nheaders >= MAX_HEADERS) |
| 299 | // goto bail; |
| 300 | llist_add_to_end(&list, xasprintf("To: %s", t)); |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 301 | argv++; |
| 302 | } |
| 303 | // enter "put message" mode |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 304 | // N.B. DATA fails iff no recipients were accepted (or even provided) |
| 305 | // in this case just bail out gracefully |
| 306 | if (354 != smtp_check("DATA", -1)) |
| 307 | goto bail; |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 308 | // dump the headers |
| 309 | while (list) { |
Denys Vlasenko | 5707b52 | 2010-12-20 05:12:39 +0100 | [diff] [blame^] | 310 | send_r_n((char *) llist_pop(&list)); |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 311 | } |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 312 | // stop analyzing headers |
| 313 | code++; |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 314 | // N.B. !s means: we read nothing, and nothing to be read in the future. |
| 315 | // just dump empty line and break the loop |
| 316 | if (!s) { |
Denys Vlasenko | 5707b52 | 2010-12-20 05:12:39 +0100 | [diff] [blame^] | 317 | send_r_n(""); |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 318 | break; |
| 319 | } |
| 320 | // go dump message body |
| 321 | // N.B. "s" already contains the first non-header line, so pretend we read it from input |
| 322 | goto dump; |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 325 | // odd case: we didn't stop "analyze headers" mode -> message body is empty. Reenter the loop |
| 326 | // N.B. after reenter code will be > 0 |
| 327 | if (!code) |
| 328 | goto reenter; |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 329 | |
Denis Vlasenko | 88b8f0a | 2009-03-31 23:41:53 +0000 | [diff] [blame] | 330 | // finalize the message |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 331 | smtp_check(".", 250); |
Vladimir Dronnikov | 944d275 | 2009-10-15 23:50:48 +0200 | [diff] [blame] | 332 | bail: |
Denis Vlasenko | 239d06b | 2008-11-06 23:42:42 +0000 | [diff] [blame] | 333 | // ... and say goodbye |
| 334 | smtp_check("QUIT", 221); |
| 335 | // cleanup |
| 336 | if (ENABLE_FEATURE_CLEAN_UP) |
| 337 | fclose(G.fp0); |
| 338 | |
| 339 | return EXIT_SUCCESS; |
| 340 | } |