2004-10-04 Helge Hess <helge.hess@opengroupware.org>
+ * added flat body fetches, used in text viewer (v0.9.16)
+
* added MIME content viewer infrastructure (v0.9.15)
* UIxMailView.m: added 'currentAddress' accessors (v0.9.14)
[super dealloc];
}
+/* 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)
+ 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];
+ return [s autorelease];
+}
+
@end /* UIxMailPartTextViewer */
xmlns:label="OGo:label"
class="mailer_plaincontent"
>
- text
+ <var:string value="flatContentAsString" />
</pre>
This class is the superclass for MIME content viewers.
*/
-@class NSArray;
+@class NSData, NSArray;
@interface UIxMailPartViewer : UIxComponent
{
NSArray *partPath;
id bodyInfo;
+ NSData *flatContent;
}
/* accessors */
- (void)setBodyInfo:(id)_info;
- (id)bodyInfo;
+- (NSData *)flatContent;
+
@end
#endif /* __Mailer_UIxMailPartViewer_H__ */
*/
#include "UIxMailPartViewer.h"
+#include "UIxMailRenderingContext.h"
+#include "WOContext+UIxMailer.h"
#include "common.h"
@implementation UIxMailPartViewer
- (void)dealloc {
+ [self->flatContent release];
[self->bodyInfo release];
[self->partPath release];
[super dealloc];
return self->bodyInfo;
}
+- (NSData *)flatContent {
+ if (self->flatContent != nil)
+ return [self->flatContent isNotNull] ? self->flatContent : nil;
+
+ self->flatContent =
+ [[[[self context] mailRenderingContext] flatContentForPartPath:
+ [self partPath]] retain];
+ return self->flatContent;
+}
+
@end /* UIxMailPartViewer */
The rendering context is used to track nesting of mail part viewers.
*/
+@class NSData, NSArray, NSDictionary;
@class WOContext, WOComponent;
@interface UIxMailRenderingContext : NSObject
{
- WOComponent *viewer; /* non-retained! */
- WOContext *context; /* non-retained! */
+ WOComponent *viewer; /* non-retained! */
+ WOContext *context; /* non-retained! */
+ NSDictionary *flatContents; /* IMAP4 name to NSData */
WOComponent *mixedViewer;
WOComponent *textViewer;
- (void)reset;
+/* fetching */
+
+- (NSDictionary *)flatContents;
+- (NSData *)flatContentForPartPath:(NSArray *)_partPath;
+
/* viewer components */
- (WOComponent *)viewerForBodyInfo:(id)_info;
#include "UIxMailRenderingContext.h"
#include "common.h"
+@interface WOComponent(Viewer)
+- (NSDictionary *)fetchFlatContents;
+@end
+
@implementation UIxMailRenderingContext
- (id)initWithViewer:(WOComponent *)_viewer context:(WOContext *)_ctx {
/* resetting state */
- (void)reset {
- [self->mixedViewer release]; self->mixedViewer = nil;
- [self->textViewer release]; self->textViewer = nil;
- [self->imageViewer release]; self->imageViewer = nil;
+ [self->flatContents release]; self->flatContents = nil;
+ [self->mixedViewer release]; self->mixedViewer = nil;
+ [self->textViewer release]; self->textViewer = nil;
+ [self->imageViewer release]; self->imageViewer = nil;
+}
+
+/* fetching */
+
+- (NSDictionary *)flatContents {
+ if (self->flatContents != nil)
+ return [self->flatContents isNotNull] ? self->flatContents : nil;
+
+ self->flatContents = [[self->viewer fetchFlatContents] retain];
+ return self->flatContents;
+}
+
+- (NSData *)flatContentForPartPath:(NSArray *)_partPath {
+ return [[self flatContents] objectForKey:
+ [_partPath componentsJoinedByString:@"."]];
}
/* viewer components */
return ma;
}
+- (NSDictionary *)fetchFlatContents {
+ NSMutableDictionary *flatContents;
+ unsigned i, count;
+ NSArray *keys;
+ id result;
+
+ keys = [self contentFetchKeys];
+ result = [[self clientObject] fetchParts:keys];
+ result = [result valueForKey:@"RawResponse"]; // hackish
+ result = [result objectForKey:@"fetch"]; // Note: -valueForKey: doesn't work!
+
+ count = [keys count];
+ flatContents = [NSMutableDictionary dictionaryWithCapacity:count];
+ for (i = 0; i < count; i++) {
+ NSString *key;
+ NSData *data;
+
+ key = [keys objectAtIndex:i];
+ data = [[result objectForKey:key] objectForKey:@"data"];
+
+ if (![data isNotNull]) continue;
+
+ if ([key hasPrefix:@"body["]) {
+ NSRange r;
+
+ key = [key substringFromIndex:5];
+ r = [key rangeOfString:@"]"];
+ if (r.length > 0)
+ key = [key substringToIndex:r.location];
+ }
+ [flatContents setObject:data forKey:key];
+ }
+ return flatContents;
+}
+
/* viewers */
- (id)contentViewerComponent {
return [NSException exceptionWithHTTPStatus:404 /* Not Found */
reason:@"did not find specified message!"];
}
+#if 0
[self logWithFormat:@"FETCH BODY PARTS: %@", [self contentFetchKeys]];
+ [self logWithFormat:@"CORE: %@", [self fetchFlatContents]];
+#endif
return self;
}
# $Id$
-SUBMINOR_VERSION:=15
+SUBMINOR_VERSION:=16