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
23 #include "SOGoMailFolder.h"
24 #include "SOGoMailObject.h"
25 #include "SOGoMailManager.h"
28 @implementation SOGoMailFolder
31 [self->filenames release];
37 - (NSString *)relativeImap4Name {
38 return [self nameInContainer];
41 /* listing the available folders */
43 - (NSArray *)toManyRelationshipKeys {
44 return [[self mailManager] subfoldersForURL:[self imap4URL]
45 password:[self imap4Password]];
47 - (NSArray *)toOneRelationshipKeys {
51 if (self->filenames != nil)
52 return [self->filenames isNotNull] ? self->filenames : nil;
54 uids = [self fetchUIDsMatchingQualifier:nil sortOrdering:@"DATE"];
55 if ([uids isKindOfClass:[NSException class]])
58 if ((count = [uids count]) == 0) {
59 self->filenames = [[NSArray alloc] init];
65 keys = [[NSMutableArray alloc] initWithCapacity:count];
66 for (i = 0; i < count; i++) {
69 k = [[uids objectAtIndex:i] stringValue];
70 k = [k stringByAppendingString:@".mail"];
73 self->filenames = [keys copy];
76 return self->filenames;
81 - (NSArray *)fetchUIDsMatchingQualifier:(id)_q sortOrdering:(id)_so {
82 /* seems to return an NSArray of NSNumber's */
83 return [[self mailManager] fetchUIDsInURL:[self imap4URL]
84 qualifier:_q sortOrdering:_so
85 password:[self imap4Password]];
88 - (NSArray *)fetchUIDs:(NSArray *)_uids parts:(NSArray *)_parts {
89 return [[self mailManager] fetchUIDs:_uids inURL:[self imap4URL]
91 password:[self imap4Password]];
96 - (BOOL)isMessageKey:(NSString *)_key inContext:(id)_ctx {
98 Every key starting with a digit is consider an IMAP4 message key. This is
99 not entirely correct since folders could also start with a number.
101 If we want to support folders beginning with numbers, we would need to
102 scan the folder list for the _key, which would make everything quite a bit
104 TODO: support this mode using a default.
106 if ([_key length] == 0)
109 if (isdigit([_key characterAtIndex:0]))
115 - (id)lookupImap4Folder:(NSString *)_key inContext:(id)_ctx {
116 // TODO: we might want to check for existence prior controller creation
117 return [[[SOGoMailFolder alloc] initWithName:_key
118 inContainer:self] autorelease];
120 - (id)lookupImap4Message:(NSString *)_key inContext:(id)_ctx {
121 // TODO: we might want to check for existence prior controller creation
122 return [[[SOGoMailObject alloc] initWithName:_key
123 inContainer:self] autorelease];
126 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
129 /* first check attributes directly bound to the application */
130 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]) != nil)
133 obj = [self isMessageKey:_key inContext:_ctx]
134 ? [self lookupImap4Message:_key inContext:_ctx]
135 : [self lookupImap4Folder:_key inContext:_ctx];
139 /* return 404 to stop acquisition */
140 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
145 - (BOOL)davIsCollection {
149 - (NSException *)davCreateCollection:(NSString *)_name inContext:(id)_ctx {
150 return [[self mailManager] createMailbox:_name atURL:[self imap4URL]
151 password:[self imap4Password]];
154 - (id)DELETEAction:(id)_ctx {
157 result = [[self mailManager] deleteMailboxAtURL:[self imap4URL]
158 password:[self imap4Password]];
162 return [NSNumber numberWithBool:YES];
165 @end /* SOGoMailFolder */