2 Copyright (C) 2004 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
23 #include "SOGoMailBaseObject.h"
24 #include "SOGoMailManager.h"
26 #include <NGObjWeb/SoObject+SoDAV.h>
27 #include <NGObjWeb/SoHTTPAuthenticator.h>
28 #include <NGExtensions/NSURL+misc.h>
30 @implementation SOGoMailBaseObject
33 static BOOL debugOn = YES;
36 - (id)initWithImap4URL:(NSURL *)_url inContainer:(id)_container {
39 n = [[_url path] lastPathComponent];
40 if ((self = [self initWithName:n inContainer:_container])) {
41 self->imap4URL = [_url retain];
47 [self->imap4URL release];
53 - (SOGoMailAccount *)mailAccountFolder {
54 if (![[self container] respondsToSelector:_cmd]) {
55 [self warnWithFormat:@"weird container of mailfolder: %@",
60 return [[self container] mailAccountFolder];
65 - (SOGoMailManager *)mailManager {
66 return [SOGoMailManager defaultMailManager];
69 - (NSString *)relativeImap4Name {
70 [self warnWithFormat:@"subclass should override %@",
71 NSStringFromSelector(_cmd)];
74 - (NSURL *)baseImap4URL {
75 if (![[self container] respondsToSelector:@selector(imap4URL)]) {
76 [self warnWithFormat:@"container does not implement -imap4URL!"];
80 return [[self container] imap4URL];
86 if (self->imap4URL != nil)
87 return self->imap4URL;
89 if ((sn = [self relativeImap4Name]) == nil)
92 if (![[self container] respondsToSelector:_cmd]) {
93 [self warnWithFormat:@"container does not implement -imap4URL!"];
97 if ((base = [self baseImap4URL]) == nil)
100 sn = [[base path] stringByAppendingPathComponent:sn];
101 self->imap4URL = [[NSURL alloc] initWithString:sn relativeToURL:base];
102 return self->imap4URL;
105 - (NSString *)imap4FolderName {
106 return [[self mailManager] imap4FolderNameForURL:[self imap4URL]];
109 - (NSString *)imap4Password {
111 Extract password from basic authentication.
113 TODO: we might want to
114 a) move the primary code to SOGoMailAccount
115 b) cache the password
121 rq = [[(WOApplication *)[WOApplication application] context] request];
122 if ((auth = [rq headerForKey:@"authorization"]) == nil) {
127 creds = [SoHTTPAuthenticator parseCredentials:auth];
128 if ([creds count] < 2)
129 /* somehow invalid */
132 return [creds objectAtIndex:1]; /* the password */
135 - (NGImap4Client *)imap4ClientForURL:(NSURL *)_url password:(NSString *)_pwd {
136 return [[self mailManager] imap4ClientForURL:_url password:_pwd];
139 - (NGImap4Client *)imap4Client {
140 return [self imap4ClientForURL:[self imap4URL]
141 password:[self imap4Password]];
144 - (void)flushMailCaches {
145 [[self mailManager] flushCachesForURL:[self imap4URL]];
150 - (NSString *)loggingPrefix {
151 /* improve perf ... */
152 return [NSString stringWithFormat:@"<0x%08X[%@]:%@>",
153 self, NSStringFromClass([self class]),
154 [self nameInContainer]];
156 @end /* SOGoMailBaseObject */