From 06cc3ddbc4b24a7ce43aa6b5f259f4ce1773491f Mon Sep 17 00:00:00 2001
From: Richard Frith-Macdonald
Date: Mon, 27 May 2002 15:35:54 +0000
Subject: [PATCH] Take note of errors when parsing, and refrain from making the
parse operation complete.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13724 72102866-910b-0410-8b05-ffd578937521
---
Headers/gnustep/base/GSMime.h | 1 +
Source/Additions/GSMime.m | 24 +++++++++++++++++++++---
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/Headers/gnustep/base/GSMime.h b/Headers/gnustep/base/GSMime.h
index 3a814bb6c..a7dc3487d 100644
--- a/Headers/gnustep/base/GSMime.h
+++ b/Headers/gnustep/base/GSMime.h
@@ -127,6 +127,7 @@
BOOL inBody;
BOOL isHttp;
BOOL complete;
+ BOOL hadErrors;
NSData *boundary;
GSMimeDocument *document;
GSMimeParser *child;
diff --git a/Source/Additions/GSMime.m b/Source/Additions/GSMime.m
index 3367f37c4..e4acf65e2 100644
--- a/Source/Additions/GSMime.m
+++ b/Source/Additions/GSMime.m
@@ -813,6 +813,7 @@ parseCharacterSet(NSString *token)
}
if ([self parseHeader: header] == NO)
{
+ hadErrors = YES;
break;
}
}
@@ -891,10 +892,16 @@ parseCharacterSet(NSString *token)
}
/**
- * Returns YES if the document parsing is known to be completed.
+ * Returns YES if the document parsing is known to be completed successfully.
+ * Returns NO if either more data is needed, or if the parser encountered an
+ * error.
*/
- (BOOL) isComplete
{
+ if (hadErrors == YES)
+ {
+ return NO;
+ }
return complete;
}
@@ -965,6 +972,12 @@ parseCharacterSet(NSString *token)
* is complete.
*
*
+ * The parser attempts to be as flexible as possible and to continue
+ * parsing wherever it can. If an error occurs in parsing, the
+ * -isComplete method will always return NO, even after the -parse:
+ * method has been called with a nil argument.
+ *
+ *
* A multipart document will be parsed to content consisting of an
* NSArray of GSMimeDocument instances representing each part.
* Otherwise, a document will become content of type NSData, unless
@@ -1009,6 +1022,7 @@ parseCharacterSet(NSString *token)
}
if ([self parseHeader: header] == NO)
{
+ hadErrors = YES;
return NO; /* Header not parsed properly. */
}
NSDebugMLLog(@"GSMime", @"Parsed header '%@'", header);
@@ -2049,9 +2063,13 @@ parseCharacterSet(NSString *token)
endedFinalPart = YES;
}
if (bytes[sectionStart] == '\r')
- sectionStart++;
+ {
+ sectionStart++;
+ }
if (bytes[sectionStart] == '\n')
- sectionStart++;
+ {
+ sectionStart++;
+ }
/*
* Create data object for this section and pass it to the