fix for #9896. make nsMsgLineBuffer work for buffers that use CR, LF, and CRLF. (before, only CRLF and LF worked.) the mac uses CR, and we'd lose the last line of the newsrc file.

git-svn-id: svn://10.0.0.236/trunk@40982 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sspitzer%netscape.com 1999-07-24 18:15:19 +00:00
parent 610914a4e8
commit de502ae869
3 changed files with 41 additions and 18 deletions

View File

@ -78,12 +78,19 @@ nsMsgLineBuffer::nsMsgLineBuffer(nsMsgLineBufferHandler *handler, PRBool convert
{
m_handler = handler;
m_convertNewlinesP = convertNewlinesP;
m_lookingForCRLF = PR_TRUE;
}
nsMsgLineBuffer::~nsMsgLineBuffer()
{
}
void
nsMsgLineBuffer::SetLookingForCRLF(PRBool b)
{
m_lookingForCRLF = b;
}
PRInt32 nsMsgLineBuffer::BufferInput(const char *net_buffer, PRInt32 net_buffer_size)
{
int status = 0;
@ -107,31 +114,39 @@ PRInt32 nsMsgLineBuffer::BufferInput(const char *net_buffer, PRInt32 net_buffer_
for (s = net_buffer; s < net_buffer_end; s++)
{
if (m_lookingForCRLF) {
/* Move forward in the buffer until the first newline.
Stop when we see CRLF, CR, or LF, or the end of the buffer.
*But*, if we see a lone CR at the *very end* of the buffer,
treat this as if we had reached the end of the buffer without
seeing a line terminator. This is to catch the case of the
buffers splitting a CRLF pair, as in "FOO\r\nBAR\r" "\nBAZ\r\n".
*/
if (*s == CR || *s == LF)
{
newline = s;
if (newline[0] == CR)
{
if (s == net_buffer_end - 1)
{
/* CR at end - wait for the next character. */
newline = 0;
break;
}
else if (newline[1] == LF)
/* CRLF seen; swallow both. */
newline++;
}
newline++;
break;
*/
if (*s == CR || *s == LF) {
newline = s;
if (newline[0] == CR) {
if (s == net_buffer_end - 1) {
/* CR at end - wait for the next character. */
newline = 0;
break;
}
else if (newline[1] == LF) {
/* CRLF seen; swallow both. */
newline++;
}
}
newline++;
break;
}
}
else {
/* if not looking for a CRLF, stop at CR or LF. (for example, when parsing the newsrc file). this fixes #9896, where we'd lose the last line of anything we'd parse that used CR as the line break. */
if (*s == CR || *s == LF) {
newline = s;
newline++;
break;
}
}
}
/* Ensure room in the net_buffer and append some or all of the current

View File

@ -66,9 +66,11 @@ protected:
nsMsgLineBuffer(PRBool convertNewlinesP);
PRInt32 ConvertAndSendBuffer();
void SetLookingForCRLF(PRBool b);
nsMsgLineBufferHandler *m_handler;
PRBool m_convertNewlinesP;
PRBool m_lookingForCRLF;
};
// I'm adding this utility class here for lack of a better place. This utility class is similar to nsMsgLineBuffer

View File

@ -73,6 +73,12 @@ nsMsgNewsFolder::nsMsgNewsFolder(void) : nsMsgLineBuffer(nsnull, PR_FALSE),
{
mIsNewsHost = PR_FALSE;
mIsNewsHostInitialized = PR_FALSE;
/* we're parsing the newsrc file, and the line breaks are platform specific.
* if MSG_LINEBREAK != CRLF, then we aren't looking for CRLF
*/
if (PL_strcmp(MSG_LINEBREAK, CRLF)) {
SetLookingForCRLF(PR_FALSE);
}
// NS_INIT_REFCNT(); done by superclass
}