Commit 5b1a5402 5b1a5402662d6685f0216a528c1c19536a7d421a by Sergey Poznyakoff

Bugfixes.

* imap4d/bye.c: Discern between input and output errors.
* imap4d/imap4d.h (ERR_NO_IFILE): New error code.
* imap4d/util.c: Discern between input and output errors.
Improve trace output.
(imap4d_getline): Signal ERR_NO_IFILE on EOF.
* movemail/movemail.c: Fix include statements.
1 parent fef67bbd
......@@ -65,7 +65,12 @@ imap4d_bye0 (int reason, struct imap4d_command *command)
case ERR_NO_OFILE:
status = EX_IOERR;
mu_diag_output (MU_DIAG_INFO, _("No socket to send to"));
mu_diag_output (MU_DIAG_INFO, _("Write error on control stream"));
break;
case ERR_NO_IFILE:
status = EX_IOERR;
mu_diag_output (MU_DIAG_INFO, _("Read error on control stream"));
break;
case ERR_MAILBOX_CORRUPTED:
......
......@@ -145,11 +145,12 @@ struct imap4d_command
#define OK 0
#define ERR_NO_MEM 1
#define ERR_NO_OFILE 2
#define ERR_TIMEOUT 3
#define ERR_SIGNAL 4
#define ERR_TLS 5
#define ERR_MAILBOX_CORRUPTED 6
#define ERR_TERMINATE 7
#define ERR_NO_IFILE 3
#define ERR_TIMEOUT 4
#define ERR_SIGNAL 5
#define ERR_TLS 6
#define ERR_MAILBOX_CORRUPTED 7
#define ERR_TERMINATE 8
/* Namespace numbers */
#define NS_PRIVATE 0
......
......@@ -340,7 +340,10 @@ util_out (int rc, const char *format, ...)
imap4d_bye (ERR_NO_MEM);
if (imap4d_transcript)
mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf);
{
int len = strcspn (buf, "\r\n");
mu_diag_output (MU_DIAG_DEBUG, "sent: %*.*s", len, len, buf);
}
status = mu_stream_sequential_write (ostream, buf, strlen (buf));
free (buf);
......@@ -381,7 +384,7 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...)
free (tempbuf);
if (imap4d_transcript)
mu_diag_output (MU_DIAG_DEBUG, "sent: %s\r\n", buf);
mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf);
mu_stream_sequential_write (ostream, buf, strlen (buf));
free (buf);
......@@ -882,13 +885,16 @@ util_uidvalidity (mu_mailbox_t smbox, unsigned long *uidvp)
void
util_setio (FILE *in, FILE *out)
{
if (!out || !in)
if (!in)
imap4d_bye (ERR_NO_IFILE);
if (!out)
imap4d_bye (ERR_NO_OFILE);
setvbuf (in, NULL, _IOLBF, 0);
setvbuf (out, NULL, _IOLBF, 0);
if (mu_stdio_stream_create (&istream, in, MU_STREAM_NO_CLOSE)
|| mu_stdio_stream_create (&ostream, out, MU_STREAM_NO_CLOSE))
if (mu_stdio_stream_create (&istream, in, MU_STREAM_NO_CLOSE))
imap4d_bye (ERR_NO_IFILE);
if (mu_stdio_stream_create (&ostream, out, MU_STREAM_NO_CLOSE))
imap4d_bye (ERR_NO_OFILE);
}
......@@ -1312,12 +1318,12 @@ check_input_err (int rc, size_t sz)
mu_diag_output (MU_DIAG_INFO,
_("Error reading from input file: %s"), p);
imap4d_bye (ERR_NO_OFILE);
imap4d_bye (ERR_NO_IFILE);
}
else if (sz == 0)
{
mu_diag_output (MU_DIAG_INFO, _("Unexpected eof on input"));
imap4d_bye (ERR_NO_OFILE);
imap4d_bye (ERR_NO_IFILE);
}
}
......@@ -1358,10 +1364,30 @@ imap4d_readline (struct imap4d_tokbuf *tok)
char *last_arg;
size_t off = imap4d_tokbuf_getline (tok);
if (transcript)
mu_diag_output (MU_DIAG_DEBUG, "recv: %s", tok->buffer);
{
int len;
char *p = strcasestr (tok->buffer, "LOGIN");
if (p && p > tok->buffer && isspace(p[-1]))
{
char *q = p + 5;
while (*q && isspace (*q))
q++;
while (*q && !isspace (*q))
q++;
len = q - tok->buffer;
mu_diag_output (MU_DIAG_DEBUG, "recv: %*.*s {censored}", len, len,
tok->buffer);
}
else
{
len = strcspn (tok->buffer, "\r\n");
mu_diag_output (MU_DIAG_DEBUG, "recv: %*.*s",
len, len, tok->buffer);
}
}
imap4d_tokbuf_tokenize (tok, off);
if (tok->argc == 0)
break;
break;
last_arg = tok->buffer + tok->argp[tok->argc - 1];
if (last_arg[0] == '{' && last_arg[strlen(last_arg)-1] == '}')
{
......@@ -1439,7 +1465,17 @@ imap4d_getline (char **pbuf, size_t *psize, size_t *pnbytes)
char *s = *pbuf;
len = util_trim_nl (s, len);
if (imap4d_transcript)
mu_diag_output (MU_DIAG_DEBUG, "recv: %s", s);
{
if (len)
mu_diag_output (MU_DIAG_DEBUG, "recv: %s", s);
else
mu_diag_output (MU_DIAG_DEBUG, "got EOF");
}
if (len == 0)
{
imap4d_bye (ERR_NO_IFILE);
/*FIXME rc = ECONNABORTED;*/
}
if (pnbytes)
*pnbytes = len;
}
......
......@@ -29,7 +29,7 @@
#include <mailutils/tls.h>
#include <mu_asprintf.h>
#include "mailutils/libargp.h"
#include <lib/muaux.h>
#include <muaux.h>
const char *program_version = "movemail (" PACKAGE_STRING ")";
static char doc[] = N_("GNU movemail");
......