From 4f29415b1ef719dfb5d2385d476e33af278e3a1b Mon Sep 17 00:00:00 2001 From: helge Date: Mon, 7 Feb 2005 13:38:38 +0000 Subject: [PATCH] added ability to process custom headers in draft object git-svn-id: http://svn.opengroupware.org/SOGo/trunk@525 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/SoObjects/Mailer/ChangeLog | 4 +++ SOGo/SoObjects/Mailer/SOGoDraftObject.h | 1 + SOGo/SoObjects/Mailer/SOGoDraftObject.m | 42 ++++++++++++++++++++----- SOGo/SoObjects/Mailer/Version | 2 +- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 2d9d7440..2cfcfb0c 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,5 +1,9 @@ 2005-02-07 Helge Hess + * v0.9.68 + + * SOGoDraftObject.m: added ability to specify additional headers + * v0.9.67 * SOGoMailFolder.m: detect special folder names and return proper diff --git a/SOGo/SoObjects/Mailer/SOGoDraftObject.h b/SOGo/SoObjects/Mailer/SOGoDraftObject.h index 0c975366..b3b635da 100644 --- a/SOGo/SoObjects/Mailer/SOGoDraftObject.h +++ b/SOGo/SoObjects/Mailer/SOGoDraftObject.h @@ -63,6 +63,7 @@ - (NGMimeMessage *)mimeMessage; - (NSString *)saveMimeMessageToTemporaryFile; +- (NSString *)saveMimeMessageToTemporaryFileWithHeaders:(NSDictionary *)_addh; - (NSException *)sendMimeMessageAtPath:(NSString *)_path; - (NSException *)sendMail; diff --git a/SOGo/SoObjects/Mailer/SOGoDraftObject.m b/SOGo/SoObjects/Mailer/SOGoDraftObject.m index 7f478265..721a48d8 100644 --- a/SOGo/SoObjects/Mailer/SOGoDraftObject.m +++ b/SOGo/SoObjects/Mailer/SOGoDraftObject.m @@ -36,6 +36,7 @@ static NGMimeType *TextPlainType = nil; static NGMimeType *MultiMixedType = nil; +static NSString *userAgent = @"SOGoMail 1.0"; static BOOL draftDeleteDisabled = NO; // for debugging static BOOL debugOn = NO; @@ -484,9 +485,25 @@ static BOOL debugOn = NO; return message; } -- (NGMutableHashMap *)mimeHeaderMap { +- (void)_addHeaders:(NSDictionary *)_h toHeaderMap:(NGMutableHashMap *)_map { + NSEnumerator *names; + NSString *name; + + if ([_h count] == 0) + return; + + names = [_h keyEnumerator]; + while ((name = [names nextObject]) != nil) { + id value; + + value = [_h objectForKey:name]; + [_map addObject:value forKey:name]; + } +} + +- (NGMutableHashMap *)mimeHeaderMapWithHeaders:(NSDictionary *)_headers { NGMutableHashMap *map; - NSDictionary *lInfo; + NSDictionary *lInfo; // TODO: this should be some kind of object? NSArray *emails; NSString *s; @@ -528,12 +545,17 @@ static BOOL debugOn = NO; [map addObject:[NSCalendarDate date] forKey:@"date"]; [map addObject:@"1.0" forKey:@"MIME-Version"]; - [map addObject:@"SOGoMail 1.0" forKey:@"X-Mailer"]; + [map addObject:userAgent forKey:@"X-Mailer"]; + + /* add custom headers */ + + [self _addHeaders:[lInfo objectForKey:@"headers"] toHeaderMap:map]; + [self _addHeaders:_headers toHeaderMap:map]; return map; } -- (NGMimeMessage *)mimeMessage { +- (NGMimeMessage *)mimeMessageWithHeaders:(NSDictionary *)_headers { NSAutoreleasePool *pool; NGMutableHashMap *map; NSArray *bodyParts; @@ -546,7 +568,7 @@ static BOOL debugOn = NO; return nil; } - if ((map = [self mimeHeaderMap]) == nil) + if ((map = [self mimeHeaderMapWithHeaders:_headers]) == nil) return nil; [self debugWithFormat:@"MIME Envelope: %@", map]; @@ -572,8 +594,11 @@ static BOOL debugOn = NO; [pool release]; return [message autorelease]; } +- (NGMimeMessage *)mimeMessage { + return [self mimeMessageWithHeaders:nil]; +} -- (NSString *)saveMimeMessageToTemporaryFile { +- (NSString *)saveMimeMessageToTemporaryFileWithHeaders:(NSDictionary *)_h { NGMimeMessageGenerator *gen; NSAutoreleasePool *pool; NGMimeMessage *message; @@ -581,7 +606,7 @@ static BOOL debugOn = NO; pool = [[NSAutoreleasePool alloc] init]; - message = [self mimeMessage]; + message = [self mimeMessageWithHeaders:_h]; if (![message isNotNull]) return nil; if ([message isKindOfClass:[NSException class]]) { @@ -596,6 +621,9 @@ static BOOL debugOn = NO; [pool release]; return [tmpPath autorelease]; } +- (NSString *)saveMimeMessageToTemporaryFile { + return [self saveMimeMessageToTemporaryFileWithHeaders:nil]; +} - (void)deleteTemporaryMessageFile:(NSString *)_path { NSFileManager *fm; diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index c5364fcf..6ce68cb9 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=67 +SUBMINOR_VERSION:=68 # v0.9.55 requires NGExtensions v4.5.136 # v0.9.44 requires libNGMime v4.3.194 -- 2.39.5