From: Eric S. Raymond Date: Thu, 30 Jan 1997 17:29:36 +0000 (-0000) Subject: Add stripcr option. X-Git-Url: http://pileus.org/git/?a=commitdiff_plain;h=65179f921d37756ed89e1ef7965e13bd5f319650;p=~andy%2Ffetchmail Add stripcr option. svn path=/trunk/; revision=842 --- diff --git a/NEWS b/NEWS index db980a96..e78160a4 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,9 @@ fetchmail-3.3 () features -- +* Whether or not carriage returns will be stripped on output is explicitly + controllable with stripcr. + bugs -- * Correction to length-extraction code for servers that return (nnn octets). diff --git a/README b/README index 8c7688e7..3947f9c1 100644 --- a/README +++ b/README @@ -21,6 +21,9 @@ Since 3.0: ** Support for ESMTP 8BITMIME and SIZE options. + ** The stripcr option to explicitly control carriage-return + stripping before mail forwarding. + Since 2.0: ** Support for secure use with ssh. diff --git a/driver.c b/driver.c index d11d8c2a..aad43332 100644 --- a/driver.c +++ b/driver.c @@ -765,19 +765,22 @@ char *realname; /* real name of host */ } /* write all the headers */ - if (sinkfp) + if (ctl->stripcr) { - if (ctl->mda) - { - char *sp, *tp; + char *sp, *tp; - for (sp = tp = headers; *sp; sp++) - if (*sp != '\r') - *tp++ = *sp; - *tp = '\0'; + for (sp = tp = headers; *sp; sp++) + if (*sp != '\r') + *tp++ = *sp; + *tp = '\0'; + } + + /* write all the headers */ + if (sinkfp) + { + if (ctl->mda) n = fwrite(headers, 1, strlen(headers), sinkfp); - } else n = SockWrite(headers, 1, strlen(headers), sinkfp); @@ -842,18 +845,20 @@ char *realname; /* real name of host */ strcat(errmsg, "\n"); /* ship out the error line */ + if (ctl->stripcr) + { + char *sp, *tp; + + for (sp = tp = errmsg; *sp; sp++) + if (*sp != '\r') + *tp++ = *sp; + *tp = '\0'; + } + if (sinkfp) { if (ctl->mda) - { - char *sp, *tp; - - for (sp = tp = errmsg; *sp; sp++) - if (*sp != '\r') - *tp++ = *sp; - *tp = '\0'; fwrite(errmsg, 1, strlen(errmsg), sinkfp); - } else SockWrite(errmsg, 1, strlen(errmsg), sinkfp); } @@ -909,7 +914,7 @@ char *realname; /* real name of host */ else SockWrite(buf, 1, 1, sinkfp); - if (ctl->mda) + if (ctl->stripcr) { char *sp, *tp; @@ -917,9 +922,10 @@ char *realname; /* real name of host */ if (*sp != '\r') *tp++ = *sp; *tp = '\0'; + } + if (ctl->mda) n = fwrite(buf, 1, strlen(buf), sinkfp); - } else if (sinkfp) n = SockWrite(buf, 1, strlen(buf), sinkfp); diff --git a/fetchmail.c b/fetchmail.c index 75d9e542..47fcfe72 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -630,6 +630,10 @@ static int load_params(int argc, char **argv, int optind) ctl->server.lead_server = &(ctl->server); no_new_server:; + /* if stripcr hasn't been set, default it asccording to MDA */ + if (ctl->stripcr == -1) + ctl->stripcr = !ctl->mda; + /* plug in the semi-standard way of indicating a mail address */ if (ctl->server.envelope == (char *)NULL) ctl->server.envelope = "X-Envelope-To:"; @@ -826,6 +830,9 @@ void dump_params (struct query *ctl) printf(" Rewrite of server-local addresses is %sabled (--norewrite %s).\n", ctl->no_rewrite ? "dis" : "en", ctl->no_rewrite ? "on" : "off"); + printf(" Carriage-return stripping is %sabled (--stripcr %s).\n", + ctl->stripcr ? "en" : "dis", + ctl->stripcr ? "on" : "off"); if (ctl->limit) printf(" Message size limit is %d bytes (--limit %d).\n", ctl->limit, ctl->limit); diff --git a/fetchmail.h b/fetchmail.h index 18bfbe1f..4f974b45 100644 --- a/fetchmail.h +++ b/fetchmail.h @@ -106,6 +106,7 @@ struct query int fetchall; int flush; int no_rewrite; + int stripcr; int limit; int fetchlimit; int batchlimit; diff --git a/fetchmail.man b/fetchmail.man index 11081032..24495d98 100644 --- a/fetchmail.man +++ b/fetchmail.man @@ -594,7 +594,7 @@ Legal user options are .PP All options correspond to the obvious command-line arguments except the following: `aka', `is', `to', `dns'/`no dns', `password', -`preconnect', and `localdomains'. +`preconnect', `localdomains', and `stripcr'. .PP The `is' or `to' keywords associate the following local (client) name(s) (or server-name to client-name mappings separated by =) with @@ -651,6 +651,12 @@ establishes a mailserver connection. This may be useful if you are attempting to set up secure POP connections with the aid of .IR ssh (1). .PP +The `stripcr' option controls whether carriage returns are stripped +out of retrieved mail before it is forwarded. It is normally not +necessary to set this, because it defaults to `on' (CR stripping +enabled) when there is an MDA declared but `off' (CR stripping +disabled) when forwarding is via SMTP. +.PP Legal protocol identifiers are auto (or AUTO) diff --git a/rcfile_l.l b/rcfile_l.l index 8156fd6a..059b07c2 100644 --- a/rcfile_l.l +++ b/rcfile_l.l @@ -59,18 +59,14 @@ keep { yylval.flag = FLAG_TRUE; return KEEP; } flush { yylval.flag = FLAG_TRUE; return FLUSH; } fetchall { yylval.flag = FLAG_TRUE; return FETCHALL; } rewrite { yylval.flag = FLAG_TRUE; return REWRITE; } +stripcr { yylval.flag = FLAG_TRUE; return STRIPCR; } dns { yylval.flag = FLAG_TRUE; return DNS; } -nokeep { yylval.flag = FLAG_FALSE; return KEEP; } -noflush { yylval.flag = FLAG_FALSE; return FLUSH; } -nofetchall { yylval.flag = FLAG_FALSE; return FETCHALL; } -norewrite { yylval.flag = FLAG_FALSE; return REWRITE; } -nodns { yylval.flag = FLAG_FALSE; return DNS; } - no{WS}keep { yylval.flag = FLAG_FALSE; return KEEP; } no{WS}flush { yylval.flag = FLAG_FALSE; return FLUSH; } no{WS}fetchall { yylval.flag = FLAG_FALSE; return FETCHALL; } no{WS}rewrite { yylval.flag = FLAG_FALSE; return REWRITE; } +no{WS}stripcr { yylval.flag = FLAG_FALSE; return REWRITE; } no{WS}dns { yylval.flag = FLAG_FALSE; return DNS; } limit { return LIMIT; } diff --git a/rcfile_y.y b/rcfile_y.y index dfc3dbdd..e9a381b0 100644 --- a/rcfile_y.y +++ b/rcfile_y.y @@ -49,7 +49,7 @@ static void prc_reset(); %token PROTO %token STRING %token NUMBER -%token KEEP FLUSH FETCHALL REWRITE DNS PORT +%token KEEP FLUSH FETCHALL REWRITE STRIPCR DNS PORT /* these are actually used by the lexer */ %token FLAG_TRUE 2 @@ -76,7 +76,10 @@ statement : SET LOGFILE MAP STRING {logfile = xstrdup($4);} */ | define_server serverspecs {prc_register(); prc_reset();} | define_server serverspecs userspecs - {memset(¤t,'\0',sizeof(current));} + { + memset(¤t,'\0',sizeof(current)); + current.stripcr = -1; + } ; define_server : POLL STRING {current.server.names = (struct idlist *)NULL; @@ -192,6 +195,7 @@ user_option : TO localnames HERE | FLUSH {current.flush = ($1==FLAG_TRUE);} | FETCHALL {current.fetchall = ($1==FLAG_TRUE);} | REWRITE {current.no_rewrite =($1==FLAG_FALSE);} + | STRIPCR {current.stripcr = ($1==FLAG_TRUE);} | LIMIT NUMBER {current.limit = $2;} | FETCHLIMIT NUMBER {current.fetchlimit = $2;} | BATCHLIMIT NUMBER {current.batchlimit = $2;}