sogo/SoObjects/Mailer/SOGoUser+Mail.m
Wolfgang Sourdeau 04afaf5430 Monotone-Parent: 1a8298d1520d86d2ba9068bd72abcf7073aa20a8
Monotone-Revision: e9bc6cb46a4431aee9c0112701adef16e8fde065

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2007-05-09T18:25:51
Monotone-Branch: ca.inverse.sogo
2007-05-09 18:25:51 +00:00

140 lines
4.1 KiB
Objective-C

/*
Copyright (C) 2004-2005 SKYRIX Software AG
This file is part of OpenGroupware.org.
OGo is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with OGo; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#include "SOGoUser+Mail.h"
#include "SOGoMailIdentity.h"
#include "common.h"
@implementation SOGoUser(Mail)
- (NSString *)agenorSentFolderName {
/* Note: specialty: the Sent folder is called the same in all accounts */
static NSString *s = nil;
if (s == nil) {
NSUserDefaults *ud;
ud = [NSUserDefaults standardUserDefaults];
s = [[ud stringForKey:@"SOGoSentFolderName"] copy];
if (![s isNotEmpty]) s = @"Sent";
[self logWithFormat:@"Note: using SOGoSentFolderName: '%@'", s];
}
return s;
}
- (NSString *)agenorSentFolderForAccount:(NSString *)_account {
// TODO: support different locations for shares!
NSString *p;
if (![_account isNotEmpty])
return nil;
// if ([_account rangeOfString:@".-."].length == 0)
// TODO: check whether we need special handling for shares!
p = [_account stringByAppendingString:@"/"];
p = [p stringByAppendingString:[self agenorSentFolderName]];
return p;
}
- (SOGoMailIdentity *)primaryMailIdentity {
SOGoMailIdentity *identity;
NSString *account;
account = [self valueForKey:@"primaryIMAP4AccountString"];
identity = [[[SOGoMailIdentity alloc] init] autorelease];
[identity setName: [self cn]];
[identity setEmail: [self primaryEmail]];
[identity setSentFolderName:[self agenorSentFolderForAccount:account]];
return identity;
}
- (SOGoMailIdentity *)mailIdentityForAccount:(NSString *)_account
emitter:(NSString *)_em
{
SOGoMailIdentity *identity;
identity = [[[SOGoMailIdentity alloc] init] autorelease];
[identity setName:[self cn]]; // TODO: should we use something else?
if ([_em isNotEmpty]) [identity setEmail:_em];
[identity setSentFolderName:[self agenorSentFolderForAccount:_account]];
return identity;
}
- (NSArray *)fetchAllMailIdentitiesWithOnlyEmitterAccess:(BOOL)_onlyGC {
NSMutableArray *identities;
NSEnumerator *accounts;
NSDictionary *shares;
NSString *account;
id identity;
identity = [self primaryMailIdentity];
shares = [self valueForKey:@"additionalIMAP4AccountsAndEMails"];
if ([shares count] == 0)
return [NSArray arrayWithObject: identity];
identities = [NSMutableArray arrayWithCapacity:[shares count] + 1];
if (identity != nil) [identities addObject:identity];
accounts = [shares keyEnumerator];
while ((account = [accounts nextObject]) != nil) {
NSString *emitter;
emitter = [shares objectForKey:account];
if (_onlyGC && ![emitter isNotNull]) continue;
identity = [self mailIdentityForAccount:account emitter:emitter];
if (identity != nil)
[identities addObject:identity];
}
return identities;
}
- (SOGoMailIdentity *)primaryMailIdentityForAccount:(NSString *)_account {
NSEnumerator *accounts;
NSDictionary *shares;
NSString *account;
id identity;
identity = [self primaryMailIdentity];
shares = [self valueForKey:@"additionalIMAP4AccountsAndEMails"];
if ([shares count] == 0)
return identity;
/* scan shares for ID */
accounts = [shares keyEnumerator];
while ((account = [accounts nextObject]) != nil) {
NSString *emitter;
if (![account isEqualToString:_account])
continue;
emitter = [shares objectForKey:account];
identity = [self mailIdentityForAccount:_account emitter:emitter];
if ([identity isNotNull])
return identity;
}
return identity;
}
@end /* SOGoUser(Mail) */