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 <NGObjWeb/SoObject+SoDAV.h>
23 #import <NGExtensions/NSNull+misc.h>
24 #import <NGExtensions/NSObject+Logs.h>
25 #import <NGExtensions/NSString+misc.h>
26 #import <NGExtensions/NSURL+misc.h>
28 #import <SoObjects/SOGo/SOGoAuthenticator.h>
30 #import "SOGoMailManager.h"
32 #import "SOGoMailBaseObject.h"
34 @implementation SOGoMailBaseObject
37 static BOOL debugOn = YES;
40 - (id) initWithImap4URL: (NSURL *) _url
41 inContainer: (id) _container
45 n = [[_url path] lastPathComponent];
46 if ((self = [self initWithName: n inContainer:_container]))
48 imap4URL = [_url retain];
62 - (SOGoMailAccount *) mailAccountFolder
64 SOGoMailAccount *folder;
66 if ([container respondsToSelector:_cmd])
67 folder = [container mailAccountFolder];
70 [self warnWithFormat: @"weird container of mailfolder: %@",
78 - (SOGoMailAccounts *) mailAccountsFolder
81 SOGoMailAccounts *folder;
86 folderClass = NSClassFromString (@"SOGoMailAccounts");
88 while (!folder && [o isNotNull])
89 if ([o isKindOfClass: folderClass])
97 - (BOOL) isInDraftsFolder
99 return [container isInDraftsFolder];
104 - (NGImap4ConnectionManager *) mailManager
106 return [NGImap4ConnectionManager defaultConnectionManager];
109 - (NGImap4Connection *) imap4Connection
113 imap4 = [[self mailManager] connectionForURL: [self imap4URL]
114 password: [self imap4Password]];
118 [self errorWithFormat:@"Could not connect IMAP4."];
124 - (NSString *) relativeImap4Name
126 [self subclassResponsibility: _cmd];
131 - (NSURL *) baseImap4URL
135 if ([container respondsToSelector:@selector(imap4URL)])
136 url = [container imap4URL];
139 [self warnWithFormat:@"container does not implement -imap4URL!"];
146 - (NSMutableString *) imap4URLString
148 NSMutableString *urlString;
151 urlString = [container imap4URLString];
152 imap4Name = [[self relativeImap4Name] stringByEscapingURL];
153 [urlString appendFormat: @"%@", imap4Name];
160 /* this could probably be handled better from NSURL but it's buggy in
163 imap4URL = [[NSURL alloc] initWithString: [self imap4URLString]];
168 - (NSString *) imap4Login
170 if (![container respondsToSelector:_cmd])
173 return [container imap4Login];
176 - (NSString *) imap4Password
179 Extract password from basic authentication.
181 TODO: we might want to
182 a) move the primary code to SOGoMailAccount
183 b) cache the password
186 return [[self authenticatorInContext: context] passwordInContext: context];
189 - (NSMutableString *) traversalFromMailAccount
191 NSMutableString *currentTraversal;
193 currentTraversal = [container traversalFromMailAccount];
194 if ([container isKindOfClass: [SOGoMailAccount class]])
195 [currentTraversal appendString: [self relativeImap4Name]];
197 [currentTraversal appendFormat: @"/%@", [self relativeImap4Name]];
199 return currentTraversal;
202 - (void)flushMailCaches {
203 [[self mailManager] flushCachesForURL:[self imap4URL]];
208 - (BOOL)isBodyPartKey:(NSString *)_key inContext:(id)_ctx {
210 Every key starting with a digit is consider an IMAP4 mime part key, used in
211 SOGoMailObject and SOGoMailBodyPart.
213 if ([_key length] == 0)
216 if (isdigit([_key characterAtIndex:0]))
222 - (NSArray *) aclsForUser: (NSString *) uid
227 @end /* SOGoMailBaseObject */