+- (NSDictionary *)fetchPlainTextParts {
+ return [self fetchPlainTextParts:[self plainTextContentFetchKeys]];
+}
+
+/* convert parts to strings */
+
+- (NSString *)stringForData:(NSData *)_data partInfo:(NSDictionary *)_info {
+ NSString *charset;
+ NSString *s;
+
+ if (![_data isNotNull])
+ return nil;
+
+ s = nil;
+
+ charset = [[_info valueForKey:@"parameterList"] valueForKey:@"charset"];
+ if ([charset isNotNull] && [charset length] > 0)
+ s = [NSString stringWithData:_data usingEncodingNamed:charset];
+
+ if (s == nil) { /* no charset provided, fall back to UTF-8 */
+ s = [[NSString alloc] initWithData:_data encoding:NSUTF8StringEncoding];
+ s = [s autorelease];
+ }
+
+ return s;
+}
+
+- (NSDictionary *)stringifyTextParts:(NSDictionary *)_datas {
+ NSMutableDictionary *md;
+ NSEnumerator *keys;
+ NSString *key;
+
+ md = [NSMutableDictionary dictionaryWithCapacity:4];
+ keys = [_datas keyEnumerator];
+ while ((key = [keys nextObject]) != nil) {
+ NSDictionary *info;
+ NSString *s;
+
+ info = [self lookupInfoForBodyPart:key];
+ if ((s = [self stringForData:[_datas objectForKey:key] partInfo:info]))
+ [md setObject:s forKey:key];
+ }
+ return md;
+}
+- (NSDictionary *)fetchPlainTextStrings:(NSArray *)_fetchKeys {
+ /*
+ The fetched parts are NSData objects, this method converts them into
+ NSString objects based on the information inside the bodystructure.
+
+ The fetch-keys are body fetch-keys like: body[text] or body[1.2.3].
+ The keys in the result dictionary are "" for 'text' and 1.2.3 for parts.
+ */
+ NSDictionary *datas;
+
+ if ((datas = [self fetchPlainTextParts:_fetchKeys]) == nil)
+ return nil;
+ if ([datas isKindOfClass:[NSException class]])
+ return datas;
+
+ return [self stringifyTextParts:datas];
+}
+