From: helge Date: Tue, 19 Jul 2005 17:13:46 +0000 (+0000) Subject: added fetching of the full MIME header to SOGoMailObject X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=567c5945f187348e2cbe11307930d572f8da0d2b;p=scalable-opengroupware.org added fetching of the full MIME header to SOGoMailObject git-svn-id: http://svn.opengroupware.org/SOGo/trunk@833 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 06dde0ef..fed53ccb 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,5 +1,9 @@ 2005-07-19 Helge Hess + * SOGoMailObject.m: changed to fetch and parse the full mail header, + can be disabled using the 'SOGoDoNotFetchMailHeader' default. The + overhead is about 10ms on the dev-system (v0.9.113) + * SOGoMailFolder.m: report NO in -isCreateAllowed when the folder is the INBOX and SOGoSpecialFoldersInRoot (altnamespace) is enabled (#1472) (v0.9.112) diff --git a/SOGo/SoObjects/Mailer/README b/SOGo/SoObjects/Mailer/README index 9f1b4389..8d0e5cc9 100644 --- a/SOGo/SoObjects/Mailer/README +++ b/SOGo/SoObjects/Mailer/README @@ -50,3 +50,9 @@ SOGoInternetMailSuffix String-Pattern '"*** This email was composed using SOGo on the public Internet ***"' you can access request values inside the pattern, eg: "$headers.host$" + +SOGoDoNotFetchMailHeader YES|NO - whether or not to fetch the mail header + - the mail header is ~4KB to fetch, a slowdown of ~13ms on the dev system + - the header gives much more information about the mail + - eg: spam status + - parsing the mail header takes time diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.h b/SOGo/SoObjects/Mailer/SOGoMailObject.h index fc888cc1..db7ab4ac 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.h +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.h @@ -43,6 +43,7 @@ @interface SOGoMailObject : SOGoMailBaseObject { id coreInfos; + id headerPart; } /* message */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.m b/SOGo/SoObjects/Mailer/SOGoMailObject.m index 713a1e9f..d93688d7 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.m +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.m @@ -26,12 +26,14 @@ #include "SOGoMailBodyPart.h" #include #include +#include #include "common.h" @implementation SOGoMailObject static NSArray *coreInfoKeys = nil; static BOOL heavyDebug = NO; +static BOOL fetchHeader = YES; static BOOL debugOn = NO; static BOOL debugBodyStructure = NO; static BOOL debugSoParts = NO; @@ -41,21 +43,39 @@ static BOOL debugSoParts = NO; } + (void)initialize { + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + NSAssert2([super version] == 1, @"invalid superclass (%@) version %i !", NSStringFromClass([self superclass]), [super version]); - + + if ((fetchHeader = ([ud boolForKey:@"SOGoDoNotFetchMailHeader"] ? NO : YES))) + NSLog(@"Note: fetching full mail header."); + else + NSLog(@"Note: not fetching full mail header: 'SOGoDoNotFetchMailHeader'"); + /* Note: see SOGoMailManager.m for allowed IMAP4 keys */ /* Note: "BODY" actually returns the structure! */ - coreInfoKeys = [[NSArray alloc] initWithObjects: - @"FLAGS", @"ENVELOPE", @"BODY", - @"RFC822.SIZE", - // not yet supported: @"INTERNALDATE", - nil]; + if (fetchHeader) { + coreInfoKeys = [[NSArray alloc] initWithObjects: + @"FLAGS", @"ENVELOPE", @"BODY", + @"RFC822.SIZE", + @"RFC822.HEADER", + // not yet supported: @"INTERNALDATE", + nil]; + } + else { + coreInfoKeys = [[NSArray alloc] initWithObjects: + @"FLAGS", @"ENVELOPE", @"BODY", + @"RFC822.SIZE", + // not yet supported: @"INTERNALDATE", + nil]; + } } - (void)dealloc { - [self->coreInfos release]; + [self->headerPart release]; + [self->coreInfos release]; [super dealloc]; } @@ -189,6 +209,36 @@ static BOOL debugSoParts = NO; return [[self envelope] cc]; } +- (NSData *)mailHeaderData { + return [[self fetchCoreInfos] valueForKey:@"header"]; +} +- (BOOL)hasMailHeaderInCoreInfos { + return [[self mailHeaderData] length] > 0 ? YES : NO; +} + +- (NSDictionary *)mailHeader { + // TODO: cache + NGMimeMessageParser *parser; + NSData *data; + + if (self->headerPart != nil) + return [self->headerPart isNotNull] ? self->headerPart : nil; + + if ([(data = [self mailHeaderData]) length] == 0) + return nil; + + // TODO: do we need to set some delegate method which stops parsing the body? + parser = [[NGMimeMessageParser alloc] init]; + self->headerPart = [[parser parsePartFromData:data] retain]; + [parser release]; parser = nil; + + if (self->headerPart == nil) { + self->headerPart = [[NSNull null] retain]; + return nil; + } + return self->headerPart; +} + - (id)lookupInfoForBodyPart:(id)_path { NSEnumerator *pe; NSString *p; diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 493dfefc..66083a11 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=112 +SUBMINOR_VERSION:=113 # v0.9.111 requires libNGExtensions v4.5.163 # v0.9.96 requires libNGMime v4.5.223 diff --git a/SOGo/UI/Templates/MailerUI/UIxMailListView.wox b/SOGo/UI/Templates/MailerUI/UIxMailListView.wox index 418fdf86..3dc615c5 100644 --- a/SOGo/UI/Templates/MailerUI/UIxMailListView.wox +++ b/SOGo/UI/Templates/MailerUI/UIxMailListView.wox @@ -112,14 +112,16 @@ +