Commit 3c21c658 3c21c6583253be9edfd9e4c1e1fc6c07726be499 by Sergey Poznyakoff

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.
1 parent 5984fc0c
......@@ -162,7 +162,8 @@ git-describe:
test -n "$$dirty" && dirty="-dirty"; \
descr=`git describe`; \
echo $${descr}$$dirty > git-describe.tmp; \
test -f git-describe && cmp git-describe.tmp git-describe || \
test -f git-describe && \
cmp git-describe.tmp git-describe >/dev/null || \
cp git-describe.tmp git-describe; \
rm git-describe.tmp; \
fi
......@@ -183,7 +184,8 @@ git-describe.h: git-describe
else \
echo "/* No git tag */"; \
fi > git-describe.h.tmp; \
test -f git-describe.h && cmp git-describe.h.tmp git-describe.h || \
test -f git-describe.h && \
cmp git-describe.h.tmp git-describe.h >/dev/null || \
cp git-describe.h.tmp git-describe.h; \
rm git-describe.h.tmp
......
......@@ -183,6 +183,7 @@ _body_get_stream (mu_body_t body, mu_stream_t *pstream, int ref)
body->filename, MU_STREAM_RDWR);
if (status != 0)
return status;
mu_stream_set_buffer (body->fstream, mu_buffer_full, 0);
status = mu_stream_open (body->fstream);
if (status != 0)
return status;
......
......@@ -93,3 +93,4 @@ MU_ERR_BAD_FILENAME _("Badly formed file or directory name")
MU_ERR_READ _("Read error")
MU_ERR_NO_TRANSPORT _("Transport stream not set")
MU_ERR_AUTH_NO_CRED _("No credentials supplied")
......
......@@ -124,9 +124,11 @@ smtp_open (mu_mailer_t mailer, int flags)
if (mu_debug_check_level (mailer->debug, MU_DEBUG_PROT))
mu_smtp_trace (smtp_mailer->smtp, MU_SMTP_TRACE_SET);
if (mu_debug_check_level (mailer->debug, MU_DEBUG_TRACE6))
mu_smtp_trace_mask (smtp_mailer->smtp, MU_SMTP_TRACE_SET, MU_XSCRIPT_SECURE);
mu_smtp_trace_mask (smtp_mailer->smtp, MU_SMTP_TRACE_SET,
MU_XSCRIPT_SECURE);
if (mu_debug_check_level (mailer->debug, MU_DEBUG_TRACE7))
mu_smtp_trace_mask (smtp_mailer->smtp, MU_SMTP_TRACE_SET, MU_XSCRIPT_PAYLOAD);
mu_smtp_trace_mask (smtp_mailer->smtp, MU_SMTP_TRACE_SET,
MU_XSCRIPT_PAYLOAD);
mu_smtp_set_param (smtp_mailer->smtp, MU_SMTP_PARAM_URL,
mu_url_to_string (mailer->url));
......@@ -203,9 +205,19 @@ smtp_open (mu_mailer_t mailer, int flags)
if (!noauth && mu_smtp_capa_test (smtp_mailer->smtp, "AUTH", NULL) == 0)
{
rc = mu_smtp_auth (smtp_mailer->smtp);
if (rc)
return rc;
rc = mu_smtp_ehlo (smtp_mailer->smtp);
switch (rc)
{
case 0:
rc = mu_smtp_ehlo (smtp_mailer->smtp);
break;
case ENOSYS:
case MU_ERR_AUTH_NO_CRED:
mu_diag_output (MU_DIAG_NOTICE, "authentication disabled: %s",
mu_strerror (rc));
rc = 0; /* Continue anyway */
break;
}
if (rc)
return rc;
}
......@@ -377,7 +389,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t msg,
mu_smtp_t smtp = smp->smtp;
int status;
size_t size, lines, count;
const char *mail_from;
const char *mail_from, *size_str;
mu_header_t header;
if (mailer == NULL)
......@@ -398,12 +410,19 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t msg,
if (status)
return status;
if (mu_smtp_capa_test (smp->smtp, "SIZE", NULL) == 0 &&
if (mu_smtp_capa_test (smp->smtp, "SIZE", &size_str) == 0 &&
mu_message_size (msg, &size) == 0 &&
mu_message_lines (msg, &lines) == 0)
status = mu_smtp_mail_basic (smp->smtp, mail_from,
"SIZE=%lu",
(unsigned long) (size + lines));
{
size_t msgsize = size + lines;
size_t maxsize = strtoul (size_str + 5, NULL, 10);
if (msgsize && msgsize > maxsize)
return EFBIG;
status = mu_smtp_mail_basic (smp->smtp, mail_from,
"SIZE=%lu",
(unsigned long) msgsize);
}
else
status = mu_smtp_mail_basic (smp->smtp, mail_from, NULL);
if (status)
......
......@@ -141,6 +141,8 @@ mu_smtp_auth (mu_smtp_t smtp)
default it does that on tty, which obviously will not suite
GUI applications). */
_mu_smtp_fixup_params (smtp);
if (!smtp->param[MU_SMTP_PARAM_USERNAME] && !smtp->secret)
return MU_ERR_AUTH_NO_CRED;
#if defined(WITH_GSASL)
return _mu_smtp_gsasl_auth (smtp);
#else
......
......@@ -308,9 +308,10 @@ fill_body (mu_message_t msg, FILE *file)
mu_stream_t stream = NULL;
char *buf = NULL;
size_t n = 0;
int nullbody = 1;
mu_message_get_body (msg, &body);
mu_body_get_streamref (body, &stream);
int nullbody = 1;
while (getline (&buf, &n, file) >= 0)
{
......@@ -651,7 +652,11 @@ mail_send0 (compose_env_t * env, int save_to)
env->header = NULL;
status = send_message (msg);
if (status)
save_dead_message (env);
{
mu_error (_("cannot send message: %s"),
mu_strerror (status));
save_dead_message (env);
}
}
}
fclose (env->file);
......