}
- (void)dealloc {
+ [self->headers release];
[self->headerPart release];
[self->coreInfos release];
[super dealloc];
return [[self mailHeaderData] length] > 0 ? YES : NO;
}
-- (NSDictionary *)mailHeader {
- // TODO: cache
+- (id)mailHeaderPart {
NGMimeMessageParser *parser;
NSData *data;
}
return self->headerPart;
}
+- (NSDictionary *)mailHeaders {
+ if (self->headers == nil)
+ self->headers = [[[self mailHeaderPart] headers] copy];
+ return self->headers;
+}
- (id)lookupInfoForBodyPart:(id)_path {
NSEnumerator *pe;
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:@"<http://"];
+}
+- (NSString *)mailingListSubscribeURL {
+ return [self scanListHeaderValue:
+ [[self mailHeaders] objectForKey:@"list-subscribe"]
+ forFieldWithPrefix:@"<http://"];
+}
+- (NSString *)mailingListUnsubscribeURL {
+ return [self scanListHeaderValue:
+ [[self mailHeaders] objectForKey:@"list-unsubscribe"]
+ forFieldWithPrefix:@"<http://"];
+}
+
/* debugging */
- (BOOL)isDebuggingEnabled {