]> err.no Git - scalable-opengroupware.org/blob - SOGo/SoObjects/Mailer/SOGoMailAccount.m
implement folder tree navigation
[scalable-opengroupware.org] / SOGo / SoObjects / Mailer / SOGoMailAccount.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id: SOGoMailAccount.m 274 2004-08-26 13:10:49Z znek $
22
23 #include "SOGoMailAccount.h"
24 #include "SOGoMailFolder.h"
25 #include "common.h"
26
27 @implementation SOGoMailAccount
28
29 /* listing the available folders */
30
31 - (NSArray *)toManyRelationshipKeys {
32   // TODO: hardcoded, if we want to support shared folders, need to change */
33   return [NSArray arrayWithObjects:@"INBOX", nil];
34 }
35
36 /* hierarchy */
37
38 - (SOGoMailAccount *)mailAccountFolder {
39   return self;
40 }
41
42 /* IMAP4 */
43
44 - (BOOL)useSSL {
45   return NO;
46 }
47
48 - (NSURL *)imap4URL {
49   /* imap://agenortest@mail.opengroupware.org/INBOX/withsubdirs/subdir1 */
50   NSString *s;
51   NSRange  r;
52
53   if (self->imap4URL != nil)
54     return self->imap4URL;
55   
56   s = [self nameInContainer];
57   r = [s rangeOfString:@"@"];
58   if (r.length == 0) {
59     [self logWithFormat:@"ERROR: missing login in account folder name: %@", s];
60     return nil;
61   }
62
63   s = [([self useSSL] ? @"imaps://" : @"imap://") stringByAppendingString:s];
64   s = [s stringByAppendingString:@"/"];
65   
66   self->imap4URL = [[NSURL alloc] initWithString:s];
67   return self->imap4URL;
68 }
69
70 /* name lookup */
71
72 - (id)lookupImap4Folder:(NSString *)_key inContext:(id)_ctx {
73   return [[[SOGoMailFolder alloc] initWithName:_key 
74                                   inContainer:self] autorelease];
75 }
76
77 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
78   id obj;
79   
80   /* first check attributes directly bound to the application */
81   if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]) != nil)
82     return obj;
83   
84   if ((obj = [self lookupImap4Folder:_key inContext:_ctx]) != nil)
85     return obj;
86   
87   /* return 404 to stop acquisition */
88   return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
89 }
90
91 /* WebDAV */
92
93 - (NSString *)shortTitle {
94   NSString *s, *login, *host;
95   NSRange r;
96
97   s = [self nameInContainer];
98   
99   r = [s rangeOfString:@"@"];
100   if (r.length > 0) {
101     login = [s substringToIndex:r.location];
102     host  = [s substringFromIndex:(r.location + r.length)];
103   }
104   else {
105     login = nil;
106     host  = s;
107   }
108   
109   r = [host rangeOfString:@"."];
110   if (r.length > 0)
111     host = [host substringToIndex:r.location];
112   
113   if ([login length] == 0)
114     return host;
115   
116   return [NSString stringWithFormat:@"%@ (%@)", host, login];
117 }
118
119 - (NSString *)davDisplayName {
120   return [self shortTitle];
121 }
122
123 @end /* SOGoMailAccount */