]> err.no Git - scalable-opengroupware.org/blob - SOGo/SoObjects/Mailer/SOGoMailAccount.m
improved WebDAV support
[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 "SOGoDraftsFolder.h"
26 #include "common.h"
27
28 @implementation SOGoMailAccount
29
30 /* listing the available folders */
31
32 - (NSArray *)toManyRelationshipKeys {
33   // TODO: hardcoded, if we want to support shared fldrs, this needs to change
34   return [NSArray arrayWithObjects:@"INBOX", @"Drafts", nil];
35 }
36
37 /* hierarchy */
38
39 - (SOGoMailAccount *)mailAccountFolder {
40   return self;
41 }
42
43 /* IMAP4 */
44
45 - (BOOL)useSSL {
46   return NO;
47 }
48
49 - (NSURL *)imap4URL {
50   /* imap://agenortest@mail.opengroupware.org/INBOX/withsubdirs/subdir1 */
51   NSString *s;
52   NSRange  r;
53
54   if (self->imap4URL != nil)
55     return self->imap4URL;
56   
57   s = [self nameInContainer];
58   r = [s rangeOfString:@"@"];
59   if (r.length == 0) {
60     [self logWithFormat:@"ERROR: missing login in account folder name: %@", s];
61     return nil;
62   }
63
64   s = [([self useSSL] ? @"imaps://" : @"imap://") stringByAppendingString:s];
65   s = [s stringByAppendingString:@"/"];
66   
67   self->imap4URL = [[NSURL alloc] initWithString:s];
68   return self->imap4URL;
69 }
70
71 /* name lookup */
72
73 - (id)lookupImap4Folder:(NSString *)_key inContext:(id)_ctx {
74   return [[[SOGoMailFolder alloc] initWithName:_key 
75                                   inContainer:self] autorelease];
76 }
77
78 - (id)lookupDraftsFolder:(NSString *)_key inContext:(id)_ctx {
79   return [[[SOGoDraftsFolder alloc] initWithName:_key 
80                                     inContainer:self] autorelease];
81 }
82
83 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
84   id obj;
85   
86   /* first check attributes directly bound to the application */
87   if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]) != nil)
88     return obj;
89   
90   if ([_key isEqualToString:@"Drafts"]) {
91     if ((obj = [self lookupDraftsFolder:_key inContext:_ctx]) != nil)
92       return obj;
93   }
94   
95   if ((obj = [self lookupImap4Folder:_key inContext:_ctx]) != nil)
96     return obj;
97   
98   /* return 404 to stop acquisition */
99   return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
100 }
101
102 /* WebDAV */
103
104 - (BOOL)davIsCollection {
105   return YES;
106 }
107
108 - (NSString *)shortTitle {
109   NSString *s, *login, *host;
110   NSRange r;
111
112   s = [self nameInContainer];
113   
114   r = [s rangeOfString:@"@"];
115   if (r.length > 0) {
116     login = [s substringToIndex:r.location];
117     host  = [s substringFromIndex:(r.location + r.length)];
118   }
119   else {
120     login = nil;
121     host  = s;
122   }
123   
124   r = [host rangeOfString:@"."];
125   if (r.length > 0)
126     host = [host substringToIndex:r.location];
127   
128   if ([login length] == 0)
129     return host;
130   
131   return [NSString stringWithFormat:@"%@ (%@)", host, login];
132 }
133
134 - (NSString *)davDisplayName {
135   return [self shortTitle];
136 }
137
138 @end /* SOGoMailAccount */