From: helge Date: Mon, 4 Oct 2004 02:35:16 +0000 (+0000) Subject: show text parts X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1cf586151a13d754e5b8eedc4ee2e86b751fff94;p=scalable-opengroupware.org show text parts git-svn-id: http://svn.opengroupware.org/SOGo/trunk@354 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/UI/Mailer/ChangeLog b/SOGo/UI/Mailer/ChangeLog index e1f85925..ed269b20 100644 --- a/SOGo/UI/Mailer/ChangeLog +++ b/SOGo/UI/Mailer/ChangeLog @@ -1,5 +1,7 @@ 2004-10-04 Helge Hess + * 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) diff --git a/SOGo/UI/Mailer/UIxMailPartTextViewer.m b/SOGo/UI/Mailer/UIxMailPartTextViewer.m index 43c2706b..78da7133 100644 --- a/SOGo/UI/Mailer/UIxMailPartTextViewer.m +++ b/SOGo/UI/Mailer/UIxMailPartTextViewer.m @@ -35,4 +35,25 @@ [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 */ diff --git a/SOGo/UI/Mailer/UIxMailPartTextViewer.wox b/SOGo/UI/Mailer/UIxMailPartTextViewer.wox index 21be728d..4ce6474a 100644 --- a/SOGo/UI/Mailer/UIxMailPartTextViewer.wox +++ b/SOGo/UI/Mailer/UIxMailPartTextViewer.wox @@ -7,5 +7,5 @@ xmlns:label="OGo:label" class="mailer_plaincontent" > - text + diff --git a/SOGo/UI/Mailer/UIxMailPartViewer.h b/SOGo/UI/Mailer/UIxMailPartViewer.h index e386278a..9e1f6f55 100644 --- a/SOGo/UI/Mailer/UIxMailPartViewer.h +++ b/SOGo/UI/Mailer/UIxMailPartViewer.h @@ -30,12 +30,13 @@ This class is the superclass for MIME content viewers. */ -@class NSArray; +@class NSData, NSArray; @interface UIxMailPartViewer : UIxComponent { NSArray *partPath; id bodyInfo; + NSData *flatContent; } /* accessors */ @@ -46,6 +47,8 @@ - (void)setBodyInfo:(id)_info; - (id)bodyInfo; +- (NSData *)flatContent; + @end #endif /* __Mailer_UIxMailPartViewer_H__ */ diff --git a/SOGo/UI/Mailer/UIxMailPartViewer.m b/SOGo/UI/Mailer/UIxMailPartViewer.m index b1b08d92..a043481c 100644 --- a/SOGo/UI/Mailer/UIxMailPartViewer.m +++ b/SOGo/UI/Mailer/UIxMailPartViewer.m @@ -20,11 +20,14 @@ */ #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]; @@ -46,4 +49,14 @@ 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 */ diff --git a/SOGo/UI/Mailer/UIxMailRenderingContext.h b/SOGo/UI/Mailer/UIxMailRenderingContext.h index dab1e371..4f471161 100644 --- a/SOGo/UI/Mailer/UIxMailRenderingContext.h +++ b/SOGo/UI/Mailer/UIxMailRenderingContext.h @@ -30,12 +30,14 @@ 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; @@ -48,6 +50,11 @@ - (void)reset; +/* fetching */ + +- (NSDictionary *)flatContents; +- (NSData *)flatContentForPartPath:(NSArray *)_partPath; + /* viewer components */ - (WOComponent *)viewerForBodyInfo:(id)_info; diff --git a/SOGo/UI/Mailer/UIxMailRenderingContext.m b/SOGo/UI/Mailer/UIxMailRenderingContext.m index 80e650a7..914dd2e3 100644 --- a/SOGo/UI/Mailer/UIxMailRenderingContext.m +++ b/SOGo/UI/Mailer/UIxMailRenderingContext.m @@ -22,6 +22,10 @@ #include "UIxMailRenderingContext.h" #include "common.h" +@interface WOComponent(Viewer) +- (NSDictionary *)fetchFlatContents; +@end + @implementation UIxMailRenderingContext - (id)initWithViewer:(WOComponent *)_viewer context:(WOContext *)_ctx { @@ -45,9 +49,25 @@ /* 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 */ diff --git a/SOGo/UI/Mailer/UIxMailView.m b/SOGo/UI/Mailer/UIxMailView.m index 4db963f3..8abb8a26 100644 --- a/SOGo/UI/Mailer/UIxMailView.m +++ b/SOGo/UI/Mailer/UIxMailView.m @@ -123,6 +123,41 @@ 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 { @@ -139,7 +174,10 @@ 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; } diff --git a/SOGo/UI/Mailer/Version b/SOGo/UI/Mailer/Version index cf9e5c12..27f42dca 100644 --- a/SOGo/UI/Mailer/Version +++ b/SOGo/UI/Mailer/Version @@ -1,3 +1,3 @@ # $Id$ -SUBMINOR_VERSION:=15 +SUBMINOR_VERSION:=16