]> err.no Git - scalable-opengroupware.org/blob - SOGo/SoObjects/Mailer/SOGoMailFolder.m
work on the mailer
[scalable-opengroupware.org] / SOGo / SoObjects / Mailer / SOGoMailFolder.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$
22
23 #include "SOGoMailFolder.h"
24 #include "SOGoMailObject.h"
25 #include "common.h"
26
27 @implementation SOGoMailFolder
28
29 /* IMAP4 */
30
31 - (NSString *)relativeImap4Name {
32   return [self nameInContainer];
33 }
34
35 /* name lookup */
36
37 - (BOOL)isMessageKey:(NSString *)_key inContext:(id)_ctx {
38   /*
39     Every key starting with a digit is consider an IMAP4 message key. This is
40     not entirely correct since folders could also start with a number.
41     
42     If we want to support folders beginning with numbers, we would need to
43     scan the folder list for the _key, which would make everything quite a bit
44     slower.
45     TODO: support this mode using a default.
46   */
47   if ([_key length] == 0)
48     return NO;
49   
50   if (isdigit([_key characterAtIndex:0]))
51     return YES;
52   
53   return NO;
54 }
55
56 - (id)lookupImap4Folder:(NSString *)_key inContext:(id)_ctx {
57   // TODO: we might want to check for existence prior controller creation
58   return [[[SOGoMailFolder alloc] initWithName:_key 
59                                   inContainer:self] autorelease];
60 }
61 - (id)lookupImap4Message:(NSString *)_key inContext:(id)_ctx {
62   // TODO: we might want to check for existence prior controller creation
63   return [[[SOGoMailObject alloc] initWithName:_key 
64                                   inContainer:self] autorelease];
65 }
66
67 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
68   id obj;
69   
70   /* first check attributes directly bound to the application */
71   if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]) != nil)
72     return obj;
73   
74   obj = [self isMessageKey:_key inContext:_ctx]
75     ? [self lookupImap4Message:_key inContext:_ctx]
76     : [self lookupImap4Folder:_key  inContext:_ctx];
77   if (obj != nil)
78     return obj;
79   
80   /* return 404 to stop acquisition */
81   return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
82 }
83
84 @end /* SOGoMailFolder */