From: helge Date: Wed, 20 Jul 2005 12:01:11 +0000 (+0000) Subject: improved handling of headers X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c2979b1cc8090a16ac4664ee461d400a3e0c2c4;p=scalable-opengroupware.org improved handling of headers added some mail classification git-svn-id: http://svn.opengroupware.org/SOGo/trunk@843 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index fed53ccb..7116760f 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,3 +1,7 @@ +2005-07-20 Helge Hess + + * SOGoMailObject.m: added handling for some specific headers (v0.9.114) + 2005-07-19 Helge Hess * SOGoMailObject.m: changed to fetch and parse the full mail header, diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.h b/SOGo/SoObjects/Mailer/SOGoMailObject.h index db7ab4ac..d82a14cf 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.h +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.h @@ -44,6 +44,7 @@ { id coreInfos; id headerPart; + NSDictionary *headers; } /* message */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.m b/SOGo/SoObjects/Mailer/SOGoMailObject.m index d93688d7..cd50bbed 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.m +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.m @@ -74,6 +74,7 @@ static BOOL debugSoParts = NO; } - (void)dealloc { + [self->headers release]; [self->headerPart release]; [self->coreInfos release]; [super dealloc]; @@ -216,8 +217,7 @@ static BOOL debugSoParts = NO; return [[self mailHeaderData] length] > 0 ? YES : NO; } -- (NSDictionary *)mailHeader { - // TODO: cache +- (id)mailHeaderPart { NGMimeMessageParser *parser; NSData *data; @@ -238,6 +238,11 @@ static BOOL debugSoParts = NO; } return self->headerPart; } +- (NSDictionary *)mailHeaders { + if (self->headers == nil) + self->headers = [[[self mailHeaderPart] headers] copy]; + return self->headers; +} - (id)lookupInfoForBodyPart:(id)_path { NSEnumerator *pe; @@ -758,6 +763,91 @@ static BOOL debugSoParts = NO; return [NSNumber numberWithBool:YES]; /* delete was successful */ } +/* some mail classification */ + +- (BOOL)isMailingListMail { + NSDictionary *h; + + if ((h = [self mailHeaders]) == nil) + return NO; + + return [[h objectForKey:@"list-id"] isNotEmpty]; +} + +- (BOOL)isVirusScanned { + NSDictionary *h; + + if ((h = [self mailHeaders]) == nil) + return NO; + + if (![[h objectForKey:@"x-virus-status"] isNotEmpty]) return NO; + if (![[h objectForKey:@"x-virus-scanned"] isNotEmpty]) return NO; + return YES; +} + +- (NSString *)scanListHeaderValue:(id)_value + forFieldWithPrefix:(NSString *)_prefix +{ + /* Note: not very tolerant on embedded commands and <> */ + // TODO: does not really belong here, should be a header-field-parser + NSRange r; + + if (![_value isNotEmpty]) + return nil; + + if ([_value isKindOfClass:[NSArray class]]) { + NSEnumerator *e; + id value; + + e = [_value objectEnumerator]; + while ((value = [e nextObject]) != nil) { + value = [self scanListHeaderValue:value forFieldWithPrefix:_prefix]; + if (value != nil) return value; + } + return nil; + } + + if (![_value isKindOfClass:[NSString class]]) + return nil; + + /* check for commas in string values */ + r = [_value rangeOfString:@","]; + if (r.length > 0) { + return [self scanListHeaderValue:[_value componentsSeparatedByString:@","] + forFieldWithPrefix:_prefix]; + } + + /* value qualifies */ + if (![(NSString *)_value hasPrefix:_prefix]) + return nil; + + /* unquote */ + if ([_value characterAtIndex:0] == '<') { + r = [_value rangeOfString:@">"]; + _value = (r.length == 0) + ? [_value substringFromIndex:1] + : [_value substringWithRange:NSMakeRange(1, r.location - 2)]; + } + + return _value; +} + +- (NSString *)mailingListArchiveURL { + return [self scanListHeaderValue: + [[self mailHeaders] objectForKey:@"list-archive"] + forFieldWithPrefix:@"