From 5fb9dad9c635d12a7478d31643090217baa05943 Mon Sep 17 00:00:00 2001 From: helge Date: Fri, 22 Jul 2005 12:06:48 +0000 Subject: [PATCH] added identity based Sent-folder functionality git-svn-id: http://svn.opengroupware.org/SOGo/trunk@893 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/UI/MailerUI/ChangeLog | 6 ++ SOGo/UI/MailerUI/README | 5 ++ SOGo/UI/MailerUI/UIxMailEditor.m | 97 ++++++++++++++++++++-- SOGo/UI/MailerUI/Version | 2 +- SOGo/UI/Templates/MailerUI/UIxMailView.wox | 1 - 5 files changed, 102 insertions(+), 9 deletions(-) diff --git a/SOGo/UI/MailerUI/ChangeLog b/SOGo/UI/MailerUI/ChangeLog index 61cd65ff..5e834faf 100644 --- a/SOGo/UI/MailerUI/ChangeLog +++ b/SOGo/UI/MailerUI/ChangeLog @@ -1,3 +1,9 @@ +2005-07-22 Helge Hess + + * UIxMailEditor.m: implemented identity based Sent folders (tied to + 'from' email address). The old url-attached Sent folder can be + enabled using 'SOGoUseLocationBasedSentFolder') (v0.9.168) + 2005-07-21 Helge Hess * UIxMailMainFrame.m: fixed banner positioning for 24x24 (v0.9.167) diff --git a/SOGo/UI/MailerUI/README b/SOGo/UI/MailerUI/README index b35646b6..0bc4b41b 100644 --- a/SOGo/UI/MailerUI/README +++ b/SOGo/UI/MailerUI/README @@ -94,6 +94,11 @@ SOGoDontUseETagsForMailViewer - YES|NO IDs in the IMAP4 server and messages cannot be edited in IMAP4 - use the default for debugging (otherwise you won't see changes ...) +SOGoUseLocationBasedSentFolder - YES | NO +- when enable SOGo looks up the Sent folder by traversing the lookup-path + until it finds a SOGoMailAccount object and then asks the account for the + Sent folder. + Notes ===== diff --git a/SOGo/UI/MailerUI/UIxMailEditor.m b/SOGo/UI/MailerUI/UIxMailEditor.m index fc513515..35d55769 100644 --- a/SOGo/UI/MailerUI/UIxMailEditor.m +++ b/SOGo/UI/MailerUI/UIxMailEditor.m @@ -51,16 +51,20 @@ #include #include #include +#include +#include #include #include #include #include +#include #include "common.h" @implementation UIxMailEditor static BOOL keepMailTmpFile = NO; static BOOL showInternetMarker = NO; +static BOOL useLocationBasedSentFolder = NO; static NSDictionary *internetMailHeaders = nil; static NSArray *infoKeys = nil; @@ -75,7 +79,10 @@ static NSArray *infoKeys = nil; keepMailTmpFile = [ud boolForKey:@"SOGoMailEditorKeepTmpFile"]; if (keepMailTmpFile) NSLog(@"WARNING: keeping mail files."); - + + useLocationBasedSentFolder = + [ud boolForKey:@"SOGoUseLocationBasedSentFolder"]; + /* Internet mail settings */ showInternetMarker = [ud boolForKey:@"SOGoShowInternetMarker"]; @@ -252,12 +259,12 @@ static NSArray *infoKeys = nil; return nil; } -- (id)lookupSentFolder { +- (id)lookupSentFolderUsingAccount { SOGoMailAccount *account; SOGoMailFolder *folder; if (self->sentFolder != nil) - return self; + return [self->sentFolder isNotNull] ? self->sentFolder : nil;; account = [[self clientObject] mailAccountFolder]; if ([account isKindOfClass:[NSException class]]) return account; @@ -267,17 +274,93 @@ static NSArray *infoKeys = nil; return ((self->sentFolder = [folder retain])); } +- (SOGoMailIdentity *)selectedMailIdentity { + SOGoMailAccounts *accounts; + NSEnumerator *e; + SOGoMailIdentity *identity; + + accounts = [[self clientObject] mailAccountsFolder]; + if ([accounts isKindOfClass:[NSException class]]) return (id)accounts; + + // TODO: This is still a hack because we detect the identity based on the + // from. In Agenor all of the identities have unique emails, but this + // is not required for SOGo. + + if ([[self from] length] == 0) + return nil; + + e = [[accounts fetchIdentitiesWithEmitterPermissions] objectEnumerator]; + while ((identity = [e nextObject]) != nil) { + if ([[identity email] isEqualToString:[self from]]) + return identity; + } + return nil; +} + +- (id)lookupSentFolderUsingFrom { + // TODO: if we have the identity we could also support BCC + SOGoMailAccounts *accounts; + SOGoMailIdentity *identity; + SoSubContext *ctx; + NSString *sentFolderName; + NSArray *sentFolderPath; + NSException *error = nil; + + if (self->sentFolder != nil) + return [self->sentFolder isNotNull] ? self->sentFolder : nil;; + + identity = [self selectedMailIdentity]; + if ([identity isKindOfClass:[NSException class]]) return identity; + + if (![(sentFolderName = [identity sentFolderName]) isNotEmpty]) { + [self warnWithFormat:@"Identity has no sent folder name: %@", identity]; + return nil; + } + + // TODO: fixme, we treat the foldername as a hardcoded path from SOGoAccounts + // TODO: escaping of foldernames with slashes + // TODO: maybe the SOGoMailIdentity should have an 'account-identifier' + // which is used to lookup the account and _then_ perform an account + // local folder lookup? => would not be possible to have identities + // saving to different accounts. + sentFolderPath = [sentFolderName componentsSeparatedByString:@"/"]; + + accounts = [[self clientObject] mailAccountsFolder]; + if ([accounts isKindOfClass:[NSException class]]) return (id)accounts; + + ctx = [[SoSubContext alloc] initWithParentContext:[self context]]; + + self->sentFolder = [[accounts traversePathArray:sentFolderPath + inContext:ctx error:&error + acquire:NO] retain]; + [ctx release]; ctx = nil; + if (error != nil) { + [self errorWithFormat:@"Sent-Folder lookup for identity %@ failed: %@", + identity, sentFolderPath]; + return error; + } + +#if 0 + [self logWithFormat:@"Sent-Folder: %@", sentFolderName]; + [self logWithFormat:@" object: %@", self->sentFolder]; +#endif + return self->sentFolder; +} + - (NSException *)storeMailInSentFolder:(NSString *)_path { SOGoMailFolder *folder; NSData *data; id result; - folder = [self lookupSentFolder]; + folder = useLocationBasedSentFolder + ? [self lookupSentFolderUsingAccount] + : [self lookupSentFolderUsingFrom]; if ([folder isKindOfClass:[NSException class]]) return (id)folder; + if (folder == nil) return nil; if ((data = [[NSData alloc] initWithContentsOfMappedFile:_path]) == nil) { return [NSException exceptionWithHTTPStatus:500 /* server error */ - reason:@"could not temporary draft file!"]; + reason:@"could not find temporary draft file!"]; } result = [folder postData:data flags:@"seen"]; @@ -401,7 +484,7 @@ static NSArray *infoKeys = nil; // TODO: all this could be handled by the SOGoDraftObject? mailPath = [[self clientObject] saveMimeMessageToTemporaryFileWithHeaders:h]; - + /* then, send mail */ if ((error = [[self clientObject] sendMimeMessageAtPath:mailPath]) != nil) { @@ -416,7 +499,7 @@ static NSArray *infoKeys = nil; return error; /* finally store in Sent */ - + if ((error = [self storeMailInSentFolder:mailPath]) != nil) return error; diff --git a/SOGo/UI/MailerUI/Version b/SOGo/UI/MailerUI/Version index 33309d94..a5e610b3 100644 --- a/SOGo/UI/MailerUI/Version +++ b/SOGo/UI/MailerUI/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=167 +SUBMINOR_VERSION:=168 # v0.9.140 requires SoObjects/Mailer v0.9.100 # v0.9.134 requires libSOGo v0.9.41 diff --git a/SOGo/UI/Templates/MailerUI/UIxMailView.wox b/SOGo/UI/Templates/MailerUI/UIxMailView.wox index 410a4b1e..94c9a839 100644 --- a/SOGo/UI/Templates/MailerUI/UIxMailView.wox +++ b/SOGo/UI/Templates/MailerUI/UIxMailView.wox @@ -150,7 +150,6 @@ -
-- 2.39.5