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 "SOGoDraftsFolder.h"
28 @implementation SOGoMailAccount
30 /* listing the available folders */
32 - (NSArray *)toManyRelationshipKeys {
33 // TODO: hardcoded, if we want to support shared fldrs, this needs to change
34 return [NSArray arrayWithObjects:@"INBOX", @"Drafts", nil];
39 - (SOGoMailAccount *)mailAccountFolder {
50 /* imap://agenortest@mail.opengroupware.org/INBOX/withsubdirs/subdir1 */
54 if (self->imap4URL != nil)
55 return self->imap4URL;
57 s = [self nameInContainer];
58 r = [s rangeOfString:@"@"];
60 [self logWithFormat:@"ERROR: missing login in account folder name: %@", s];
64 s = [([self useSSL] ? @"imaps://" : @"imap://") stringByAppendingString:s];
65 s = [s stringByAppendingString:@"/"];
67 self->imap4URL = [[NSURL alloc] initWithString:s];
68 return self->imap4URL;
73 - (id)lookupImap4Folder:(NSString *)_key inContext:(id)_ctx {
74 return [[[SOGoMailFolder alloc] initWithName:_key
75 inContainer:self] autorelease];
78 - (id)lookupDraftsFolder:(NSString *)_key inContext:(id)_ctx {
79 return [[[SOGoDraftsFolder alloc] initWithName:_key
80 inContainer:self] autorelease];
83 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
86 /* first check attributes directly bound to the application */
87 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]) != nil)
90 if ([_key isEqualToString:@"Drafts"]) {
91 if ((obj = [self lookupDraftsFolder:_key inContext:_ctx]) != nil)
95 if ((obj = [self lookupImap4Folder:_key inContext:_ctx]) != nil)
98 /* return 404 to stop acquisition */
99 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
104 - (NSString *)shortTitle {
105 NSString *s, *login, *host;
108 s = [self nameInContainer];
110 r = [s rangeOfString:@"@"];
112 login = [s substringToIndex:r.location];
113 host = [s substringFromIndex:(r.location + r.length)];
120 r = [host rangeOfString:@"."];
122 host = [host substringToIndex:r.location];
124 if ([login length] == 0)
127 return [NSString stringWithFormat:@"%@ (%@)", host, login];
130 - (NSString *)davDisplayName {
131 return [self shortTitle];
134 @end /* SOGoMailAccount */