2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <Foundation/NSArray.h>
23 #import <Foundation/NSUserDefaults.h>
24 #import <Foundation/NSKeyValueCoding.h>
26 #import <NGExtensions/NSNull+misc.h>
27 #import <NGExtensions/NSObject+Logs.h>
29 #import "SOGoMailIdentity.h"
31 #import "SOGoUser+Mail.h"
33 @implementation SOGoUser(Mail)
35 - (NSString *)agenorSentFolderName {
36 /* Note: specialty: the Sent folder is called the same in all accounts */
37 static NSString *s = nil;
41 ud = [NSUserDefaults standardUserDefaults];
42 s = [[ud stringForKey:@"SOGoSentFolderName"] copy];
43 if (![s isNotEmpty]) s = @"Sent";
44 [self logWithFormat:@"Note: using SOGoSentFolderName: '%@'", s];
49 - (NSString *)agenorSentFolderForAccount:(NSString *)_account {
50 // TODO: support different locations for shares!
53 if (![_account isNotEmpty])
56 // if ([_account rangeOfString:@".-."].length == 0)
57 // TODO: check whether we need special handling for shares!
58 p = [_account stringByAppendingString:@"/"];
59 p = [p stringByAppendingString:[self agenorSentFolderName]];
63 - (SOGoMailIdentity *)primaryMailIdentity {
64 SOGoMailIdentity *identity;
67 account = [self valueForKey:@"primaryIMAP4AccountString"];
69 identity = [[[SOGoMailIdentity alloc] init] autorelease];
70 [identity setName: [self cn]];
71 [identity setEmail: [self primaryEmail]];
72 [identity setSentFolderName:[self agenorSentFolderForAccount:account]];
76 - (SOGoMailIdentity *)mailIdentityForAccount:(NSString *)_account
77 emitter:(NSString *)_em
79 SOGoMailIdentity *identity;
81 identity = [[[SOGoMailIdentity alloc] init] autorelease];
82 [identity setName:[self cn]]; // TODO: should we use something else?
83 if ([_em isNotEmpty]) [identity setEmail:_em];
84 [identity setSentFolderName:[self agenorSentFolderForAccount:_account]];
88 - (NSArray *)fetchAllMailIdentitiesWithOnlyEmitterAccess:(BOOL)_onlyGC {
89 NSMutableArray *identities;
90 NSEnumerator *accounts;
95 identity = [self primaryMailIdentity];
96 shares = [self valueForKey:@"additionalIMAP4AccountsAndEMails"];
97 if ([shares count] == 0)
98 return [NSArray arrayWithObject: identity];
100 identities = [NSMutableArray arrayWithCapacity:[shares count] + 1];
101 if (identity != nil) [identities addObject:identity];
103 accounts = [shares keyEnumerator];
104 while ((account = [accounts nextObject]) != nil) {
107 emitter = [shares objectForKey:account];
108 if (_onlyGC && ![emitter isNotNull]) continue;
110 identity = [self mailIdentityForAccount:account emitter:emitter];
112 [identities addObject:identity];
118 - (SOGoMailIdentity *)primaryMailIdentityForAccount:(NSString *)_account {
119 NSEnumerator *accounts;
120 NSDictionary *shares;
124 identity = [self primaryMailIdentity];
125 shares = [self valueForKey:@"additionalIMAP4AccountsAndEMails"];
126 if ([shares count] == 0)
129 /* scan shares for ID */
130 accounts = [shares keyEnumerator];
131 while ((account = [accounts nextObject]) != nil) {
134 if (![account isEqualToString:_account])
137 emitter = [shares objectForKey:account];
138 identity = [self mailIdentityForAccount:_account emitter:emitter];
139 if ([identity isNotNull])
146 @end /* SOGoUser(Mail) */