2004-10-05 Helge Hess <helge.hess@opengroupware.org>
+ * v0.9.19
+
+ * UIxMailPartViewer.m: added content decoding for QP, base64 and 7bit,
+ added proper charset decoding
+
+ * UIxMailPartTextViewer.m: moved content => NSString conversion to
+ UIxMailPartViewer.m
+
* v0.9.18
* UIxMailPartViewer.m: added support methods for caches, added -sleep
/* accessors */
-- (NSString *)flatContentAsString {
- /* Note: we even have the line count in the body-info! */
- NSString *charset, *enc;
- NSString *s;
- NSData *content;
-
- if ((content = [self flatContent]) == nil) {
- [self logWithFormat:@"ERROR: got no text content: %@", [self partPath]];
- return nil;
- }
-
- charset =
- [[[self bodyInfo] objectForKey:@"parameterList"] objectForKey:@"charset"];
- enc = [[self bodyInfo] objectForKey:@"encoding"];
-
- // TODO: properly decode charset, might need to handle encoding?
-
- s = [[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding];
- if (s == nil)
- [self logWithFormat:@"ERROR: could not convert content to text!"];
- return [s autorelease];
-}
-
@end /* UIxMailPartTextViewer */
#include "UIxMailPartViewer.h"
#include "UIxMailRenderingContext.h"
#include "WOContext+UIxMailer.h"
+#include <NGExtensions/NSString+Encoding.h>
#include "common.h"
@implementation UIxMailPartViewer
return self->flatContent;
}
+- (NSData *)decodedFlatContent {
+ NSString *enc;
+
+ enc = [[[self bodyInfo] objectForKey:@"encoding"] lowercaseString];
+
+ if ([enc isEqualToString:@"7bit"])
+ return [self flatContent];
+
+ if ([enc isEqualToString:@"base64"])
+ return [[self flatContent] dataByDecodingBase64];
+
+ if ([enc isEqualToString:@"quoted-printable"])
+ return [[self flatContent] dataByDecodingQuotedPrintable];
+
+ [self logWithFormat:@"ERROR: unsupported MIME encoding: %@", enc];
+ return [self flatContent];
+}
+
+- (NSString *)flatContentAsString {
+ /* Note: we even have the line count in the body-info! */
+ NSString *charset;
+ NSString *s;
+ NSData *content;
+
+ if ((content = [self decodedFlatContent]) == nil) {
+ [self logWithFormat:@"ERROR: got no text content: %@", [self partPath]];
+ return nil;
+ }
+
+ charset =
+ [[[self bodyInfo] objectForKey:@"parameterList"] objectForKey:@"charset"];
+ charset = [charset lowercaseString];
+
+ // TODO: properly decode charset, might need to handle encoding?
+
+ if ([charset length] > 0) {
+ s = [NSString stringWithData:content usingEncodingNamed:charset];
+ }
+ else {
+ s = [[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding];
+ s = [s autorelease];
+ }
+ if (s == nil) {
+ [self logWithFormat:
+ @"ERROR: could not convert content to text, charset: '%@'",
+ charset];
+ }
+ return s;
+}
+
@end /* UIxMailPartViewer */