From 60e6d78753d7cba662a3eee29c05d5b4d52e4551 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 27 Jan 1997 02:13:33 +0000 Subject: CR-strip fix. svn path=/trunk/; revision=833 --- NEWS | 6 ++++ driver.c | 120 +++++++++++++++++++++++++++++++++++++++++---------------------- imap.c | 3 ++ 3 files changed, 88 insertions(+), 41 deletions(-) diff --git a/NEWS b/NEWS index 234a54ad..c2ee5c5c 100644 --- a/NEWS +++ b/NEWS @@ -3,12 +3,18 @@ ------------------------------------------------------------------------------ fetchmail-3.2 () +features -- + +* Better error notification on IMAP select failure. + bugs -- * The code can now handle arbitrarily long address lists. * Fix RFC822 parsing to strip comments at end of bare addresses. +* Explicitly strip CRs out of fetched mail. + ------------------------------------------------------------------------------ fetchmail-3.1 (Fri Jan 24 12:45:18 EST 1997) diff --git a/driver.c b/driver.c index 35bb3e8c..1761275c 100644 --- a/driver.c +++ b/driver.c @@ -763,25 +763,37 @@ char *realname; /* real name of host */ } /* write all the headers */ - if (ctl->mda) - n = fwrite(headers, 1, oldlen, sinkfp); - else if (sinkfp) - n = SockWrite(headers, 1, oldlen, sinkfp); - - if (n < 0) + if (sinkfp) { - free(headers); - headers = NULL; - error(0, errno, "writing RFC822 headers"); if (ctl->mda) { - pclose(sinkfp); - signal(SIGCHLD, sigchld); + char *sp, *tp; + + for (sp = tp = headers; *sp; sp++) + if (*sp != '\r') + *tp++ = *sp; + *tp = '\0'; + + n = fwrite(headers, 1, oldlen, sinkfp); } - return(PS_IOERR); + else + n = SockWrite(headers, 1, oldlen, sinkfp); + + if (n < 0) + { + free(headers); + headers = NULL; + error(0, errno, "writing RFC822 headers"); + if (ctl->mda) + { + pclose(sinkfp); + signal(SIGCHLD, sigchld); + } + return(PS_IOERR); + } + else if (outlevel == O_VERBOSE) + fputs("#", stderr); } - else if (outlevel == O_VERBOSE) - fputs("#", stderr); free(headers); headers = NULL; @@ -828,19 +840,33 @@ char *realname; /* real name of host */ strcat(errmsg, "\n"); /* ship out the error line */ - if (ctl->mda) - fwrite(errmsg, 1, strlen(errmsg), sinkfp); - else if (sinkfp) - SockWrite(errmsg, 1, strlen(errmsg), sinkfp); + if (sinkfp) + { + if (ctl->mda) + { + char *sp, *tp; + + for (sp = tp = headers; *sp; sp++) + if (*sp != '\r') + *tp++ = *sp; + *tp = '\0'; + fwrite(errmsg, 1, strlen(errmsg), sinkfp); + } + else + SockWrite(errmsg, 1, strlen(errmsg), sinkfp); + } } free_str_list(&xmit_names); /* issue the delimiter line */ - if (ctl->mda) - fputs("\r\n", sinkfp); - else if (sinkfp) - SockWrite("\r\n", 1, 2, sinkfp); + if (sinkfp) + { + if (ctl->mda) + fputc('\n', sinkfp); + else + SockWrite("\r\n", 1, 2, sinkfp); + } /* * Body processing starts here @@ -871,31 +897,43 @@ char *realname; /* real name of host */ if (buf[1] == '\r' && buf[2] == '\n') break; - /* SMTP byte-stuffing */ - if (*buf == '.') - if (ctl->mda) - fputs(".", sinkfp); - else if (sinkfp) - SockWrite(buf, 1, 1, sinkfp); - /* ship out the text line */ - if (ctl->mda) - n = fwrite(buf, 1, strlen(buf), sinkfp); - else if (sinkfp) - n = SockWrite(buf, 1, strlen(buf), sinkfp); - - if (n < 0) + if (sinkfp) { - error(0, errno, "writing message text"); + /* SMTP byte-stuffing */ + if (*buf == '.') + if (ctl->mda) + fputs(".", sinkfp); + else + SockWrite(buf, 1, 1, sinkfp); + if (ctl->mda) { - pclose(sinkfp); - signal(SIGCHLD, sigchld); + char *sp, *tp; + + for (sp = tp = headers; *sp; sp++) + if (*sp != '\r') + *tp++ = *sp; + *tp = '\0'; + + n = fwrite(buf, 1, strlen(buf), sinkfp); } - return(PS_IOERR); + else if (sinkfp) + n = SockWrite(buf, 1, strlen(buf), sinkfp); + + if (n < 0) + { + error(0, errno, "writing message text"); + if (ctl->mda) + { + pclose(sinkfp); + signal(SIGCHLD, sigchld); + } + return(PS_IOERR); + } + else if (outlevel == O_VERBOSE) + fputc('*', stderr); } - else if (outlevel == O_VERBOSE) - fputc('*', stderr); } /* diff --git a/imap.c b/imap.c index 4e5122fa..f6a68ea9 100644 --- a/imap.c +++ b/imap.c @@ -128,7 +128,10 @@ static int imap_getrange(FILE *sockfp, struct query *ctl, int*countp, int*newp) "SELECT %s", ctl->mailbox ? ctl->mailbox : "INBOX"); if (ok != 0) + { + error(0, 0, "mailbox selection failed"); return(ok); + } *countp = count; -- cgit v1.2.3