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 return [NSArray arrayWithObjects:@"INBOX", @"Drafts", nil];
40 - (SOGoMailAccount *)mailAccountFolder {
44 - (NSArray *)allFolderPathes {
47 pathes = [[self mailManager] allFoldersForURL:[self imap4URL]
48 password:[self imap4Password]];
49 pathes = [pathes sortedArrayUsingSelector:@selector(compare:)];
60 /* imap://agenortest@mail.opengroupware.org/INBOX/withsubdirs/subdir1 */
64 if (self->imap4URL != nil)
65 return self->imap4URL;
67 s = [self nameInContainer];
68 r = [s rangeOfString:@"@"];
70 [self logWithFormat:@"ERROR: missing login in account folder name: %@", s];
74 s = [([self useSSL] ? @"imaps://" : @"imap://") stringByAppendingString:s];
75 s = [s stringByAppendingString:@"/"];
77 self->imap4URL = [[NSURL alloc] initWithString:s];
78 return self->imap4URL;
83 - (id)lookupImap4Folder:(NSString *)_key inContext:(id)_ctx {
84 return [[[SOGoMailFolder alloc] initWithName:_key
85 inContainer:self] autorelease];
88 - (id)lookupDraftsFolder:(NSString *)_key inContext:(id)_ctx {
89 return [[[SOGoDraftsFolder alloc] initWithName:_key
90 inContainer:self] autorelease];
93 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
96 /* first check attributes directly bound to the application */
97 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]) != nil)
100 if ([_key isEqualToString:@"Drafts"]) {
101 if ((obj = [self lookupDraftsFolder:_key inContext:_ctx]) != nil)
105 if ((obj = [self lookupImap4Folder:_key inContext:_ctx]) != nil)
108 /* return 404 to stop acquisition */
109 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
114 - (BOOL)davIsCollection {
118 - (NSString *)shortTitle {
119 NSString *s, *login, *host;
122 s = [self nameInContainer];
124 r = [s rangeOfString:@"@"];
126 login = [s substringToIndex:r.location];
127 host = [s substringFromIndex:(r.location + r.length)];
134 r = [host rangeOfString:@"."];
136 host = [host substringToIndex:r.location];
138 if ([login length] == 0)
141 return [NSString stringWithFormat:@"%@ (%@)", host, login];
144 - (NSString *)davDisplayName {
145 return [self shortTitle];
148 @end /* SOGoMailAccount */