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 #include "SOGoMailBaseObject.h"
23 #include "SOGoMailManager.h"
25 #include <NGObjWeb/SoObject+SoDAV.h>
26 #include <NGObjWeb/SoHTTPAuthenticator.h>
27 #include <NGExtensions/NSURL+misc.h>
29 @implementation SOGoMailBaseObject
32 return [super version] + 1 /* v1 */;
35 NSAssert2([super version] == 0,
36 @"invalid superclass (%@) version %i !",
37 NSStringFromClass([self superclass]), [super version]);
41 static BOOL debugOn = YES;
44 - (id)initWithImap4URL:(NSURL *)_url inContainer:(id)_container {
47 n = [[_url path] lastPathComponent];
48 if ((self = [self initWithName:n inContainer:_container])) {
49 self->imap4URL = [_url retain];
55 [self->imap4URL release];
61 - (SOGoMailAccount *)mailAccountFolder {
62 if (![[self container] respondsToSelector:_cmd]) {
63 [self warnWithFormat:@"weird container of mailfolder: %@",
68 return [[self container] mailAccountFolder];
71 - (SOGoMailAccounts *)mailAccountsFolder {
74 for (o = [self container]; [o isNotNull]; o = [o container]) {
75 if ([o isKindOfClass:NSClassFromString(@"SOGoMailAccounts")])
83 - (NGImap4ConnectionManager *)mailManager {
84 return [NGImap4ConnectionManager defaultConnectionManager];
86 - (NGImap4Connection *)imap4Connection {
87 if (self->imap4 == nil) {
88 self->imap4 = [[[self mailManager] connectionForURL:[self imap4URL]
89 password:[self imap4Password]] retain];
90 if (self->imap4 == nil) {
91 [self errorWithFormat:@"Could not connect IMAP4."];
92 self->imap4 = [[NSNull null] retain];
95 return [self->imap4 isNotNull] ? self->imap4 : nil;
98 - (NSString *)relativeImap4Name {
99 [self warnWithFormat:@"subclass should override %@",
100 NSStringFromSelector(_cmd)];
103 - (NSURL *)baseImap4URL {
104 if (![[self container] respondsToSelector:@selector(imap4URL)]) {
105 [self warnWithFormat:@"container does not implement -imap4URL!"];
109 return [[self container] imap4URL];
111 - (NSURL *)imap4URL {
115 if (self->imap4URL != nil)
116 return self->imap4URL;
118 if ((sn = [self relativeImap4Name]) == nil)
121 if (![[self container] respondsToSelector:_cmd]) {
122 [self warnWithFormat:@"container does not implement -imap4URL!"];
126 if ((base = [self baseImap4URL]) == nil)
129 sn = [[base path] stringByAppendingPathComponent:sn];
130 self->imap4URL = [[NSURL alloc] initWithString:sn relativeToURL:base];
131 return self->imap4URL;
134 - (NSString *)imap4Login {
135 if (![[self container] respondsToSelector:_cmd])
138 return [[self container] imap4Login];
140 - (NSString *)imap4Password {
142 Extract password from basic authentication.
144 TODO: we might want to
145 a) move the primary code to SOGoMailAccount
146 b) cache the password
152 rq = [context request];
153 if ((auth = [rq headerForKey:@"authorization"]) == nil) {
158 creds = [SoHTTPAuthenticator parseCredentials:auth];
159 if ([creds count] < 2)
160 /* somehow invalid */
163 return [creds objectAtIndex:1]; /* the password */
166 - (void)flushMailCaches {
167 [[self mailManager] flushCachesForURL:[self imap4URL]];
172 - (BOOL)isBodyPartKey:(NSString *)_key inContext:(id)_ctx {
174 Every key starting with a digit is consider an IMAP4 mime part key, used in
175 SOGoMailObject and SOGoMailBodyPart.
177 if ([_key length] == 0)
180 if (isdigit([_key characterAtIndex:0]))
186 - (NSArray *) aclsForUser: (NSString *) uid
191 @end /* SOGoMailBaseObject */