From e2fc2cf006eb410622dc21b16b60acd2b61098d3 Mon Sep 17 00:00:00 2001 From: helge Date: Tue, 19 Jul 2005 09:30:22 +0000 Subject: [PATCH] implemented Internet mail marker support in textpart git-svn-id: http://svn.opengroupware.org/SOGo/trunk@818 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/SoObjects/Mailer/ChangeLog | 5 +++ SOGo/SoObjects/Mailer/README | 4 +++ SOGo/SoObjects/Mailer/SOGoDraftObject.m | 45 +++++++++++++++++++++---- SOGo/SoObjects/Mailer/Version | 2 +- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 3684ff08..29551aee 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,5 +1,10 @@ 2005-07-19 Helge Hess + * SOGoDraftObject.m: added support for adding a marker to the textpart + of the message in case the client is accessing the server from the + Internet. The text can be specified using the + 'SOGoInternetMailSuffix' default (v0.9.110) + * v0.9.109 * added fragile base class version checks to most classes diff --git a/SOGo/SoObjects/Mailer/README b/SOGo/SoObjects/Mailer/README index 2be7a9bb..dca7ba44 100644 --- a/SOGo/SoObjects/Mailer/README +++ b/SOGo/SoObjects/Mailer/README @@ -43,3 +43,7 @@ SOGoSharedFolderName IMAP4-Name - corresponds to the Cyrus setting: sharedprefix SOGoOtherUsersFolderName IMAP4-Name - corresponds to the Cyrus setting: userprefix + +SOGoInternetMailSuffix String - suffix to add to mails sent via Internet + - eg: -SOGoInternetMailSuffix \ + '"*** This email was composed using SOGo on the public Internet ***"' diff --git a/SOGo/SoObjects/Mailer/SOGoDraftObject.m b/SOGo/SoObjects/Mailer/SOGoDraftObject.m index 60d417ba..d33367ac 100644 --- a/SOGo/SoObjects/Mailer/SOGoDraftObject.m +++ b/SOGo/SoObjects/Mailer/SOGoDraftObject.m @@ -20,6 +20,7 @@ */ #include "SOGoDraftObject.h" +#include #include #include #include @@ -34,12 +35,14 @@ @implementation SOGoDraftObject -static NGMimeType *TextPlainType = nil; -static NGMimeType *MultiMixedType = nil; -static NSString *userAgent = @"SOGoMail 1.0"; -static BOOL draftDeleteDisabled = NO; // for debugging -static BOOL debugOn = NO; -static BOOL showTextAttachmentsInline = NO; +static NGMimeType *TextPlainType = nil; +static NGMimeType *MultiMixedType = nil; +static NSString *userAgent = @"SOGoMail 1.0"; +static BOOL draftDeleteDisabled = NO; // for debugging +static BOOL debugOn = NO; +static BOOL showTextAttachmentsInline = NO; +static NSString *fromInternetSuffix = nil; +static NSData *fromInternetSuffixData = nil; + (int)version { return [super version] + 0 /* v1 */; @@ -47,7 +50,7 @@ static BOOL showTextAttachmentsInline = NO; + (void)initialize { NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - + NSAssert2([super version] == 1, @"invalid superclass (%@) version %i !", NSStringFromClass([self superclass]), [super version]); @@ -58,6 +61,15 @@ static BOOL showTextAttachmentsInline = NO; if ((draftDeleteDisabled = [ud boolForKey:@"SOGoNoDraftDeleteAfterSend"])) NSLog(@"WARNING: draft delete is disabled! (SOGoNoDraftDeleteAfterSend)"); + fromInternetSuffix = [ud stringForKey:@"SOGoInternetMailSuffix"]; + if ([fromInternetSuffix length] == 0) + NSLog(@"Note: no 'SOGoInternetMailSuffix' is configured."); + else { + fromInternetSuffix = [@"\n" stringByAppendingString:fromInternetSuffix]; + fromInternetSuffixData = + [fromInternetSuffix dataUsingEncoding:NSUTF8StringEncoding]; + } + TextPlainType = [[NGMimeType mimeType:@"text" subType:@"plain"] copy]; MultiMixedType = [[NGMimeType mimeType:@"multipart" subType:@"mixed"] copy]; } @@ -299,19 +311,38 @@ static BOOL showTextAttachmentsInline = NO; - (NGMimeMessage *)mimeMessageForContentWithHeaderMap:(NGMutableHashMap *)map { NSDictionary *lInfo; NGMimeMessage *message; + BOOL addSuffix; id body; if ((lInfo = [self fetchInfo]) == nil) return nil; + addSuffix = + [[[WOApplication application] context] isAccessFromIntranet] ? NO : YES; + if (addSuffix) + addSuffix = [fromInternetSuffix length] > 0 ? YES : NO; + [map setObject:@"text/plain" forKey:@"content-type"]; if ((body = [lInfo objectForKey:@"text"]) != nil) { if ([body isKindOfClass:[NSString class]]) { + if (addSuffix) + body = [body stringByAppendingString:fromInternetSuffix]; + /* Note: just 'utf8' is displayed wrong in Mail.app */ [map setObject:@"text/plain; charset=utf-8" forKey:@"content-type"]; body = [body dataUsingEncoding:NSUTF8StringEncoding]; } + else if ([body isKindOfClass:[NSData class]] && addSuffix) { + body = [[body mutableCopy] autorelease]; + [(NSMutableData *)body appendData:fromInternetSuffixData]; + } + else if (addSuffix) { + [self warnWithFormat:@"Note: cannot add Internet marker to body: %@", + NSStringFromClass([body class])]; + } } + else if (addSuffix) + body = fromInternetSuffixData; message = [[[NGMimeMessage alloc] initWithHeader:map] autorelease]; [message setBody:body]; diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 5443d466..e8532a11 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=109 +SUBMINOR_VERSION:=110 # v0.9.96 requires libNGMime v4.5.223 # v0.9.91 requires libNGMime v4.5.222 -- 2.39.5