[Courier-imap] [PATCH 1/2] Fix RFC822.HEADER for messages with CRLF lines
Brought to you by:
mrsam
From: Ángel G. <an...@16...> - 2014-08-20 20:15:38
|
Previously RFC822.HEADER would return the full email. --- imap/fetch.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/imap/fetch.c b/imap/fetch.c index 54e7139..40dd270 100644 --- a/imap/fetch.c +++ b/imap/fetch.c @@ -1353,7 +1353,7 @@ static void rfc822header(FILE *fp, struct fetchinfo *fi, struct rfc2045 *rfcp) { unsigned long n=0; -int c; +int c, last; char buf[BUFSIZ]; unsigned long i; int eol; @@ -1368,15 +1368,22 @@ int eol; } eol=0; + last = 0; while ((c=getc(fp)) != EOF) { ++n; - if (c != '\n') + if (c == '\r') { + last=c; + continue; + } + else if (c != '\n') + { + last=0; eol=0; continue; } - ++n; + if (last != '\r') ++n; if (eol) break; eol=1; } @@ -1392,8 +1399,10 @@ int eol; writes("}\r\n"); i=0; + c = 0; while (n) { + last = c; c=getc(fp); if (c == '\n') { @@ -1402,8 +1411,11 @@ int eol; writemem(buf, i); i=0; } - buf[i++]='\r'; - if (--n == 0) break; + if (last != '\r') + { + buf[i++]='\r'; + if (--n == 0) break; + } } if (i >= sizeof(buf)) -- 1.7.10.4 |