From: helge Date: Mon, 4 Oct 2004 01:46:02 +0000 (+0000) Subject: added MIME viewer infrastructure X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05d8ff386bf9867aa0d1c166ff5c7ad208ef6046;p=scalable-opengroupware.org added MIME viewer infrastructure git-svn-id: http://svn.opengroupware.org/SOGo/trunk@353 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.h b/SOGo/SoObjects/Mailer/SOGoMailObject.h index d727785a..d064644f 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.h +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.h @@ -61,6 +61,7 @@ - (NSArray *)toEnvelopeAddresses; - (NSArray *)ccEnvelopeAddresses; +- (id)bodyStructure; - (id)lookupInfoForBodyPart:(NSArray *)_path; @end diff --git a/SOGo/UI/Mailer/ChangeLog b/SOGo/UI/Mailer/ChangeLog index 64c28236..e1f85925 100644 --- a/SOGo/UI/Mailer/ChangeLog +++ b/SOGo/UI/Mailer/ChangeLog @@ -1,5 +1,7 @@ 2004-10-04 Helge Hess + * added MIME content viewer infrastructure (v0.9.15) + * UIxMailView.m: added 'currentAddress' accessors (v0.9.14) * UIxMailView.m: use core infos stored in message SoObject for display diff --git a/SOGo/UI/Mailer/GNUmakefile b/SOGo/UI/Mailer/GNUmakefile index cc5af4b0..9a09fea5 100644 --- a/SOGo/UI/Mailer/GNUmakefile +++ b/SOGo/UI/Mailer/GNUmakefile @@ -15,6 +15,7 @@ MailerUI_OBJC_FILES += \ UIxSubjectFormatter.m \ UIxEnvelopeAddressFormatter.m \ WOContext+UIxMailer.m \ + UIxMailRenderingContext.m \ \ UIxMailMainFrame.m \ UIxMailTree.m \ @@ -24,6 +25,11 @@ MailerUI_OBJC_FILES += \ UIxMailListView.m \ UIxMailView.m \ UIxMailEditor.m \ + \ + UIxMailPartViewer.m \ + UIxMailPartTextViewer.m \ + UIxMailPartImageViewer.m\ + UIxMailPartMixedViewer.m MailerUI_RESOURCE_FILES += \ Version \ @@ -38,6 +44,10 @@ MailerUI_RESOURCE_FILES += \ UIxMailListView.wox \ UIxMailView.wox \ UIxMailEditor.wox \ + \ + UIxMailPartTextViewer.wox \ + UIxMailPartMixedViewer.wox \ + UIxMailPartImageViewer.wox \ MailerUI_RESOURCE_FILES += \ uix.css \ diff --git a/SOGo/UI/Mailer/UIxMailPartImageViewer.m b/SOGo/UI/Mailer/UIxMailPartImageViewer.m new file mode 100644 index 00000000..d77f3e04 --- /dev/null +++ b/SOGo/UI/Mailer/UIxMailPartImageViewer.m @@ -0,0 +1,49 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include "UIxMailPartViewer.h" + +@interface UIxMailPartImageViewer : UIxMailPartViewer +{ +} + +@end + +#include "common.h" + +@implementation UIxMailPartImageViewer + +- (void)dealloc { + [super dealloc]; +} + +/* URLs */ + +- (NSString *)pathToImage { + NSString *url; + + url = [[self clientObject] baseURLInContext:[self context]]; + if (![url hasSuffix:@"/"]) url = [url stringByAppendingString:@"/"]; + return [url stringByAppendingString: + [[self partPath] componentsJoinedByString:@"/"]]; +} + +@end /* UIxMailPartImageViewer */ diff --git a/SOGo/UI/Mailer/UIxMailPartImageViewer.wox b/SOGo/UI/Mailer/UIxMailPartImageViewer.wox new file mode 100644 index 00000000..fb176335 --- /dev/null +++ b/SOGo/UI/Mailer/UIxMailPartImageViewer.wox @@ -0,0 +1,9 @@ + + diff --git a/SOGo/UI/Mailer/UIxMailPartMixedViewer.m b/SOGo/UI/Mailer/UIxMailPartMixedViewer.m new file mode 100644 index 00000000..4a7b9d36 --- /dev/null +++ b/SOGo/UI/Mailer/UIxMailPartMixedViewer.m @@ -0,0 +1,90 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include "UIxMailPartViewer.h" + +@interface UIxMailPartMixedViewer : UIxMailPartViewer +{ + id childInfo; + unsigned int childIndex; +} + +@end + +#include "UIxMailRenderingContext.h" +#include "WOContext+UIxMailer.h" +#include "common.h" + +@implementation UIxMailPartMixedViewer + +- (void)dealloc { + [self->childInfo release]; + [super dealloc]; +} + +/* notifications */ + +- (void)sleep { + [self->childInfo release]; self->childInfo = nil; + [super sleep]; +} + +/* accessors */ + +- (void)setChildInfo:(id)_info { + ASSIGN(self->childInfo, _info); +} +- (id)childInfo { + return self->childInfo; +} + +- (void)setChildIndex:(unsigned int)_index { + self->childIndex = _index; +} +- (unsigned int)childIndex { + return self->childIndex; +} + +- (NSString *)childPartName { + unsigned char buf[8]; + sprintf(buf, "%d", [self childIndex] + 1); + return [NSString stringWithCString:buf]; +} + +- (id)childPartPath { + NSArray *pp; + + pp = [self partPath]; + return [pp count] > 0 + ? [pp arrayByAddingObject:[self childPartName]] + : [NSArray arrayWithObject:[self childPartName]]; +} + +/* nested viewers */ + +- (id)contentViewerComponent { + id info; + + info = [self childInfo]; + return [[[self context] mailRenderingContext] viewerForBodyInfo:info]; +} + +@end /* UIxMailPartMixedViewer */ diff --git a/SOGo/UI/Mailer/UIxMailPartMixedViewer.wox b/SOGo/UI/Mailer/UIxMailPartMixedViewer.wox new file mode 100644 index 00000000..d8ab883d --- /dev/null +++ b/SOGo/UI/Mailer/UIxMailPartMixedViewer.wox @@ -0,0 +1,17 @@ + +
+
+ +
+ +
+
+
+
diff --git a/SOGo/UI/Mailer/UIxMailPartTextViewer.m b/SOGo/UI/Mailer/UIxMailPartTextViewer.m new file mode 100644 index 00000000..43c2706b --- /dev/null +++ b/SOGo/UI/Mailer/UIxMailPartTextViewer.m @@ -0,0 +1,38 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include "UIxMailPartViewer.h" + +@interface UIxMailPartTextViewer : UIxMailPartViewer +{ +} + +@end + +#include "common.h" + +@implementation UIxMailPartTextViewer + +- (void)dealloc { + [super dealloc]; +} + +@end /* UIxMailPartTextViewer */ diff --git a/SOGo/UI/Mailer/UIxMailPartTextViewer.wox b/SOGo/UI/Mailer/UIxMailPartTextViewer.wox new file mode 100644 index 00000000..21be728d --- /dev/null +++ b/SOGo/UI/Mailer/UIxMailPartTextViewer.wox @@ -0,0 +1,11 @@ + +
+  text
+
diff --git a/SOGo/UI/Mailer/UIxMailPartViewer.h b/SOGo/UI/Mailer/UIxMailPartViewer.h new file mode 100644 index 00000000..e386278a --- /dev/null +++ b/SOGo/UI/Mailer/UIxMailPartViewer.h @@ -0,0 +1,51 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#ifndef __Mailer_UIxMailPartViewer_H__ +#define __Mailer_UIxMailPartViewer_H__ + +#include + +/* + UIxMailPartViewer + + This class is the superclass for MIME content viewers. +*/ + +@class NSArray; + +@interface UIxMailPartViewer : UIxComponent +{ + NSArray *partPath; + id bodyInfo; +} + +/* accessors */ + +- (void)setPartPath:(NSArray *)_path; +- (NSArray *)partPath; + +- (void)setBodyInfo:(id)_info; +- (id)bodyInfo; + +@end + +#endif /* __Mailer_UIxMailPartViewer_H__ */ diff --git a/SOGo/UI/Mailer/UIxMailPartViewer.m b/SOGo/UI/Mailer/UIxMailPartViewer.m new file mode 100644 index 00000000..b1b08d92 --- /dev/null +++ b/SOGo/UI/Mailer/UIxMailPartViewer.m @@ -0,0 +1,49 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include "UIxMailPartViewer.h" +#include "common.h" + +@implementation UIxMailPartViewer + +- (void)dealloc { + [self->bodyInfo release]; + [self->partPath release]; + [super dealloc]; +} + +/* accessors */ + +- (void)setPartPath:(NSArray *)_path { + ASSIGN(self->partPath, _path); +} +- (NSArray *)partPath { + return self->partPath; +} + +- (void)setBodyInfo:(id)_info { + ASSIGN(self->bodyInfo, _info); +} +- (id)bodyInfo { + return self->bodyInfo; +} + +@end /* UIxMailPartViewer */ diff --git a/SOGo/UI/Mailer/UIxMailRenderingContext.h b/SOGo/UI/Mailer/UIxMailRenderingContext.h new file mode 100644 index 00000000..dab1e371 --- /dev/null +++ b/SOGo/UI/Mailer/UIxMailRenderingContext.h @@ -0,0 +1,57 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#ifndef __Mailer_UIxMailRenderingContext_H__ +#define __Mailer_UIxMailRenderingContext_H__ + +#import + +/* + UIxMailRenderingContext + + The rendering context is used to track nesting of mail part viewers. +*/ + +@class WOContext, WOComponent; + +@interface UIxMailRenderingContext : NSObject +{ + WOComponent *viewer; /* non-retained! */ + WOContext *context; /* non-retained! */ + + WOComponent *mixedViewer; + WOComponent *textViewer; + WOComponent *imageViewer; +} + +- (id)initWithViewer:(WOComponent *)_viewer context:(WOContext *)_ctx; + +/* state */ + +- (void)reset; + +/* viewer components */ + +- (WOComponent *)viewerForBodyInfo:(id)_info; + +@end + +#endif /* __Mailer_UIxMailRenderingContext_H__ */ diff --git a/SOGo/UI/Mailer/UIxMailRenderingContext.m b/SOGo/UI/Mailer/UIxMailRenderingContext.m new file mode 100644 index 00000000..80e650a7 --- /dev/null +++ b/SOGo/UI/Mailer/UIxMailRenderingContext.m @@ -0,0 +1,100 @@ +/* + Copyright (C) 2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include "UIxMailRenderingContext.h" +#include "common.h" + +@implementation UIxMailRenderingContext + +- (id)initWithViewer:(WOComponent *)_viewer context:(WOContext *)_ctx { + if ((self = [super init])) { + self->viewer = _viewer; + self->context = _ctx; + } + return self; +} +- (id)init { + return [self initWithViewer:nil context:nil]; +} + +- (void)dealloc { + [self->mixedViewer release]; + [self->textViewer release]; + [self->imageViewer release]; + [super dealloc]; +} + +/* resetting state */ + +- (void)reset { + [self->mixedViewer release]; self->mixedViewer = nil; + [self->textViewer release]; self->textViewer = nil; + [self->imageViewer release]; self->imageViewer = nil; +} + +/* viewer components */ + +- (WOComponent *)mixedViewer { + if (self->mixedViewer == nil) { + self->mixedViewer = + [[self->viewer pageWithName:@"UIxMailPartMixedViewer"] retain]; + } + return self->mixedViewer; +} + +- (WOComponent *)textViewer { + if (self->textViewer == nil) { + self->textViewer = + [[self->viewer pageWithName:@"UIxMailPartTextViewer"] retain]; + } + return self->textViewer; +} + +- (WOComponent *)imageViewer { + if (self->imageViewer == nil) { + self->imageViewer = + [[self->viewer pageWithName:@"UIxMailPartImageViewer"] retain]; + } + return self->imageViewer; +} + +- (WOComponent *)viewerForBodyInfo:(id)_info { + NSString *mt, *st; + + mt = [[_info valueForKey:@"type"] lowercaseString]; + st = [[_info valueForKey:@"subtype"] lowercaseString]; + + if ([mt isEqualToString:@"multipart"]) { + if ([st isEqualToString:@"mixed"]) + return [self mixedViewer]; + } + else if ([mt isEqualToString:@"text"]) { + if ([st isEqualToString:@"plain"]) + return [self textViewer]; + } + else if ([mt isEqualToString:@"image"]) + return [self imageViewer]; + + [self logWithFormat:@"ERROR: found no viewer for MIME type: %@/%@", mt, st]; + return nil; +} + +@end /* UIxMailRenderingContext */ diff --git a/SOGo/UI/Mailer/UIxMailView.m b/SOGo/UI/Mailer/UIxMailView.m index 4061a34a..4db963f3 100644 --- a/SOGo/UI/Mailer/UIxMailView.m +++ b/SOGo/UI/Mailer/UIxMailView.m @@ -31,6 +31,8 @@ @end +#include "UIxMailRenderingContext.h" +#include "WOContext+UIxMailer.h" #include #include #include "common.h" @@ -64,12 +66,72 @@ return [[self clientObject] fetchCoreInfos]; } -/* derived accessors */ - - (BOOL)hasCC { return [[[self clientObject] ccEnvelopeAddresses] count] > 0 ? YES : NO; } +/* process body structure */ + +- (BOOL)shouldFetchPartOfType:(NSString *)_type subtype:(NSString *)_subtype { + _type = [_type lowercaseString]; + _subtype = [_subtype lowercaseString]; + + if ([_type isEqualToString:@"text"]) + return [_subtype isEqualToString:@"plain"]; + return NO; +} + +- (void)addRequiredKeysOfStructure:(id)_info path:(NSString *)_p + toArray:(NSMutableArray *)_keys +{ + NSArray *parts; + unsigned i, count; + BOOL fetchPart; + + fetchPart = [self shouldFetchPartOfType:[_info valueForKey:@"type"] + subtype:[_info valueForKey:@"subtype"]]; + if (fetchPart) { + NSString *k; + + k = [[@"body[" stringByAppendingString:_p] stringByAppendingString:@"]"]; + [_keys addObject:k]; + } + + /* recurse */ + + parts = [_info objectForKey:@"parts"]; + for (i = 0, count = [parts count]; i < count; i++) { + NSString *sp; + id childInfo; + + sp = [_p length] > 0 + ? [_p stringByAppendingFormat:@".%d", i + 1] + : [NSString stringWithFormat:@"%d", i + 1]; + + childInfo = [parts objectAtIndex:i]; + + [self addRequiredKeysOfStructure:childInfo path:sp toArray:_keys]; + } +} + +- (NSArray *)contentFetchKeys { + NSMutableArray *ma; + + ma = [NSMutableArray arrayWithCapacity:4]; + [self addRequiredKeysOfStructure:[[self clientObject] bodyStructure] + path:@"" toArray:ma]; + return ma; +} + +/* viewers */ + +- (id)contentViewerComponent { + id info; + + info = [[self clientObject] bodyStructure]; + return [[[self context] mailRenderingContext] viewerForBodyInfo:info]; +} + /* actions */ - (id)defaultAction { @@ -77,6 +139,7 @@ return [NSException exceptionWithHTTPStatus:404 /* Not Found */ reason:@"did not find specified message!"]; } + [self logWithFormat:@"FETCH BODY PARTS: %@", [self contentFetchKeys]]; return self; } @@ -109,4 +172,18 @@ return [self redirectToLocation:@"view"]; } +/* generating response */ + +- (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { + UIxMailRenderingContext *mctx; + + mctx = [[UIxMailRenderingContext alloc] initWithViewer:self context:_ctx]; + [_ctx pushMailRenderingContext:mctx]; + [mctx release]; + + [super appendToResponse:_response inContext:_ctx]; + + [[_ctx popMailRenderingContext] reset]; +} + @end /* UIxMailView */ diff --git a/SOGo/UI/Mailer/UIxMailView.wox b/SOGo/UI/Mailer/UIxMailView.wox index 3d6a63e2..47c70a13 100644 --- a/SOGo/UI/Mailer/UIxMailView.wox +++ b/SOGo/UI/Mailer/UIxMailView.wox @@ -35,6 +35,9 @@ + + + (screenshot) @@ -68,11 +71,12 @@
+ +
+ -

- - screenshot - diff --git a/SOGo/UI/Mailer/Version b/SOGo/UI/Mailer/Version index cc039aca..cf9e5c12 100644 --- a/SOGo/UI/Mailer/Version +++ b/SOGo/UI/Mailer/Version @@ -1,3 +1,3 @@ # $Id$ -SUBMINOR_VERSION:=14 +SUBMINOR_VERSION:=15 diff --git a/SOGo/UI/Mailer/WOContext+UIxMailer.h b/SOGo/UI/Mailer/WOContext+UIxMailer.h index 483db2a4..07f76813 100644 --- a/SOGo/UI/Mailer/WOContext+UIxMailer.h +++ b/SOGo/UI/Mailer/WOContext+UIxMailer.h @@ -31,6 +31,7 @@ */ @class NSFormatter; +@class UIxMailRenderingContext; @interface WOContext(UIxMailer) @@ -39,6 +40,10 @@ - (NSFormatter *)mailEnvelopeAddressFormatter; - (NSFormatter *)mailEnvelopeFullAddressFormatter; +- (void)pushMailRenderingContext:(UIxMailRenderingContext *)_mctx; +- (UIxMailRenderingContext *)popMailRenderingContext; +- (UIxMailRenderingContext *)mailRenderingContext; + @end #endif /* __Mailer_WOContext_UIxMailer_H__ */ diff --git a/SOGo/UI/Mailer/WOContext+UIxMailer.m b/SOGo/UI/Mailer/WOContext+UIxMailer.m index 83a195c8..94614709 100644 --- a/SOGo/UI/Mailer/WOContext+UIxMailer.m +++ b/SOGo/UI/Mailer/WOContext+UIxMailer.m @@ -20,6 +20,7 @@ */ #include "WOContext+UIxMailer.h" +#include "UIxMailRenderingContext.h" #include "UIxMailFormatter.h" #include "common.h" @@ -44,4 +45,25 @@ initWithMaxLength:256 generateFullEMail:YES] autorelease]; } +/* mail rendering */ + +static NSString *MRK = @"UIxMailRenderingContext"; + +- (void)pushMailRenderingContext:(UIxMailRenderingContext *)_mctx { + [self setObject:_mctx forKey:MRK]; +} +- (UIxMailRenderingContext *)popMailRenderingContext { + UIxMailRenderingContext *mctx; + + if ((mctx = [self objectForKey:MRK]) == nil) + return nil; + + mctx = [[mctx retain] autorelease]; + [self removeObjectForKey:MRK]; + return mctx; +} +- (UIxMailRenderingContext *)mailRenderingContext { + return [self objectForKey:MRK]; +} + @end /* WOContext(UIxMailer) */ diff --git a/SOGo/UI/Mailer/mailer.css b/SOGo/UI/Mailer/mailer.css index d1bdc899..8a8186c3 100644 --- a/SOGo/UI/Mailer/mailer.css +++ b/SOGo/UI/Mailer/mailer.css @@ -283,3 +283,9 @@ div.mailer_mailcontent { background-color: white; padding: 8px; } + +img.mailer_imagecontent { + border: 0px; +} +pre.mailer_plaincontent { +}