Permalink
Browse files

More error handling when fetching message body

  • Loading branch information...
1 parent d5b029a commit 0c096356c056142a151ee193610ab8a56a53d6ae @mronge mronge committed Feb 28, 2013
Showing with 39 additions and 16 deletions.
  1. +39 −16 Source/CTCoreMessage.m
View
@@ -151,7 +151,10 @@ - (NSString *)body {
[self fetchBodyStructure];
}
NSMutableString *result = [NSMutableString string];
- [self _buildUpBodyText:myParsedMIME result:result];
+ BOOL success = [self _buildUpBodyText:myParsedMIME result:result];
+ if (!success) {
+ return nil;
+ }
return result;
}
@@ -181,7 +184,10 @@ - (NSString *)htmlBody {
[self fetchBodyStructure];
}
NSMutableString *result = [NSMutableString string];
- [self _buildUpHtmlBodyText:myParsedMIME result:result];
+ BOOL success = [self _buildUpHtmlBodyText:myParsedMIME result:result];
+ if (!success) {
+ return nil;
+ }
return result;
}
@@ -196,56 +202,73 @@ - (NSString *)bodyPreferringPlainText:(BOOL *)isHTML {
}
-- (void)_buildUpBodyText:(CTMIME *)mime result:(NSMutableString *)result {
+- (BOOL)_buildUpBodyText:(CTMIME *)mime result:(NSMutableString *)result {
if (mime == nil)
- return;
+ return NO;
if ([mime isKindOfClass:[CTMIME_MessagePart class]]) {
- [self _buildUpBodyText:[mime content] result:result];
+ return [self _buildUpBodyText:[mime content] result:result];
}
else if ([mime isKindOfClass:[CTMIME_TextPart class]]) {
if ([[mime.contentType lowercaseString] rangeOfString:@"text/plain"].location != NSNotFound) {
- [(CTMIME_TextPart *)mime fetchPart];
+ BOOL success = [(CTMIME_TextPart *)mime fetchPart];
+ if (!success) {
+ return NO;
+ }
NSString* y = [mime content];
- if(y != nil) {
- [result appendString:y];
+ if(y == nil) {
+ return NO;
}
+ [result appendString:y];
}
}
else if ([mime isKindOfClass:[CTMIME_MultiPart class]]) {
//TODO need to take into account the different kinds of multipart
NSEnumerator *enumer = [[mime content] objectEnumerator];
CTMIME *subpart;
while ((subpart = [enumer nextObject])) {
- [self _buildUpBodyText:subpart result:result];
+ BOOL success = [self _buildUpBodyText:subpart result:result];
+ if (!success) {
+ return NO;
+ }
}
}
+ return YES;
}
-- (void)_buildUpHtmlBodyText:(CTMIME *)mime result:(NSMutableString *)result {
+- (BOOL)_buildUpHtmlBodyText:(CTMIME *)mime result:(NSMutableString *)result {
if (mime == nil)
- return;
+ return NO;
if ([mime isKindOfClass:[CTMIME_MessagePart class]]) {
- [self _buildUpHtmlBodyText:[mime content] result:result];
+ return [self _buildUpHtmlBodyText:[mime content] result:result];
}
else if ([mime isKindOfClass:[CTMIME_TextPart class]]) {
if ([[mime.contentType lowercaseString] rangeOfString:@"text/html"].location != NSNotFound) {
- [(CTMIME_TextPart *)mime fetchPart];
+ BOOL success = [(CTMIME_TextPart *)mime fetchPart];
+ if (!success) {
+ return NO;
+ }
+
NSString* y = [mime content];
- if(y != nil) {
- [result appendString:y];
+ if(y == nil) {
+ return NO;
}
+ [result appendString:y];
}
}
else if ([mime isKindOfClass:[CTMIME_MultiPart class]]) {
//TODO need to take into account the different kinds of multipart
NSEnumerator *enumer = [[mime content] objectEnumerator];
CTMIME *subpart;
while ((subpart = [enumer nextObject])) {
- [self _buildUpHtmlBodyText:subpart result:result];
+ BOOL success = [self _buildUpHtmlBodyText:subpart result:result];
+ if (!success) {
+ return NO;
+ }
}
}
+ return YES;
}

0 comments on commit 0c09635

Please sign in to comment.