diff --git a/Headers/Additions/GNUstepBase/GSMime.h b/Headers/Additions/GNUstepBase/GSMime.h index 6212fceb8..949c38ea3 100644 --- a/Headers/Additions/GNUstepBase/GSMime.h +++ b/Headers/Additions/GNUstepBase/GSMime.h @@ -244,6 +244,14 @@ extern "C" { - (BOOL) isInHeaders; - (GSMimeDocument*) mimeDocument; - (BOOL) parse: (NSData*)d; +/** Parses headers from the supplied data returning YES if more data is + * needed before the end of thge headers are reached.
+ * If body is not NULL and the end of the headers were reached leaving + * some unused data, that remaining data is returned.
+ * NB. The returned data is a reference to part of the original memory + * buffer provided in d, so you must copy it if you intend to use it after + * modifying or deallocating the original data. + */ - (BOOL) parseHeaders: (NSData*)d remaining: (NSData**)body; - (BOOL) parseHeader: (NSString*)aHeader; - (BOOL) scanHeaderBody: (NSScanner*)scanner into: (GSMimeHeader*)info; diff --git a/Source/Additions/GSMime.m b/Source/Additions/GSMime.m index d70cdf45e..5898495a0 100644 --- a/Source/Additions/GSMime.m +++ b/Source/Additions/GSMime.m @@ -1357,13 +1357,11 @@ wordData(NSString *word) } if (l == 0) { - NSData *dummy = nil; - /* Add an empty line to the end of the current headers to force * completion of header parsing. */ [self parseHeaders: [NSData dataWithBytes: "\r\n\r\n" length: 4] - remaining: &dummy]; + remaining: 0]; flags.wantEndOfLine = 0; flags.inBody = 0; flags.complete = 1; /* Finished parsing */ @@ -1386,7 +1384,16 @@ wordData(NSString *word) [data appendBytes: [d bytes] length: i]; bytes = (unsigned char*)[data bytes]; dataEnd = [data length]; - d = [d subdataWithRange: NSMakeRange(i, l - i)]; + if (l > i) + { + d = [[[NSData alloc] initWithBytesNoCopy: (void*)([d bytes] + i) + length: l - i + freeWhenDone: NO] autorelease]; + } + else + { + d = nil; + } if (body != 0) { *body = d;