diff --git a/ChangeLog b/ChangeLog index 7cb7ae643..9152f90a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-11-25 Richard Frith-Macdonald + + * Source/Additions/GSMime.m: fix for incremental parsing so that + the parser insists on the crlf after the last boundary in a message + (hold a flag to say we are still expecting the crlf). + 2003-11-23 S.J.Chun * Headers/Additions/GNUstepBase/GSCategories.h: Change diff --git a/Headers/Additions/GNUstepBase/GSMime.h b/Headers/Additions/GNUstepBase/GSMime.h index f2a987dee..44fa7c2b5 100644 --- a/Headers/Additions/GNUstepBase/GSMime.h +++ b/Headers/Additions/GNUstepBase/GSMime.h @@ -160,6 +160,7 @@ unsigned int complete:1; unsigned int hadErrors:1; unsigned int buggyQuotes:1; + unsigned int wantEndOfLine:1; } flags; NSData *boundary; GSMimeDocument *document; diff --git a/Source/Additions/GSMime.m b/Source/Additions/GSMime.m index 1696bc3a4..3cd7b9c35 100644 --- a/Source/Additions/GSMime.m +++ b/Source/Additions/GSMime.m @@ -1212,7 +1212,8 @@ wordData(NSString *word) * This is an intermediary response ... so we have * to restart the parsing operation! */ - NSDebugMLLog(@"GSMime", @"Parsed http continuation", ""); + NSDebugMLLog(@"GSMime", + @"Parsed http continuation", ""); flags.inBody = 0; } } @@ -1242,7 +1243,11 @@ wordData(NSString *word) { BOOL result; - if (flags.inBody == 1) + if (flags.wantEndOfLine == 1) + { + result = [self parse: [NSData dataWithBytes: @"\r\n" length: 2]]; + } + else if (flags.inBody == 1) { result = [self _decodeBody: d]; } @@ -1254,6 +1259,7 @@ wordData(NSString *word) */ result = [self parse: [NSData dataWithBytes: @"\r\n\r\n" length: 4]]; } + flags.wantEndOfLine = 0; flags.inBody = 0; flags.complete = 1; /* Finished parsing */ return result; @@ -2201,6 +2207,8 @@ NSDebugMLLog(@"GSMime", @"Header parsed - %@", info); while (done == NO) { + BOOL found = NO; + /* * Search our data for the next boundary. */ @@ -2212,18 +2220,37 @@ NSDebugMLLog(@"GSMime", @"Header parsed - %@", info); if (lineStart == 0 || bytes[lineStart-1] == '\r' || bytes[lineStart-1] == '\n') { + BOOL lastPart = NO; + unsigned eol; + lineEnd = lineStart + bLength; - if (lineEnd + 2 < dataEnd && bytes[lineEnd] == '-' + eol = lineEnd; + if (lineEnd + 2 <= dataEnd && bytes[lineEnd] == '-' && bytes[lineEnd+1] == '-') { - endedFinalPart = YES; + eol += 2; + lastPart = YES; + } + if (eol < dataEnd && bytes[eol] == '\r') + { + eol++; + } + if (eol < dataEnd && bytes[eol] == '\n') + { + flags.wantEndOfLine = 0; + found = YES; + endedFinalPart = lastPart; + } + else + { + flags.wantEndOfLine = 1; } break; } } lineStart++; } - if (dataEnd - lineStart < bLength) + if (found == NO) { done = YES; /* Needs more data. */ }