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
21 // $Id: SOGoMailAccount.m 274 2004-08-26 13:10:49Z znek $
23 #include "SOGoMailAccount.h"
24 #include "SOGoMailFolder.h"
25 #include "SOGoMailManager.h"
26 #include "SOGoDraftsFolder.h"
29 @implementation SOGoMailAccount
31 /* listing the available folders */
33 - (NSArray *)toManyRelationshipKeys {
34 // TODO: hardcoded, if we want to support shared fldrs, this needs to change
35 static NSArray *accFolderNames = nil;
36 if (accFolderNames == nil) {
37 accFolderNames = [[NSArray alloc] initWithObjects:
38 @"INBOX", @"Drafts", @"Filters", nil];
40 return accFolderNames;
45 - (SOGoMailAccount *)mailAccountFolder {
49 - (NSArray *)allFolderPathes {
52 pathes = [[self mailManager] allFoldersForURL:[self imap4URL]
53 password:[self imap4Password]];
54 pathes = [pathes sortedArrayUsingSelector:@selector(compare:)];
65 /* imap://agenortest@mail.opengroupware.org/INBOX/withsubdirs/subdir1 */
69 if (self->imap4URL != nil)
70 return self->imap4URL;
72 s = [self nameInContainer];
73 r = [s rangeOfString:@"@"];
75 [self logWithFormat:@"ERROR: missing login in account folder name: %@", s];
79 s = [([self useSSL] ? @"imaps://" : @"imap://") stringByAppendingString:s];
80 s = [s stringByAppendingString:@"/"];
82 self->imap4URL = [[NSURL alloc] initWithString:s];
83 return self->imap4URL;
88 - (id)lookupFolder:(NSString *)_key ofClassNamed:(NSString *)_cn
93 if ((clazz = NSClassFromString(_cn)) == Nil) {
94 [self logWithFormat:@"ERROR: did not find class '%@' for key: '%@'",
96 return [NSException exceptionWithHTTPStatus:500 /* server error */
97 reason:@"did not find mail folder class!"];
99 return [[[clazz alloc] initWithName:_key inContainer:self] autorelease];
102 - (id)lookupImap4Folder:(NSString *)_key inContext:(id)_cx {
103 return [self lookupFolder:_key ofClassNamed:@"SOGoMailFolder" inContext:_cx];
105 - (id)lookupDraftsFolder:(NSString *)_key inContext:(id)_ctx {
106 return [self lookupFolder:_key ofClassNamed:@"SOGoDraftsFolder"
109 - (id)lookupFiltersFolder:(NSString *)_key inContext:(id)_ctx {
110 return [self lookupFolder:_key ofClassNamed:@"SOGoSieveScriptsFolder"
114 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
117 /* first check attributes directly bound to the application */
118 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]) != nil)
121 // TODO: those should be product.plist bindings? (can't be class bindings
122 // though because they are 'per-account')
123 if ([_key isEqualToString:@"Drafts"]) {
124 if ((obj = [self lookupDraftsFolder:_key inContext:_ctx]) != nil)
127 if ([_key isEqualToString:@"Filters"]) {
128 if ((obj = [self lookupFiltersFolder:_key inContext:_ctx]) != nil)
132 if ((obj = [self lookupImap4Folder:_key inContext:_ctx]) != nil)
135 /* return 404 to stop acquisition */
136 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
141 - (BOOL)davIsCollection {
145 - (NSString *)shortTitle {
146 NSString *s, *login, *host;
149 s = [self nameInContainer];
151 r = [s rangeOfString:@"@"];
153 login = [s substringToIndex:r.location];
154 host = [s substringFromIndex:(r.location + r.length)];
161 r = [host rangeOfString:@"."];
163 host = [host substringToIndex:r.location];
165 if ([login length] == 0)
168 return [NSString stringWithFormat:@"%@ (%@)", host, login];
171 - (NSString *)davDisplayName {
172 return [self shortTitle];
175 @end /* SOGoMailAccount */