2 Copyright (C) 2004-2005 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
22 #include "SOGoMailFolder.h"
23 #include "SOGoMailObject.h"
24 #include "SOGoMailManager.h"
27 @implementation SOGoMailFolder
30 [self->filenames release];
36 - (NSString *)relativeImap4Name {
37 return [self nameInContainer];
40 /* listing the available folders */
42 - (NSArray *)toManyRelationshipKeys {
43 return [[self mailManager] subfoldersForURL:[self imap4URL]
44 password:[self imap4Password]];
46 - (NSArray *)toOneRelationshipKeys {
50 if (self->filenames != nil)
51 return [self->filenames isNotNull] ? self->filenames : nil;
53 uids = [self fetchUIDsMatchingQualifier:nil sortOrdering:@"DATE"];
54 if ([uids isKindOfClass:[NSException class]])
57 if ((count = [uids count]) == 0) {
58 self->filenames = [[NSArray alloc] init];
64 keys = [[NSMutableArray alloc] initWithCapacity:count];
65 for (i = 0; i < count; i++) {
68 k = [[uids objectAtIndex:i] stringValue];
69 k = [k stringByAppendingString:@".mail"];
72 self->filenames = [keys copy];
75 return self->filenames;
80 - (NSArray *)fetchUIDsMatchingQualifier:(id)_q sortOrdering:(id)_so {
81 /* seems to return an NSArray of NSNumber's */
82 return [[self mailManager] fetchUIDsInURL:[self imap4URL]
83 qualifier:_q sortOrdering:_so
84 password:[self imap4Password]];
87 - (NSArray *)fetchUIDs:(NSArray *)_uids parts:(NSArray *)_parts {
88 return [[self mailManager] fetchUIDs:_uids inURL:[self imap4URL]
90 password:[self imap4Password]];
93 - (NSException *)postData:(NSData *)_data flags:(id)_flags {
94 return [[self mailManager] postData:_data flags:_flags
95 toFolderURL:[self imap4URL]
96 password:[self imap4Password]];
101 - (BOOL)isMessageKey:(NSString *)_key inContext:(id)_ctx {
103 Every key starting with a digit is consider an IMAP4 message key. This is
104 not entirely correct since folders could also start with a number.
106 If we want to support folders beginning with numbers, we would need to
107 scan the folder list for the _key, which would make everything quite a bit
109 TODO: support this mode using a default.
111 if ([_key length] == 0)
114 if (isdigit([_key characterAtIndex:0]))
120 - (id)lookupImap4Folder:(NSString *)_key inContext:(id)_ctx {
121 // TODO: we might want to check for existence prior controller creation
122 return [[[SOGoMailFolder alloc] initWithName:_key
123 inContainer:self] autorelease];
125 - (id)lookupImap4Message:(NSString *)_key inContext:(id)_ctx {
126 // TODO: we might want to check for existence prior controller creation
127 return [[[SOGoMailObject alloc] initWithName:_key
128 inContainer:self] autorelease];
131 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
134 /* first check attributes directly bound to the application */
135 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]) != nil)
138 obj = [self isMessageKey:_key inContext:_ctx]
139 ? [self lookupImap4Message:_key inContext:_ctx]
140 : [self lookupImap4Folder:_key inContext:_ctx];
144 /* return 404 to stop acquisition */
145 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
150 - (BOOL)davIsCollection {
154 - (NSException *)davCreateCollection:(NSString *)_name inContext:(id)_ctx {
155 return [[self mailManager] createMailbox:_name atURL:[self imap4URL]
156 password:[self imap4Password]];
159 - (id)DELETEAction:(id)_ctx {
162 result = [[self mailManager] deleteMailboxAtURL:[self imap4URL]
163 password:[self imap4Password]];
167 return [NSNumber numberWithBool:YES];
170 @end /* SOGoMailFolder */