Re: [PATCH] Let mailsplit and mailinfo handle mails with CRLF line-endings
- From
- Brandon Casey <brandon.casey.ctr@nrlssc.navy.mil>
- Date
- Aug 4, 2009, 18:50 UTC
- Message-ID
- <pUtiIFYWaIGcw7mPKZiIk4XSCpgEimhFB1QSpwG5P0mtMWR_ZefDdg@cipher.nrlssc.navy.mil>
- In-Reply-To
- <fabb9a1e0908041034y1a43fdf6nae14ec106a82f00c@mail.gmail.com>
Sverre Rabbelier wrote:
Show 15 quoted lines
> Heya, > > On Tue, Aug 4, 2009 at 10:26, Alex Riesen<raa.lkml@gmail.com> wrote: >> } >> + if (len > 1 && buf[len - 2] == '\r') >> + buf[--len - 1] = '\n'; >> buf[len] = '\0'; > > How about something like: > > + if (len > 1 && buf[len - 2] == '\r' && (buf[len - 1] == '\n' > || buf[len - 1] == '\0')) > + buf[--len - 1] = '\n'; > > To make sure that we're not erasing a \r somewhere in the middle of the content?
You may want to push the \r back into the buffer if it is the last character read too. We may reach the limit of size characters without finding a \n, and so we can't tell whether the last \r we read was a solitary \r or whether it is the beginning of \r\n sequence.
So maybe we need something like this after the 'for' loop instead:
if (c == '\n') {
if (len > 1 && buf[len - 2] == '\r')
buf[--len - 1] = '\n';
} else if (c == '\r') {
ungetc(c, in);
len--;
}-brandon