diff --git a/Source/Additions/GSMime.m b/Source/Additions/GSMime.m index 2cb2808a9..7e0f5914e 100644 --- a/Source/Additions/GSMime.m +++ b/Source/Additions/GSMime.m @@ -2419,10 +2419,21 @@ NSDebugMLLog(@"GSMime", @"Header parsed - %@", info); /* * Eat a newline that is part of a cr-lf sequence. */ - input++; - if (c == '\r' && input < dataEnd && bytes[input] == '\n') - { + if (input < dataEnd) + { + /* + * If we had an end-of-line with nothing else, we must have + * finished unwrapping at the final boundary. + */ + if (input == lineStart) + { + unwrappingComplete = YES; + } input++; + if (c == '\r' && input < dataEnd && bytes[input] == '\n') + { + input++; + } } /* @@ -2432,6 +2443,10 @@ NSDebugMLLog(@"GSMime", @"Header parsed - %@", info); && ((c = bytes[input]) == '\r' || c == '\n' || isspace(c) == 0)) { unwrappingComplete = YES; + } + + if (unwrappingComplete == YES) + { bytes[lineEnd] = '\0'; /* * If this is a zero-length line, we have reached the end of diff --git a/Source/GSHTTPURLHandle.m b/Source/GSHTTPURLHandle.m index 63c40e6c4..4707fd293 100644 --- a/Source/GSHTTPURLHandle.m +++ b/Source/GSHTTPURLHandle.m @@ -301,58 +301,55 @@ static void debugWrite(NSData *data) d = [dict objectForKey: NSFileHandleNotificationDataItem]; if (debug == YES) debugRead(d); - if ([parser parse: d] == NO || [parser isComplete] == YES) + if ([parser parse: d] == NO) { - if ([parser isComplete] == YES) + if (debug == YES) { - GSMimeHeader *info; - NSString *val; - - connectionState = idle; - [nc removeObserver: self - name: NSFileHandleReadCompletionNotification - object: sock]; - [sock closeFile]; - DESTROY(sock); - - /* - * Retrieve essential keys from document - */ - info = [document headerNamed: @"http"]; - val = [info objectForKey: NSHTTPPropertyServerHTTPVersionKey]; - if (val != nil) - { - [pageInfo setObject: val - forKey: NSHTTPPropertyServerHTTPVersionKey]; - } - val = [info objectForKey: NSHTTPPropertyStatusCodeKey]; - if (val != nil) - { - [pageInfo setObject: val forKey: NSHTTPPropertyStatusCodeKey]; - } - val = [info objectForKey: NSHTTPPropertyStatusReasonKey]; - if (val != nil) - { - [pageInfo setObject: val forKey: NSHTTPPropertyStatusReasonKey]; - } - /* - * Tell superclass that we have successfully loaded the data. - */ - d = [parser data]; - r = NSMakeRange(bodyPos, [d length] - bodyPos); - bodyPos = 0; - [self didLoadBytes: [d subdataWithRange: r] - loadComplete: YES]; + NSLog(@"HTTP parse failure - %@", parser); } - else + [self endLoadInBackground]; + [self backgroundLoadDidFailWithReason: @"Response parse failed"]; + } + else if ([parser isComplete] == YES) + { + GSMimeHeader *info; + NSString *val; + + connectionState = idle; + [nc removeObserver: self + name: NSFileHandleReadCompletionNotification + object: sock]; + [sock closeFile]; + DESTROY(sock); + + /* + * Retrieve essential keys from document + */ + info = [document headerNamed: @"http"]; + val = [info objectForKey: NSHTTPPropertyServerHTTPVersionKey]; + if (val != nil) { - if (debug == YES) - { - NSLog(@"HTTP parse failure - %@", parser); - } - [self endLoadInBackground]; - [self backgroundLoadDidFailWithReason: @"Response parse failed"]; + [pageInfo setObject: val + forKey: NSHTTPPropertyServerHTTPVersionKey]; } + val = [info objectForKey: NSHTTPPropertyStatusCodeKey]; + if (val != nil) + { + [pageInfo setObject: val forKey: NSHTTPPropertyStatusCodeKey]; + } + val = [info objectForKey: NSHTTPPropertyStatusReasonKey]; + if (val != nil) + { + [pageInfo setObject: val forKey: NSHTTPPropertyStatusReasonKey]; + } + /* + * Tell superclass that we have successfully loaded the data. + */ + d = [parser data]; + r = NSMakeRange(bodyPos, [d length] - bodyPos); + bodyPos = 0; + [self didLoadBytes: [d subdataWithRange: r] + loadComplete: YES]; } else {