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) ...@@ -65,7 +65,12 @@ imap4d_bye0 (int reason, struct imap4d_command *command)
65 65
66 case ERR_NO_OFILE: 66 case ERR_NO_OFILE:
67 status = EX_IOERR; 67 status = EX_IOERR;
68 mu_diag_output (MU_DIAG_INFO, _("No socket to send to")); 68 mu_diag_output (MU_DIAG_INFO, _("Write error on control stream"));
69 break;
70
71 case ERR_NO_IFILE:
72 status = EX_IOERR;
73 mu_diag_output (MU_DIAG_INFO, _("Read error on control stream"));
69 break; 74 break;
70 75
71 case ERR_MAILBOX_CORRUPTED: 76 case ERR_MAILBOX_CORRUPTED:
......
...@@ -145,11 +145,12 @@ struct imap4d_command ...@@ -145,11 +145,12 @@ struct imap4d_command
145 #define OK 0 145 #define OK 0
146 #define ERR_NO_MEM 1 146 #define ERR_NO_MEM 1
147 #define ERR_NO_OFILE 2 147 #define ERR_NO_OFILE 2
148 #define ERR_TIMEOUT 3 148 #define ERR_NO_IFILE 3
149 #define ERR_SIGNAL 4 149 #define ERR_TIMEOUT 4
150 #define ERR_TLS 5 150 #define ERR_SIGNAL 5
151 #define ERR_MAILBOX_CORRUPTED 6 151 #define ERR_TLS 6
152 #define ERR_TERMINATE 7 152 #define ERR_MAILBOX_CORRUPTED 7
153 #define ERR_TERMINATE 8
153 154
154 /* Namespace numbers */ 155 /* Namespace numbers */
155 #define NS_PRIVATE 0 156 #define NS_PRIVATE 0
......
...@@ -340,7 +340,10 @@ util_out (int rc, const char *format, ...) ...@@ -340,7 +340,10 @@ util_out (int rc, const char *format, ...)
340 imap4d_bye (ERR_NO_MEM); 340 imap4d_bye (ERR_NO_MEM);
341 341
342 if (imap4d_transcript) 342 if (imap4d_transcript)
343 mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf); 343 {
344 int len = strcspn (buf, "\r\n");
345 mu_diag_output (MU_DIAG_DEBUG, "sent: %*.*s", len, len, buf);
346 }
344 347
345 status = mu_stream_sequential_write (ostream, buf, strlen (buf)); 348 status = mu_stream_sequential_write (ostream, buf, strlen (buf));
346 free (buf); 349 free (buf);
...@@ -381,7 +384,7 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...) ...@@ -381,7 +384,7 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...)
381 free (tempbuf); 384 free (tempbuf);
382 385
383 if (imap4d_transcript) 386 if (imap4d_transcript)
384 mu_diag_output (MU_DIAG_DEBUG, "sent: %s\r\n", buf); 387 mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf);
385 388
386 mu_stream_sequential_write (ostream, buf, strlen (buf)); 389 mu_stream_sequential_write (ostream, buf, strlen (buf));
387 free (buf); 390 free (buf);
...@@ -882,13 +885,16 @@ util_uidvalidity (mu_mailbox_t smbox, unsigned long *uidvp) ...@@ -882,13 +885,16 @@ util_uidvalidity (mu_mailbox_t smbox, unsigned long *uidvp)
882 void 885 void
883 util_setio (FILE *in, FILE *out) 886 util_setio (FILE *in, FILE *out)
884 { 887 {
885 if (!out || !in) 888 if (!in)
889 imap4d_bye (ERR_NO_IFILE);
890 if (!out)
886 imap4d_bye (ERR_NO_OFILE); 891 imap4d_bye (ERR_NO_OFILE);
887 892
888 setvbuf (in, NULL, _IOLBF, 0); 893 setvbuf (in, NULL, _IOLBF, 0);
889 setvbuf (out, NULL, _IOLBF, 0); 894 setvbuf (out, NULL, _IOLBF, 0);
890 if (mu_stdio_stream_create (&istream, in, MU_STREAM_NO_CLOSE) 895 if (mu_stdio_stream_create (&istream, in, MU_STREAM_NO_CLOSE))
891 || mu_stdio_stream_create (&ostream, out, MU_STREAM_NO_CLOSE)) 896 imap4d_bye (ERR_NO_IFILE);
897 if (mu_stdio_stream_create (&ostream, out, MU_STREAM_NO_CLOSE))
892 imap4d_bye (ERR_NO_OFILE); 898 imap4d_bye (ERR_NO_OFILE);
893 } 899 }
894 900
...@@ -1312,12 +1318,12 @@ check_input_err (int rc, size_t sz) ...@@ -1312,12 +1318,12 @@ check_input_err (int rc, size_t sz)
1312 1318
1313 mu_diag_output (MU_DIAG_INFO, 1319 mu_diag_output (MU_DIAG_INFO,
1314 _("Error reading from input file: %s"), p); 1320 _("Error reading from input file: %s"), p);
1315 imap4d_bye (ERR_NO_OFILE); 1321 imap4d_bye (ERR_NO_IFILE);
1316 } 1322 }
1317 else if (sz == 0) 1323 else if (sz == 0)
1318 { 1324 {
1319 mu_diag_output (MU_DIAG_INFO, _("Unexpected eof on input")); 1325 mu_diag_output (MU_DIAG_INFO, _("Unexpected eof on input"));
1320 imap4d_bye (ERR_NO_OFILE); 1326 imap4d_bye (ERR_NO_IFILE);
1321 } 1327 }
1322 } 1328 }
1323 1329
...@@ -1358,10 +1364,30 @@ imap4d_readline (struct imap4d_tokbuf *tok) ...@@ -1358,10 +1364,30 @@ imap4d_readline (struct imap4d_tokbuf *tok)
1358 char *last_arg; 1364 char *last_arg;
1359 size_t off = imap4d_tokbuf_getline (tok); 1365 size_t off = imap4d_tokbuf_getline (tok);
1360 if (transcript) 1366 if (transcript)
1361 mu_diag_output (MU_DIAG_DEBUG, "recv: %s", tok->buffer); 1367 {
1368 int len;
1369 char *p = strcasestr (tok->buffer, "LOGIN");
1370 if (p && p > tok->buffer && isspace(p[-1]))
1371 {
1372 char *q = p + 5;
1373 while (*q && isspace (*q))
1374 q++;
1375 while (*q && !isspace (*q))
1376 q++;
1377 len = q - tok->buffer;
1378 mu_diag_output (MU_DIAG_DEBUG, "recv: %*.*s {censored}", len, len,
1379 tok->buffer);
1380 }
1381 else
1382 {
1383 len = strcspn (tok->buffer, "\r\n");
1384 mu_diag_output (MU_DIAG_DEBUG, "recv: %*.*s",
1385 len, len, tok->buffer);
1386 }
1387 }
1362 imap4d_tokbuf_tokenize (tok, off); 1388 imap4d_tokbuf_tokenize (tok, off);
1363 if (tok->argc == 0) 1389 if (tok->argc == 0)
1364 break; 1390 break;
1365 last_arg = tok->buffer + tok->argp[tok->argc - 1]; 1391 last_arg = tok->buffer + tok->argp[tok->argc - 1];
1366 if (last_arg[0] == '{' && last_arg[strlen(last_arg)-1] == '}') 1392 if (last_arg[0] == '{' && last_arg[strlen(last_arg)-1] == '}')
1367 { 1393 {
...@@ -1439,7 +1465,17 @@ imap4d_getline (char **pbuf, size_t *psize, size_t *pnbytes) ...@@ -1439,7 +1465,17 @@ imap4d_getline (char **pbuf, size_t *psize, size_t *pnbytes)
1439 char *s = *pbuf; 1465 char *s = *pbuf;
1440 len = util_trim_nl (s, len); 1466 len = util_trim_nl (s, len);
1441 if (imap4d_transcript) 1467 if (imap4d_transcript)
1442 mu_diag_output (MU_DIAG_DEBUG, "recv: %s", s); 1468 {
1469 if (len)
1470 mu_diag_output (MU_DIAG_DEBUG, "recv: %s", s);
1471 else
1472 mu_diag_output (MU_DIAG_DEBUG, "got EOF");
1473 }
1474 if (len == 0)
1475 {
1476 imap4d_bye (ERR_NO_IFILE);
1477 /*FIXME rc = ECONNABORTED;*/
1478 }
1443 if (pnbytes) 1479 if (pnbytes)
1444 *pnbytes = len; 1480 *pnbytes = len;
1445 } 1481 }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
29 #include <mailutils/tls.h> 29 #include <mailutils/tls.h>
30 #include <mu_asprintf.h> 30 #include <mu_asprintf.h>
31 #include "mailutils/libargp.h" 31 #include "mailutils/libargp.h"
32 #include <lib/muaux.h> 32 #include <muaux.h>
33 33
34 const char *program_version = "movemail (" PACKAGE_STRING ")"; 34 const char *program_version = "movemail (" PACKAGE_STRING ")";
35 static char doc[] = N_("GNU movemail"); 35 static char doc[] = N_("GNU movemail");
......