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 - (SOGoMailManager *)mailManager {
65 return [SOGoMailManager defaultMailManager];
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 *)imap4FolderName {
105 return [[self mailManager] imap4FolderNameForURL:[self imap4URL]];
108 - (NSString *)imap4Password {
110 Extract password from basic authentication.
112 TODO: we might want to
113 a) move the primary code to SOGoMailAccount
114 b) cache the password
120 rq = [[(WOApplication *)[WOApplication application] context] request];
121 if ((auth = [rq headerForKey:@"authorization"]) == nil) {
126 creds = [SoHTTPAuthenticator parseCredentials:auth];
127 if ([creds count] < 2)
128 /* somehow invalid */
131 return [creds objectAtIndex:1]; /* the password */
134 - (NGImap4Client *)imap4ClientForURL:(NSURL *)_url password:(NSString *)_pwd {
135 return [[self mailManager] imap4ClientForURL:_url password:_pwd];
138 - (NGImap4Client *)imap4Client {
139 return [self imap4ClientForURL:[self imap4URL]
140 password:[self imap4Password]];
143 - (void)flushMailCaches {
144 [[self mailManager] flushCachesForURL:[self imap4URL]];
149 - (NSString *)loggingPrefix {
150 /* improve perf ... */
151 return [NSString stringWithFormat:@"<0x%08X[%@]:%@>",
152 self, NSStringFromClass([self class]),
153 [self nameInContainer]];
155 @end /* SOGoMailBaseObject */