Various SMTP improvements.
* Makefile.am: Shut up cmp's stderr. * libmailutils/body.c (_body_get_stream): Set full buffering mode on the body stream. * libmailutils/errors (MU_ERR_AUTH_NO_CRED): New error code. * libproto/mailer/smtp.c (smtp_open): Do not treat ENOSYS or MU_ERR_AUTH_NO_CRED (returned by mu_smtp_auth) as errors. (smtp_send_message): Do not try to submit the message if it is bigger than the maximum imposed by the server. * libproto/mailer/smtp_auth.c (mu_smtp_auth): Return MU_ERR_AUTH_NO_CRED if neither user name nor password are supplied. * mail/send.c (mail_send0): Issue diagnostics if sending attempt has failed.
Showing
6 changed files
with
44 additions
and
14 deletions
... | @@ -162,7 +162,8 @@ git-describe: | ... | @@ -162,7 +162,8 @@ git-describe: |
162 | test -n "$$dirty" && dirty="-dirty"; \ | 162 | test -n "$$dirty" && dirty="-dirty"; \ |
163 | descr=`git describe`; \ | 163 | descr=`git describe`; \ |
164 | echo $${descr}$$dirty > git-describe.tmp; \ | 164 | echo $${descr}$$dirty > git-describe.tmp; \ |
165 | test -f git-describe && cmp git-describe.tmp git-describe || \ | 165 | test -f git-describe && \ |
166 | cmp git-describe.tmp git-describe >/dev/null || \ | ||
166 | cp git-describe.tmp git-describe; \ | 167 | cp git-describe.tmp git-describe; \ |
167 | rm git-describe.tmp; \ | 168 | rm git-describe.tmp; \ |
168 | fi | 169 | fi |
... | @@ -183,7 +184,8 @@ git-describe.h: git-describe | ... | @@ -183,7 +184,8 @@ git-describe.h: git-describe |
183 | else \ | 184 | else \ |
184 | echo "/* No git tag */"; \ | 185 | echo "/* No git tag */"; \ |
185 | fi > git-describe.h.tmp; \ | 186 | fi > git-describe.h.tmp; \ |
186 | test -f git-describe.h && cmp git-describe.h.tmp git-describe.h || \ | 187 | test -f git-describe.h && \ |
188 | cmp git-describe.h.tmp git-describe.h >/dev/null || \ | ||
187 | cp git-describe.h.tmp git-describe.h; \ | 189 | cp git-describe.h.tmp git-describe.h; \ |
188 | rm git-describe.h.tmp | 190 | rm git-describe.h.tmp |
189 | 191 | ... | ... |
... | @@ -183,6 +183,7 @@ _body_get_stream (mu_body_t body, mu_stream_t *pstream, int ref) | ... | @@ -183,6 +183,7 @@ _body_get_stream (mu_body_t body, mu_stream_t *pstream, int ref) |
183 | body->filename, MU_STREAM_RDWR); | 183 | body->filename, MU_STREAM_RDWR); |
184 | if (status != 0) | 184 | if (status != 0) |
185 | return status; | 185 | return status; |
186 | mu_stream_set_buffer (body->fstream, mu_buffer_full, 0); | ||
186 | status = mu_stream_open (body->fstream); | 187 | status = mu_stream_open (body->fstream); |
187 | if (status != 0) | 188 | if (status != 0) |
188 | return status; | 189 | return status; | ... | ... |
... | @@ -93,3 +93,4 @@ MU_ERR_BAD_FILENAME _("Badly formed file or directory name") | ... | @@ -93,3 +93,4 @@ MU_ERR_BAD_FILENAME _("Badly formed file or directory name") |
93 | MU_ERR_READ _("Read error") | 93 | MU_ERR_READ _("Read error") |
94 | 94 | ||
95 | MU_ERR_NO_TRANSPORT _("Transport stream not set") | 95 | MU_ERR_NO_TRANSPORT _("Transport stream not set") |
96 | MU_ERR_AUTH_NO_CRED _("No credentials supplied") | ... | ... |
... | @@ -124,9 +124,11 @@ smtp_open (mu_mailer_t mailer, int flags) | ... | @@ -124,9 +124,11 @@ smtp_open (mu_mailer_t mailer, int flags) |
124 | if (mu_debug_check_level (mailer->debug, MU_DEBUG_PROT)) | 124 | if (mu_debug_check_level (mailer->debug, MU_DEBUG_PROT)) |
125 | mu_smtp_trace (smtp_mailer->smtp, MU_SMTP_TRACE_SET); | 125 | mu_smtp_trace (smtp_mailer->smtp, MU_SMTP_TRACE_SET); |
126 | if (mu_debug_check_level (mailer->debug, MU_DEBUG_TRACE6)) | 126 | if (mu_debug_check_level (mailer->debug, MU_DEBUG_TRACE6)) |
127 | mu_smtp_trace_mask (smtp_mailer->smtp, MU_SMTP_TRACE_SET, MU_XSCRIPT_SECURE); | 127 | mu_smtp_trace_mask (smtp_mailer->smtp, MU_SMTP_TRACE_SET, |
128 | MU_XSCRIPT_SECURE); | ||
128 | if (mu_debug_check_level (mailer->debug, MU_DEBUG_TRACE7)) | 129 | if (mu_debug_check_level (mailer->debug, MU_DEBUG_TRACE7)) |
129 | mu_smtp_trace_mask (smtp_mailer->smtp, MU_SMTP_TRACE_SET, MU_XSCRIPT_PAYLOAD); | 130 | mu_smtp_trace_mask (smtp_mailer->smtp, MU_SMTP_TRACE_SET, |
131 | MU_XSCRIPT_PAYLOAD); | ||
130 | 132 | ||
131 | mu_smtp_set_param (smtp_mailer->smtp, MU_SMTP_PARAM_URL, | 133 | mu_smtp_set_param (smtp_mailer->smtp, MU_SMTP_PARAM_URL, |
132 | mu_url_to_string (mailer->url)); | 134 | mu_url_to_string (mailer->url)); |
... | @@ -203,9 +205,19 @@ smtp_open (mu_mailer_t mailer, int flags) | ... | @@ -203,9 +205,19 @@ smtp_open (mu_mailer_t mailer, int flags) |
203 | if (!noauth && mu_smtp_capa_test (smtp_mailer->smtp, "AUTH", NULL) == 0) | 205 | if (!noauth && mu_smtp_capa_test (smtp_mailer->smtp, "AUTH", NULL) == 0) |
204 | { | 206 | { |
205 | rc = mu_smtp_auth (smtp_mailer->smtp); | 207 | rc = mu_smtp_auth (smtp_mailer->smtp); |
206 | if (rc) | 208 | switch (rc) |
207 | return rc; | 209 | { |
208 | rc = mu_smtp_ehlo (smtp_mailer->smtp); | 210 | case 0: |
211 | rc = mu_smtp_ehlo (smtp_mailer->smtp); | ||
212 | break; | ||
213 | |||
214 | case ENOSYS: | ||
215 | case MU_ERR_AUTH_NO_CRED: | ||
216 | mu_diag_output (MU_DIAG_NOTICE, "authentication disabled: %s", | ||
217 | mu_strerror (rc)); | ||
218 | rc = 0; /* Continue anyway */ | ||
219 | break; | ||
220 | } | ||
209 | if (rc) | 221 | if (rc) |
210 | return rc; | 222 | return rc; |
211 | } | 223 | } |
... | @@ -377,7 +389,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t msg, | ... | @@ -377,7 +389,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t msg, |
377 | mu_smtp_t smtp = smp->smtp; | 389 | mu_smtp_t smtp = smp->smtp; |
378 | int status; | 390 | int status; |
379 | size_t size, lines, count; | 391 | size_t size, lines, count; |
380 | const char *mail_from; | 392 | const char *mail_from, *size_str; |
381 | mu_header_t header; | 393 | mu_header_t header; |
382 | 394 | ||
383 | if (mailer == NULL) | 395 | if (mailer == NULL) |
... | @@ -398,12 +410,19 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t msg, | ... | @@ -398,12 +410,19 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t msg, |
398 | if (status) | 410 | if (status) |
399 | return status; | 411 | return status; |
400 | 412 | ||
401 | if (mu_smtp_capa_test (smp->smtp, "SIZE", NULL) == 0 && | 413 | if (mu_smtp_capa_test (smp->smtp, "SIZE", &size_str) == 0 && |
402 | mu_message_size (msg, &size) == 0 && | 414 | mu_message_size (msg, &size) == 0 && |
403 | mu_message_lines (msg, &lines) == 0) | 415 | mu_message_lines (msg, &lines) == 0) |
404 | status = mu_smtp_mail_basic (smp->smtp, mail_from, | 416 | { |
405 | "SIZE=%lu", | 417 | size_t msgsize = size + lines; |
406 | (unsigned long) (size + lines)); | 418 | size_t maxsize = strtoul (size_str + 5, NULL, 10); |
419 | |||
420 | if (msgsize && msgsize > maxsize) | ||
421 | return EFBIG; | ||
422 | status = mu_smtp_mail_basic (smp->smtp, mail_from, | ||
423 | "SIZE=%lu", | ||
424 | (unsigned long) msgsize); | ||
425 | } | ||
407 | else | 426 | else |
408 | status = mu_smtp_mail_basic (smp->smtp, mail_from, NULL); | 427 | status = mu_smtp_mail_basic (smp->smtp, mail_from, NULL); |
409 | if (status) | 428 | if (status) | ... | ... |
... | @@ -141,6 +141,8 @@ mu_smtp_auth (mu_smtp_t smtp) | ... | @@ -141,6 +141,8 @@ mu_smtp_auth (mu_smtp_t smtp) |
141 | default it does that on tty, which obviously will not suite | 141 | default it does that on tty, which obviously will not suite |
142 | GUI applications). */ | 142 | GUI applications). */ |
143 | _mu_smtp_fixup_params (smtp); | 143 | _mu_smtp_fixup_params (smtp); |
144 | if (!smtp->param[MU_SMTP_PARAM_USERNAME] && !smtp->secret) | ||
145 | return MU_ERR_AUTH_NO_CRED; | ||
144 | #if defined(WITH_GSASL) | 146 | #if defined(WITH_GSASL) |
145 | return _mu_smtp_gsasl_auth (smtp); | 147 | return _mu_smtp_gsasl_auth (smtp); |
146 | #else | 148 | #else | ... | ... |
... | @@ -308,9 +308,10 @@ fill_body (mu_message_t msg, FILE *file) | ... | @@ -308,9 +308,10 @@ fill_body (mu_message_t msg, FILE *file) |
308 | mu_stream_t stream = NULL; | 308 | mu_stream_t stream = NULL; |
309 | char *buf = NULL; | 309 | char *buf = NULL; |
310 | size_t n = 0; | 310 | size_t n = 0; |
311 | int nullbody = 1; | ||
312 | |||
311 | mu_message_get_body (msg, &body); | 313 | mu_message_get_body (msg, &body); |
312 | mu_body_get_streamref (body, &stream); | 314 | mu_body_get_streamref (body, &stream); |
313 | int nullbody = 1; | ||
314 | 315 | ||
315 | while (getline (&buf, &n, file) >= 0) | 316 | while (getline (&buf, &n, file) >= 0) |
316 | { | 317 | { |
... | @@ -651,7 +652,11 @@ mail_send0 (compose_env_t * env, int save_to) | ... | @@ -651,7 +652,11 @@ mail_send0 (compose_env_t * env, int save_to) |
651 | env->header = NULL; | 652 | env->header = NULL; |
652 | status = send_message (msg); | 653 | status = send_message (msg); |
653 | if (status) | 654 | if (status) |
654 | save_dead_message (env); | 655 | { |
656 | mu_error (_("cannot send message: %s"), | ||
657 | mu_strerror (status)); | ||
658 | save_dead_message (env); | ||
659 | } | ||
655 | } | 660 | } |
656 | } | 661 | } |
657 | fclose (env->file); | 662 | fclose (env->file); | ... | ... |
-
Please register or sign in to post a comment