aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--driver.c109
-rw-r--r--fetchmail.c4
-rw-r--r--fetchmail.h2
-rw-r--r--options.c4
4 files changed, 87 insertions, 32 deletions
diff --git a/driver.c b/driver.c
index 02994f00..cce53fe5 100644
--- a/driver.c
+++ b/driver.c
@@ -152,7 +152,7 @@ struct method *proto;
ok = gen_readmsg(socket,mboxfd,len,protocol->delimited,
queryctl->servername,
queryctl->output,
- queryctl->rewrite);
+ !queryctl->norewrite);
if (protocol->trail)
(*protocol->trail)(socket, queryctl, number);
if (ok != 0)
@@ -328,11 +328,9 @@ int output;
int rewrite;
{
char buf [MSGBUFSIZE];
- char *bufp;
- char savec;
char fromBuf[MSGBUFSIZE];
- int n;
- int needFrom;
+ char *bufp, *headers, *unixfrom, *fromhdr, *tohdr, *cchdr, *bcchdr;
+ int n, oldlen;
int inheaders;
int lines,sizeticker;
time_t now;
@@ -349,6 +347,7 @@ int rewrite;
/* read the message content from the server */
inheaders = 1;
+ headers = unixfrom = fromhdr = tohdr = cchdr = bcchdr = NULL;
lines = 0;
sizeticker = MSGBUFSIZE;
while (delimited || len > 0) {
@@ -356,7 +355,7 @@ int rewrite;
return(PS_SOCKET);
len -= n;
bufp = buf;
- if (buf[0] == '\r' || buf[0] == '\n')
+ if (buf[0] == '\0' || buf[0] == '\r' || buf[0] == '\n')
inheaders = 0;
if (*bufp == '.') {
bufp++;
@@ -365,44 +364,96 @@ int rewrite;
}
strcat(bufp,"\n");
- /* Check for Unix 'From' header, and add a bogus one if it's not
- present -- only if not using an MDA.
- XXX -- should probably parse real From: header and use its
- address field instead of bogus 'POPmail' string.
- */
- if (output != TO_MDA && lines == 0) {
- if (strlen(bufp) >= strlen("From ")) {
- savec = *(bufp + 5);
- *(bufp + 5) = 0;
- needFrom = strcmp(bufp,"From ") != 0;
- *(bufp + 5) = savec;
+ if (inheaders)
+ {
+ if (rewrite)
+ reply_hack(bufp, pophost);
+
+ if (!lines)
+ {
+ oldlen = strlen(bufp);
+ headers = malloc(oldlen + 1);
+ if (headers == NULL)
+ return(PS_IOERR);
+ (void) strcpy(headers, bufp);
+ bufp = headers;
}
else
- needFrom = 1;
- if (needFrom) {
- now = time(NULL);
- sprintf(fromBuf,"From POPmail %s",ctime(&now));
+ {
+ int newlen = oldlen + strlen(bufp);
+
+ headers = realloc(headers, newlen + 1);
+ if (headers == NULL)
+ return(PS_IOERR);
+ strcpy(headers + oldlen, bufp);
+ bufp = headers + oldlen;
+ oldlen = newlen;
+ }
+
+ if (!strncmp(bufp,"From ",5))
+ unixfrom = bufp;
+ else if (strncmp("From: ", bufp, 6))
+ tohdr = bufp;
+ else if (strncmp("To: ", bufp, 4))
+ fromhdr = bufp;
+ else if (strncmp("Cc: ", bufp, 4))
+ cchdr = bufp;
+ else if (strncmp("Bcc: ", bufp, 5))
+ bcchdr = bufp;
+
+ goto skipwrite;
+ }
+ else if (headers)
+ {
+ switch (output)
+ {
+ case TO_SMTP:
+ SMTP_data(mboxfd);
+ break;
+
+ case TO_FOLDER:
+ case TO_STDOUT:
+ if (unixfrom)
+ (void) strcpy(fromBuf, unixfrom);
+ else
+ {
+ now = time(NULL);
+ sprintf(fromBuf,"From POPmail %s",ctime(&now));
+ }
+
if (write(mboxfd,fromBuf,strlen(fromBuf)) < 0) {
perror("gen_readmsg: write");
return(PS_IOERR);
}
+ break;
+
+ case TO_MDA:
+ break;
}
- }
- /*
- * Edit some headers so that replies will work properly.
- */
- if (inheaders && rewrite)
- reply_hack(bufp, pophost);
+ if (write(mboxfd,headers,oldlen) < 0)
+ {
+ free(headers);
+ headers = NULL;
+ perror("gen_readmsg: write");
+ return(PS_IOERR);
+ }
+ free(headers);
+ headers = NULL;
+ }
/* write this line to the file */
- if (write(mboxfd,bufp,strlen(bufp)) < 0) {
+ if (write(mboxfd,bufp,strlen(bufp)) < 0)
+ {
perror("gen_readmsg: write");
return(PS_IOERR);
}
+ skipwrite:;
+
sizeticker -= strlen(bufp);
- if (sizeticker <= 0) {
+ if (sizeticker <= 0)
+ {
if (outlevel > O_SILENT && outlevel < O_VERBOSE && mboxfd != 1)
fputc('.',stderr);
sizeticker = MSGBUFSIZE;
diff --git a/fetchmail.c b/fetchmail.c
index 2a609973..726f93dc 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -385,6 +385,10 @@ struct hostrec *queryctl;
printf(" Old messages will%s be flushed before message retrieval (--flush %s).\n",
queryctl->flush ? "" : " not",
queryctl->flush ? "on" : "off");
+ printf(" Rewrite of host-local addresses is %sabled (--norewrite %s)\n",
+ queryctl->norewrite ? "dis" : "en",
+ queryctl->norewrite ? "on" : "off");
+
switch(queryctl->output)
{
diff --git a/fetchmail.h b/fetchmail.h
index 6cd1b480..2efb8a40 100644
--- a/fetchmail.h
+++ b/fetchmail.h
@@ -62,7 +62,7 @@ struct hostrec
int protocol;
int fetchall;
int flush;
- int rewrite;
+ int norewrite;
/* state used for tracking UIDL ids */
char lastid [IDLEN];
diff --git a/options.c b/options.c
index 804effa3..452c774d 100644
--- a/options.c
+++ b/options.c
@@ -235,7 +235,7 @@ struct hostrec *queryctl;
break;
case 'N':
case LA_NOREWRITE:
- queryctl->rewrite = 0;
+ queryctl->norewrite = 1;
break;
case LA_YYDEBUG:
yydebug = 1;
@@ -318,7 +318,7 @@ struct hostrec *queryctl;
#else
queryctl->keep = 0;
#endif
- queryctl->rewrite = 1;
+ queryctl->norewrite = 0;
strcpy(queryctl->localname,pw->pw_name);
strcpy(queryctl->remotename,pw->pw_name);