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 static BOOL debugOn = YES;
35 - (id)initWithImap4URL:(NSURL *)_url inContainer:(id)_container {
38 n = [[_url path] lastPathComponent];
39 if ((self = [self initWithName:n inContainer:_container])) {
40 self->imap4URL = [_url retain];
46 [self->imap4URL release];
52 - (SOGoMailAccount *)mailAccountFolder {
53 if (![[self container] respondsToSelector:_cmd]) {
54 [self warnWithFormat:@"weird container of mailfolder: %@",
59 return [[self container] mailAccountFolder];
64 - (NGImap4ConnectionManager *)mailManager {
65 return [NGImap4ConnectionManager defaultConnectionManager];
68 - (NSString *)relativeImap4Name {
69 [self warnWithFormat:@"subclass should override %@",
70 NSStringFromSelector(_cmd)];
73 - (NSURL *)baseImap4URL {
74 if (![[self container] respondsToSelector:@selector(imap4URL)]) {
75 [self warnWithFormat:@"container does not implement -imap4URL!"];
79 return [[self container] imap4URL];
85 if (self->imap4URL != nil)
86 return self->imap4URL;
88 if ((sn = [self relativeImap4Name]) == nil)
91 if (![[self container] respondsToSelector:_cmd]) {
92 [self warnWithFormat:@"container does not implement -imap4URL!"];
96 if ((base = [self baseImap4URL]) == nil)
99 sn = [[base path] stringByAppendingPathComponent:sn];
100 self->imap4URL = [[NSURL alloc] initWithString:sn relativeToURL:base];
101 return self->imap4URL;
104 - (NSString *)imap4Login {
105 if (![[self container] respondsToSelector:_cmd])
108 return [[self container] imap4Login];
110 - (NSString *)imap4Password {
112 Extract password from basic authentication.
114 TODO: we might want to
115 a) move the primary code to SOGoMailAccount
116 b) cache the password
122 rq = [[(WOApplication *)[WOApplication application] context] request];
123 if ((auth = [rq headerForKey:@"authorization"]) == nil) {
128 creds = [SoHTTPAuthenticator parseCredentials:auth];
129 if ([creds count] < 2)
130 /* somehow invalid */
133 return [creds objectAtIndex:1]; /* the password */
136 - (NGImap4Client *)imap4ClientForURL:(NSURL *)_url password:(NSString *)_pwd {
137 return [[self mailManager] imap4ClientForURL:_url password:_pwd];
140 - (NGImap4Client *)imap4Client {
141 return [self imap4ClientForURL:[self imap4URL]
142 password:[self imap4Password]];
145 - (void)flushMailCaches {
146 [[self mailManager] flushCachesForURL:[self imap4URL]];
151 - (BOOL)isBodyPartKey:(NSString *)_key inContext:(id)_ctx {
153 Every key starting with a digit is consider an IMAP4 mime part key, used in
154 SOGoMailObject and SOGoMailBodyPart.
156 if ([_key length] == 0)
159 if (isdigit([_key characterAtIndex:0]))
167 - (NSString *)loggingPrefix {
168 /* improve perf ... */
169 return [NSString stringWithFormat:@"<0x%08X[%@]:%@>",
170 self, NSStringFromClass([self class]),
171 [self nameInContainer]];
173 @end /* SOGoMailBaseObject */