From f29b44dd37a0652dbabcef76453db7184a394412 Mon Sep 17 00:00:00 2001 From: helge Date: Sun, 3 Oct 2004 00:05:13 +0000 Subject: [PATCH] work on mail viewer git-svn-id: http://svn.opengroupware.org/SOGo/trunk@346 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/SoObjects/Mailer/ChangeLog | 9 ++ SOGo/SoObjects/Mailer/SOGoMailManager.h | 4 + SOGo/SoObjects/Mailer/SOGoMailManager.m | 54 +++++++- SOGo/SoObjects/Mailer/SOGoMailObject.h | 4 + SOGo/SoObjects/Mailer/SOGoMailObject.m | 8 ++ SOGo/SoObjects/Mailer/Version | 2 +- SOGo/UI/Mailer/ChangeLog | 2 + SOGo/UI/Mailer/GNUmakefile | 7 +- SOGo/UI/Mailer/UIxEnvelopeAddressFormatter.m | 124 +++++++++++++++++++ SOGo/UI/Mailer/UIxMailFormatter.h | 11 ++ SOGo/UI/Mailer/UIxMailFormatter.m | 82 ------------ SOGo/UI/Mailer/UIxMailView.m | 53 ++++++++ SOGo/UI/Mailer/UIxMailView.wox | 42 ++++++- SOGo/UI/Mailer/Version | 2 +- SOGo/UI/Mailer/WOContext+UIxMailer.h | 1 + SOGo/UI/Mailer/WOContext+UIxMailer.m | 4 + SOGo/UI/Mailer/mailer.css | 9 +- 17 files changed, 321 insertions(+), 97 deletions(-) create mode 100644 SOGo/UI/Mailer/UIxEnvelopeAddressFormatter.m diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 325083a2..922d85a9 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,3 +1,12 @@ +2004-10-03 Helge Hess + + * v0.9.20 + + * SOGoMailObject.m: added method to fetch parts + + * SOGoMailManager.m: properly select folder prior fetch, added method + to fetch parts of a single (message) URL + 2004-10-02 Helge Hess * SOGoMailFolder.[hm]: removed ability to restrict UID fetch range, diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.h b/SOGo/SoObjects/Mailer/SOGoMailManager.h index b431d0f1..d6f468fd 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.h +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.h @@ -59,6 +59,10 @@ - (NSArray *)fetchUIDs:(NSArray *)_uids inURL:(NSURL *)_url parts:(NSArray *)_parts password:(NSString *)_pwd; +/* individual message */ + +- (id)fetchURL:(NSURL *)_url parts:(NSArray *)_parts password:(NSString *)_pwd; + @end #endif /* __Mailer_SOGoMailManager_H__ */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.m b/SOGo/SoObjects/Mailer/SOGoMailManager.m index f65ae96c..8852c92e 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.m +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.m @@ -211,7 +211,7 @@ static NSTimeInterval PoolScanInterval = 5 * 60; return @"."; } -- (NSString *)imap4FolderNameForURL:(NSURL *)_url { +- (NSString *)imap4FolderNameForURL:(NSURL *)_url removeFileName:(BOOL)_delfn { /* a bit hackish, but should be OK */ NSString *folderName; @@ -223,10 +223,15 @@ static NSTimeInterval PoolScanInterval = 5 * 60; return nil; if ([folderName characterAtIndex:0] == '/') folderName = [folderName substringFromIndex:1]; + + if (_delfn) folderName = [folderName stringByDeletingLastPathComponent]; return [[folderName pathComponents] componentsJoinedByString: [self imap4Separator]]; } +- (NSString *)imap4FolderNameForURL:(NSURL *)_url { + return [self imap4FolderNameForURL:_url removeFileName:NO]; +} - (NSArray *)extractSubfoldersForURL:(NSURL *)_url fromResultSet:(NSDictionary *)_result @@ -375,6 +380,7 @@ static NSTimeInterval PoolScanInterval = 5 * 60; - (NSArray *)fetchUIDs:(NSArray *)_uids inURL:(NSURL *)_url parts:(NSArray *)_parts password:(NSString *)_pwd { + // currently returns a dict?! /* Allowed fetch keys: UID @@ -394,11 +400,21 @@ static NSTimeInterval PoolScanInterval = 5 * 60; if (_uids == nil) return nil; if ([_uids count] == 0) - return [NSArray array]; + return nil; // TODO: might break empty folders?! return a dict! if ((client = [self imap4ClientForURL:_url password:_pwd]) == nil) return nil; + /* select folder */ + + result = [client select:[self imap4FolderNameForURL:_url]]; + if (![[result valueForKey:@"result"] boolValue]) { + [self logWithFormat:@"ERROR: could not select URL: %@: %@", _url, result]; + return nil; + } + + /* fetch parts */ + #warning TODO: split uids into batches, otherwise Cyrus will complain // not really important because we batch before (in the sort) // if the list is too long, we get a: @@ -414,6 +430,40 @@ static NSTimeInterval PoolScanInterval = 5 * 60; return (id)result; } +- (id)fetchURL:(NSURL *)_url parts:(NSArray *)_parts password:(NSString *)_pwd{ + // currently returns a dict + NGImap4Client *client; + NSDictionary *result; + NSString *uid; + + if (![_url isNotNull]) return nil; + + + if ((client = [self imap4ClientForURL:_url password:_pwd]) == nil) + return nil; + + /* select folder */ + + result = [client select:[self imap4FolderNameForURL:_url + removeFileName:YES]]; + if (![[result valueForKey:@"result"] boolValue]) { + [self logWithFormat:@"ERROR: could not select URL: %@: %@", _url, result]; + return nil; + } + + /* fetch parts */ + + uid = [[_url path] lastPathComponent]; + + result = [client fetchUids:[NSArray arrayWithObject:uid] parts:_parts]; + if (![[result valueForKey:@"result"] boolValue]) { + [self logWithFormat:@"ERROR: could not fetch url: %@", _url]; + return nil; + } + //[self logWithFormat:@"RESULT: %@", result]; + return (id)result; +} + /* debugging */ - (BOOL)isDebuggingEnabled { diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.h b/SOGo/SoObjects/Mailer/SOGoMailObject.h index 5aca122c..9cb4ab1a 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.h +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.h @@ -37,6 +37,10 @@ { } +/* message */ + +- (id)fetchParts:(NSArray *)_parts; + @end #endif /* __Mailer_SOGoMailObject_H__ */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.m b/SOGo/SoObjects/Mailer/SOGoMailObject.m index 608841d5..603ea64a 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.m +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.m @@ -21,6 +21,7 @@ // $Id$ #include "SOGoMailObject.h" +#include "SOGoMailManager.h" #include "common.h" @implementation SOGoMailObject @@ -31,4 +32,11 @@ return [self nameInContainer]; } +/* message */ + +- (id)fetchParts:(NSArray *)_parts { + return [[self mailManager] fetchURL:[self imap4URL] parts:_parts + password:[self imap4Password]]; +} + @end /* SOGoMailObject */ diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 93c8cd1d..7cb001ac 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,3 +1,3 @@ # $Id$ -SUBMINOR_VERSION:=19 +SUBMINOR_VERSION:=20 diff --git a/SOGo/UI/Mailer/ChangeLog b/SOGo/UI/Mailer/ChangeLog index 9c25d33e..8a9d37ca 100644 --- a/SOGo/UI/Mailer/ChangeLog +++ b/SOGo/UI/Mailer/ChangeLog @@ -1,5 +1,7 @@ 2004-10-03 Helge Hess + * work on viewer (v0.9.11) + * UIxMailMainFrame.wox: made toolbar floating (v0.9.10) 2004-10-02 Helge Hess diff --git a/SOGo/UI/Mailer/GNUmakefile b/SOGo/UI/Mailer/GNUmakefile index 792eb63c..cc5af4b0 100644 --- a/SOGo/UI/Mailer/GNUmakefile +++ b/SOGo/UI/Mailer/GNUmakefile @@ -11,9 +11,10 @@ MailerUI_LANGUAGES = English French MailerUI_OBJC_FILES += \ MailerUIProduct.m \ \ - UIxMailFormatter.m \ - UIxSubjectFormatter.m \ - WOContext+UIxMailer.m \ + UIxMailFormatter.m \ + UIxSubjectFormatter.m \ + UIxEnvelopeAddressFormatter.m \ + WOContext+UIxMailer.m \ \ UIxMailMainFrame.m \ UIxMailTree.m \ diff --git a/SOGo/UI/Mailer/UIxEnvelopeAddressFormatter.m b/SOGo/UI/Mailer/UIxEnvelopeAddressFormatter.m new file mode 100644 index 00000000..5330e571 --- /dev/null +++ b/SOGo/UI/Mailer/UIxEnvelopeAddressFormatter.m @@ -0,0 +1,124 @@ +/* + 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 "UIxMailFormatter.h" +#include +#include "common.h" + +@implementation UIxEnvelopeAddressFormatter + +static Class EnvAddrClass = Nil; +static Class StrClass = Nil; + ++ (void)initialize { + EnvAddrClass = [NGImap4EnvelopeAddress class]; + StrClass = [NSString class]; +} + +- (id)initWithMaxLength:(unsigned int)_max generateFullEMail:(BOOL)_genFull { + if ((self = [super init])) { + self->maxLength = _max; + self->separator = @", "; + + self->eafFlags.fullEMail = _genFull ? 1 : 0; + } + return self; +} +- (id)init { + return [self initWithMaxLength:128 generateFullEMail:NO]; +} + +/* configuration */ + +- (unsigned)maxLength { + return self->maxLength; +} +- (NSString *)separator { + return self->separator; +} +- (BOOL)generateFullEMail { + return self->eafFlags.fullEMail ? YES : NO; +} + +/* formatting envelope addresses */ + +- (NSString *)stringForEnvelopeAddress:(NGImap4EnvelopeAddress *)_address { + NSString *s; + + if ([self generateFullEMail]) + return [_address email]; + + s = [_address personalName]; + if ([s isNotNull]) return s; + + s = [_address baseEMail]; + if ([s isNotNull]) return s; + + [self debugWithFormat:@"WARNING: unexpected envelope address: %@", _address]; + return [_address stringValue]; +} + +- (NSString *)stringForArray:(NSArray *)_addresses { + NSMutableString *ms; + unsigned i, count; + + if ((count = [_addresses count]) == 0) + return nil; + + if (count == 1) + return [self stringForObjectValue:[_addresses objectAtIndex:0]]; + + ms = [NSMutableString stringWithCapacity:16 * count]; + for (i = 0; i < count && [ms length] < [self maxLength]; i++) { + NSString *s; + + s = [self stringForObjectValue:[_addresses objectAtIndex:i]]; + if (s == nil) + continue; + + if ([ms length] > 0) [ms appendString:[self separator]]; + [ms appendString:s]; + } + return ms; +} + +/* formatter entry function */ + +- (NSString *)stringForObjectValue:(id)_address { + if (![_address isNotNull]) + return nil; + + if ([_address isKindOfClass:StrClass]) /* preformatted? */ + return _address; + + if ([_address isKindOfClass:EnvAddrClass]) + return [self stringForEnvelopeAddress:_address]; + + if ([_address isKindOfClass:[NSArray class]]) + return [self stringForArray:_address]; + + [self debugWithFormat: + @"NOTE: unexpected object for envelope formatter: %@<%@>", + _address, NSStringFromClass([_address class])]; + return [_address stringValue]; +} + +@end /* UIxEnvelopeAddressFormatter */ diff --git a/SOGo/UI/Mailer/UIxMailFormatter.h b/SOGo/UI/Mailer/UIxMailFormatter.h index 8507c21b..c197eb29 100644 --- a/SOGo/UI/Mailer/UIxMailFormatter.h +++ b/SOGo/UI/Mailer/UIxMailFormatter.h @@ -82,6 +82,17 @@ @end @interface UIxEnvelopeAddressFormatter : UIxMailFormatter +{ + NSString *separator; + unsigned int maxLength; + struct { + int fullEMail:1; + int reserved:31; + } eafFlags; +} + +- (id)initWithMaxLength:(unsigned int)_max generateFullEMail:(BOOL)_genFull; + @end #endif /* __Mailer_UIxMailFormatter_H__ */ diff --git a/SOGo/UI/Mailer/UIxMailFormatter.m b/SOGo/UI/Mailer/UIxMailFormatter.m index c5a13819..04a98790 100644 --- a/SOGo/UI/Mailer/UIxMailFormatter.m +++ b/SOGo/UI/Mailer/UIxMailFormatter.m @@ -147,85 +147,3 @@ static BOOL debugOn = YES; } @end /* UIxMailDateFormatter */ - -#include - -@implementation UIxEnvelopeAddressFormatter - -static Class EnvAddrClass = Nil; - -+ (void)initialize { - if (EnvAddrClass == Nil) EnvAddrClass = [NGImap4EnvelopeAddress class]; -} - -/* configuration */ - -- (unsigned)maxLength { - return 128; // TODO -} - -- (NSString *)separator { - return @", "; -} - -/* formatting envelope addresses */ - -- (NSString *)stringForEnvelopeAddress:(NGImap4EnvelopeAddress *)_address { - NSString *s; - - s = [_address personalName]; - if ([s isNotNull]) return s; - - s = [_address baseEMail]; - if ([s isNotNull]) return s; - - [self debugWithFormat:@"WARNING: unexpected envelope address: %@", _address]; - return [_address stringValue]; -} - -- (NSString *)stringForArray:(NSArray *)_addresses { - NSMutableString *ms; - unsigned i, count; - - if ((count = [_addresses count]) == 0) - return nil; - - if (count == 1) - return [self stringForObjectValue:[_addresses objectAtIndex:0]]; - - ms = [NSMutableString stringWithCapacity:16 * count]; - for (i = 0; i < count && [ms length] < [self maxLength]; i++) { - NSString *s; - - s = [self stringForObjectValue:[_addresses objectAtIndex:i]]; - if (s == nil) - continue; - - if ([ms length] > 0) [ms appendString:[self separator]]; - [ms appendString:s]; - } - return ms; -} - -/* formatter entry function */ - -- (NSString *)stringForObjectValue:(id)_address { - if (![_address isNotNull]) - return nil; - - if ([_address isKindOfClass:StrClass]) /* preformatted? */ - return _address; - - if ([_address isKindOfClass:EnvAddrClass]) - return [self stringForEnvelopeAddress:_address]; - - if ([_address isKindOfClass:[NSArray class]]) - return [self stringForArray:_address]; - - [self debugWithFormat: - @"NOTE: unexpected object for envelope formatter: %@<%@>", - _address, NSStringFromClass([_address class])]; - return [_address stringValue]; -} - -@end /* UIxEnvelopeAddressFormatter */ diff --git a/SOGo/UI/Mailer/UIxMailView.m b/SOGo/UI/Mailer/UIxMailView.m index 0341e336..490ccc33 100644 --- a/SOGo/UI/Mailer/UIxMailView.m +++ b/SOGo/UI/Mailer/UIxMailView.m @@ -24,6 +24,7 @@ @interface UIxMailView : UIxComponent { + id message; } - (BOOL)isDeletableClientObject; @@ -31,10 +32,62 @@ @end #include +#include #include "common.h" @implementation UIxMailView +- (void)dealloc { + [self->message release]; + [super dealloc]; +} + +/* notifications */ + +- (void)sleep { + [self->message release]; self->message = nil; + [super sleep]; +} + +/* fetching */ + +- (NSArray *)fetchKeys { + /* Note: see SOGoMailManager.m for allowed IMAP4 keys */ + static NSArray *keys = nil; + if (keys == nil) + keys = [[NSArray alloc] initWithObjects:@"FLAGS", @"ENVELOPE", nil]; + return keys; +} + +- (id)message { + id msgs; + + if (self->message != nil) + return [self->message isNotNull] ? self->message : nil; + + msgs = [[self clientObject] fetchParts:[self fetchKeys]]; // returns dict + msgs = [msgs valueForKey:@"fetch"]; + if ([msgs count] == 0) + return nil; + return [msgs objectAtIndex:0]; +} + +/* derived accessors */ + +- (BOOL)hasCC { + return [[self valueForKeyPath:@"message.envelope.cc"] count] > 0 ? YES : NO; +} + +/* actions */ + +- (id)defaultAction { + if ([self message] == nil) { + return [NSException exceptionWithHTTPStatus:404 /* Not Found */ + reason:@"did not find specified message!"]; + } + return self; +} + - (BOOL)isDeletableClientObject { return [[self clientObject] respondsToSelector:@selector(delete)]; } diff --git a/SOGo/UI/Mailer/UIxMailView.wox b/SOGo/UI/Mailer/UIxMailView.wox index 95dae8ae..20342598 100644 --- a/SOGo/UI/Mailer/UIxMailView.wox +++ b/SOGo/UI/Mailer/UIxMailView.wox @@ -10,33 +10,65 @@ title="name" const:hideFolderTree="1" > + - + - + + + + + + + +
:Re: Statuslist + +
: - Maxime Wacker [mwacker@linagora.com] + +
:08.09.2004 15:32 + +
: - Helge Hess [helge.hess@skyrix.com] + + + +
: + + + + +
+
+
- a b c
+