From: helge Date: Sun, 3 Oct 2004 22:33:46 +0000 (+0000) Subject: moved core info fetch to SoObject X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42ae9a7831f3b69db4c82a07ff303c85342f0f61;p=scalable-opengroupware.org moved core info fetch to SoObject git-svn-id: http://svn.opengroupware.org/SOGo/trunk@350 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 9be6b5f4..07a7a049 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,3 +1,9 @@ +2004-10-04 Helge Hess + + * SOGoMailObject.m: added method to fetch core infos of a mail, added + various methods to retrieve core info data (like subject or date) + (v0.9.22) + 2004-10-03 Helge Hess * v0.9.21 diff --git a/SOGo/SoObjects/Mailer/SOGoMailBodyPart.h b/SOGo/SoObjects/Mailer/SOGoMailBodyPart.h index cd2eb996..39e13038 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailBodyPart.h +++ b/SOGo/SoObjects/Mailer/SOGoMailBodyPart.h @@ -33,10 +33,20 @@ commands in NGImap4. */ +@class SOGoMailObject; + @interface SOGoMailBodyPart : SOGoMailBaseObject { } +/* hierarchy */ + +- (SOGoMailObject *)mailObject; + +/* IMAP4 */ + +- (NSString *)bodyPartIdentifier; + @end #endif /* __Mailer_SOGoMailBodyPart_H__ */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailBodyPart.m b/SOGo/SoObjects/Mailer/SOGoMailBodyPart.m index 8a66834a..b326af03 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailBodyPart.m +++ b/SOGo/SoObjects/Mailer/SOGoMailBodyPart.m @@ -21,6 +21,7 @@ #include "SOGoMailBodyPart.h" #include "SOGoMailObject.h" +#include "SOGoMailManager.h" #include "common.h" @implementation SOGoMailBodyPart @@ -35,6 +36,38 @@ return [[self container] mailObject]; } +/* IMAP4 */ + +- (NSString *)bodyPartIdentifier { + NSMutableString *ms; + id obj; + + ms = [NSMutableString stringWithCapacity:16]; + for (obj = self; [obj isKindOfClass:[SOGoMailBodyPart class]]; + obj = [obj container]) { + NSString *s; + NSRange r; + + s = [self nameInContainer]; + r = [s rangeOfString:@"."]; /* strip extensions */ + if (r.length > 0) + s = [s substringToIndex:r.location]; + + if ([ms length] > 0) { + [ms insertString:@"." atIndex:0]; + [ms insertString:s atIndex:0]; + } + else + [ms appendString:s]; + } + return ms; +} + +- (NSURL *)imap4URL { + /* reuse URL of message */ + return [[self mailObject] imap4URL]; +} + /* name lookup */ - (id)lookupImap4BodyPartKey:(NSString *)_key inContext:(id)_ctx { @@ -59,4 +92,57 @@ return [NSException exceptionWithHTTPStatus:404 /* Not Found */]; } +/* fetch */ + +- (NSData *)fetchBLOB { + // HEADER, HEADER.FIELDS, HEADER.FIELDS.NOT, MIME, TEXT + return [[self mailManager] fetchContentOfBodyPart:[self bodyPartIdentifier] + atURL:[self imap4URL] + password:[self imap4Password]]; +} + +/* WebDAV */ + +- (NSString *)davContentType { + // TODO: what about the content-type and other headers? + // => we could pass them in as the extension? (eg generate 1.gif!) + NSString *pe; + + pe = [[self nameInContainer] pathExtension]; + if ([pe length] == 0) + return @"application/octet-stream"; + + /* TODO: add some map */ + if ([pe isEqualToString:@"gif"]) return @"image/gif"; + if ([pe isEqualToString:@"png"]) return @"image/png"; + if ([pe isEqualToString:@"jpg"]) return @"image/jpeg"; + if ([pe isEqualToString:@"txt"]) return @"text/plain"; + + return @"application/octet-stream"; +} + +/* actions */ + +- (id)GETAction:(WOContext *)_ctx { + WOResponse *r; + NSData *data; + + [self debugWithFormat:@"should fetch body part: %@", + [self bodyPartIdentifier]]; + + if ((data = [self fetchBLOB]) == nil) { + return [NSException exceptionWithHTTPStatus:404 /* not found */ + reason:@"did not find body part"]; + } + + [self debugWithFormat:@" fetched %d bytes.", [data length]]; + + r = [_ctx response]; + [r setHeader:[self davContentType] forKey:@"content-type"]; + [r setHeader:[NSString stringWithFormat:@"%d", [data length]] + forKey:@"content-length"]; + [r setContent:data]; + return r; +} + @end /* SOGoMailBodyPart */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.h b/SOGo/SoObjects/Mailer/SOGoMailManager.h index d6f468fd..36a40994 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.h +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.h @@ -31,7 +31,7 @@ Coordinates access to IMAP4 mailboxes, caches folder hierarchies, etc. */ -@class NSString, NSURL, NSArray, NSMutableDictionary, NSTimer; +@class NSString, NSData, NSURL, NSArray, NSMutableDictionary, NSTimer; @class NGImap4Client; @interface SOGoMailManager : NSObject @@ -63,6 +63,9 @@ - (id)fetchURL:(NSURL *)_url parts:(NSArray *)_parts password:(NSString *)_pwd; +- (NSData *)fetchContentOfBodyPart:(NSString *)_partId + atURL:(NSURL *)_url password:(NSString *)_pwd; + @end #endif /* __Mailer_SOGoMailManager_H__ */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.m b/SOGo/SoObjects/Mailer/SOGoMailManager.m index 1a66f0aa..7f46fce6 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.m +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.m @@ -465,6 +465,44 @@ static NSTimeInterval PoolScanInterval = 5 * 60; return (id)result; } +- (NSData *)fetchContentOfBodyPart:(NSString *)_partId + atURL:(NSURL *)_url password:(NSString *)_pwd +{ + NSString *key; + NSArray *parts; + id result, fetch, body; + + if (_partId == nil) return nil; + + key = [@"body[" stringByAppendingString:_partId]; + key = [key stringByAppendingString:@"]"]; + parts = [NSArray arrayWithObjects:&key count:1]; + + /* fetch */ + + result = [self fetchURL:_url parts:parts password:_pwd]; + + /* process results */ + + result = [result objectForKey:@"fetch"]; + if ([result count] == 0) { /* did not find part */ + [self logWithFormat:@"ERROR: did not find part: %@", _partId]; + return nil; + } + + fetch = [result objectAtIndex:0]; + if ((body = [fetch objectForKey:@"body"]) == nil) { + [self logWithFormat:@"ERROR: did not find body in response: %@", result]; + return nil; + } + + if ((result = [body objectForKey:@"data"]) == nil) { + [self logWithFormat:@"ERROR: did not find data in body: %@", fetch]; + return nil; + } + return result; +} + /* debugging */ - (BOOL)isDebuggingEnabled { diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.h b/SOGo/SoObjects/Mailer/SOGoMailObject.h index ae45d58f..09c01a75 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.h +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.h @@ -38,14 +38,29 @@ would address the MIME part 1.2.3 of the mail 12345 in the folder INBOX. */ +@class NSString, NSArray, NSCalendarDate; +@class NGImap4Envelope, NGImap4EnvelopeAddress; + @interface SOGoMailObject : SOGoMailBaseObject { + id coreInfos; } /* message */ - (id)fetchParts:(NSArray *)_parts; /* Note: 'parts' are fetch keys here */ +/* core infos */ + +- (id)fetchCoreInfos; + +- (NGImap4Envelope *)envelope; +- (NSString *)subject; +- (NSCalendarDate *)date; +- (NGImap4EnvelopeAddress *)fromEnvelopeAddress; +- (NSArray *)toEnvelopeAddresses; +- (NSArray *)ccEnvelopeAddresses; + @end #endif /* __Mailer_SOGoMailObject_H__ */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.m b/SOGo/SoObjects/Mailer/SOGoMailObject.m index 072fdb62..fb29a6a9 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.m +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.m @@ -23,10 +23,26 @@ #include "SOGoMailObject.h" #include "SOGoMailManager.h" #include "SOGoMailBodyPart.h" +#include +#include #include "common.h" @implementation SOGoMailObject +static NSArray *coreInfoKeys = nil; + ++ (void)initialize { + /* Note: see SOGoMailManager.m for allowed IMAP4 keys */ + /* Note: "BODY" actually returns the structure! */ + coreInfoKeys = [[NSArray alloc] initWithObjects: + @"FLAGS", @"ENVELOPE", @"BODY", nil]; +} + +- (void)dealloc { + [self->coreInfos release]; + [super dealloc]; +} + /* IMAP4 */ - (NSString *)relativeImap4Name { @@ -46,6 +62,43 @@ password:[self imap4Password]]; } +/* core infos */ + +- (id)fetchCoreInfos { + id msgs; + + if (self->coreInfos != nil) + return [self->coreInfos isNotNull] ? self->coreInfos : nil; + + msgs = [[self clientObject] fetchParts:coreInfoKeys]; // returns dict + // [self logWithFormat:@"M: %@", msgs]; + msgs = [msgs valueForKey:@"fetch"]; + if ([msgs count] == 0) + return nil; + + self->coreInfos = [[msgs objectAtIndex:0] retain]; + return self->coreInfos; +} + +- (NGImap4Envelope *)envelope { + return [[self fetchCoreInfos] valueForKey:@"envelope"]; +} +- (NSString *)subject { + return [[self envelope] subject]; +} +- (NSCalendarDate *)date { + return [[self envelope] date]; +} +- (NGImap4EnvelopeAddress *)fromEnvelopeAddress { + return [[self envelope] from]; +} +- (NSArray *)toEnvelopeAddresses { + return [[self envelope] to]; +} +- (NSArray *)ccEnvelopeAddresses { + return [[self envelope] cc]; +} + /* name lookup */ - (BOOL)isBodyPartKey:(NSString *)_key inContext:(id)_ctx { diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 49f242e5..78237daf 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,3 +1,3 @@ # $Id$ -SUBMINOR_VERSION:=21 +SUBMINOR_VERSION:=22 diff --git a/SOGo/UI/Mailer/ChangeLog b/SOGo/UI/Mailer/ChangeLog index 0c540986..01c54cd5 100644 --- a/SOGo/UI/Mailer/ChangeLog +++ b/SOGo/UI/Mailer/ChangeLog @@ -1,3 +1,8 @@ +2004-10-04 Helge Hess + + * UIxMailView.m: use core infos stored in message SoObject for display + (v0.9.13) + 2004-10-03 Helge Hess * v0.9.12 diff --git a/SOGo/UI/Mailer/UIxMailView.m b/SOGo/UI/Mailer/UIxMailView.m index 49cd19be..68e09945 100644 --- a/SOGo/UI/Mailer/UIxMailView.m +++ b/SOGo/UI/Mailer/UIxMailView.m @@ -24,7 +24,6 @@ @interface UIxMailView : UIxComponent { - id message; id currentAddress; } @@ -40,7 +39,6 @@ - (void)dealloc { [self->currentAddress release]; - [self->message release]; [super dealloc]; } @@ -48,43 +46,19 @@ - (void)sleep { [self->currentAddress release]; self->currentAddress = nil; - [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) { - /* Note: "BODY" actually returns the structure! */ - keys = [[NSArray alloc] initWithObjects: - @"FLAGS", @"ENVELOPE", @"BODY", 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 - // [self logWithFormat:@"M: %@", msgs]; - msgs = [msgs valueForKey:@"fetch"]; - if ([msgs count] == 0) - return nil; - - self->message = [[msgs objectAtIndex:0] retain]; - return self->message; + return [[self clientObject] fetchCoreInfos]; } /* derived accessors */ - (BOOL)hasCC { - return [[self valueForKeyPath:@"message.envelope.cc"] count] > 0 ? YES : NO; + return [[[self clientObject] ccEnvelopeAddresses] count] > 0 ? YES : NO; } /* actions */ diff --git a/SOGo/UI/Mailer/UIxMailView.wox b/SOGo/UI/Mailer/UIxMailView.wox index 6e0e2f77..3d6a63e2 100644 --- a/SOGo/UI/Mailer/UIxMailView.wox +++ b/SOGo/UI/Mailer/UIxMailView.wox @@ -17,7 +17,7 @@ : - @@ -26,14 +26,14 @@ - : - @@ -42,7 +42,8 @@ : - + @@ -54,7 +55,8 @@ : - + diff --git a/SOGo/UI/Mailer/Version b/SOGo/UI/Mailer/Version index 9cef7993..92c8fa08 100644 --- a/SOGo/UI/Mailer/Version +++ b/SOGo/UI/Mailer/Version @@ -1,3 +1,3 @@ # $Id$ -SUBMINOR_VERSION:=12 +SUBMINOR_VERSION:=13