2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-10-26 16:26:01 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2007-10-26 16:26:01 +02:00
|
|
|
#import <Foundation/NSURL.h>
|
2007-05-19 02:46:16 +02:00
|
|
|
#import <Foundation/NSUserDefaults.h>
|
|
|
|
|
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
2007-10-26 16:26:01 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2007-05-19 02:46:16 +02:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSURL+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2007-05-30 22:23:54 +02:00
|
|
|
#import <NGExtensions/NSString+misc.h>
|
2007-05-19 02:46:16 +02:00
|
|
|
|
|
|
|
#import <NGImap4/NGImap4Connection.h>
|
|
|
|
#import <NGImap4/NGImap4Client.h>
|
|
|
|
|
|
|
|
#import <SoObjects/SOGo/SOGoPermissions.h>
|
2007-05-30 22:23:54 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
2007-05-19 02:46:16 +02:00
|
|
|
#import <SoObjects/SOGo/NSArray+Utilities.h>
|
|
|
|
|
|
|
|
#import "SOGoMailObject.h"
|
|
|
|
#import "SOGoMailAccount.h"
|
|
|
|
#import "SOGoMailManager.h"
|
|
|
|
#import "SOGoMailFolder.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-22 21:16:07 +02:00
|
|
|
static NSString *defaultUserID = @"anyone";
|
|
|
|
|
2008-05-31 23:04:56 +02:00
|
|
|
#warning this could be detected from the capabilities
|
|
|
|
static SOGoIMAPAclStyle aclStyle = undefined;
|
|
|
|
static BOOL aclUsernamesAreQuoted = NO;
|
|
|
|
/* http://www.tools.ietf.org/wg/imapext/draft-ietf-imapext-acl/ */
|
|
|
|
static BOOL aclConformsToIMAPExt = NO;
|
|
|
|
|
2008-08-26 20:40:48 +02:00
|
|
|
@interface NGImap4Connection (PrivateMethods)
|
|
|
|
|
|
|
|
- (NSString *) imap4FolderNameForURL: (NSURL *) url;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@implementation SOGoMailFolder
|
|
|
|
|
2008-05-31 23:04:56 +02:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud;
|
|
|
|
NSString *aclStyleStr;
|
|
|
|
|
|
|
|
if (aclStyle == undefined)
|
|
|
|
{
|
|
|
|
ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
aclStyleStr = [ud stringForKey: @"SOGoIMAPAclStyle"];
|
|
|
|
if ([aclStyleStr isEqualToString: @"rfc2086"])
|
|
|
|
aclStyle = rfc2086;
|
|
|
|
else
|
|
|
|
aclStyle = rfc4314;
|
|
|
|
|
|
|
|
aclUsernamesAreQuoted
|
|
|
|
= [ud boolForKey: @"SOGoIMAPAclUsernamesAreQuoted"];
|
|
|
|
aclConformsToIMAPExt
|
|
|
|
= [ud boolForKey: @"SOGoIMAPAclConformsToIMAPExt"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (SOGoIMAPAclStyle) imapAclStyle
|
|
|
|
{
|
|
|
|
return aclStyle;
|
|
|
|
}
|
|
|
|
|
2007-06-01 07:45:12 +02:00
|
|
|
- (void) _adjustOwner
|
|
|
|
{
|
|
|
|
SOGoMailAccount *mailAccount;
|
2007-06-05 16:59:30 +02:00
|
|
|
NSString *path, *folder;
|
2007-06-01 07:45:12 +02:00
|
|
|
NSArray *names;
|
|
|
|
|
|
|
|
mailAccount = [self mailAccountFolder];
|
|
|
|
path = [[self imap4Connection] imap4FolderNameForURL: [self imap4URL]];
|
|
|
|
|
2007-06-05 16:59:30 +02:00
|
|
|
folder = [mailAccount sharedFolderName];
|
|
|
|
if (folder && [path hasPrefix: folder])
|
2007-10-17 00:30:02 +02:00
|
|
|
[self setOwner: @"nobody"];
|
2007-06-05 16:59:30 +02:00
|
|
|
else
|
2007-06-01 07:45:12 +02:00
|
|
|
{
|
2007-06-05 16:59:30 +02:00
|
|
|
folder = [mailAccount otherUsersFolderName];
|
|
|
|
if (folder && [path hasPrefix: folder])
|
|
|
|
{
|
|
|
|
names = [path componentsSeparatedByString: @"/"];
|
|
|
|
if ([names count] > 1)
|
|
|
|
[self setOwner: [names objectAtIndex: 1]];
|
|
|
|
else
|
2007-10-17 00:30:02 +02:00
|
|
|
[self setOwner: @"nobody"];
|
2007-06-05 16:59:30 +02:00
|
|
|
}
|
2007-06-01 07:45:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithName: (NSString *) newName
|
|
|
|
inContainer: (id) newContainer
|
|
|
|
{
|
|
|
|
if ((self = [super initWithName: newName
|
|
|
|
inContainer: newContainer]))
|
|
|
|
{
|
|
|
|
[self _adjustOwner];
|
2007-08-17 04:27:35 +02:00
|
|
|
mailboxACL = nil;
|
2007-06-01 07:45:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-05-22 21:17:45 +02:00
|
|
|
[filenames release];
|
|
|
|
[folderType release];
|
2007-08-17 04:27:35 +02:00
|
|
|
[mailboxACL release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IMAP4 */
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (NSString *) relativeImap4Name
|
|
|
|
{
|
2007-08-01 20:48:37 +02:00
|
|
|
return [nameInContainer substringFromIndex: 6];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-10-22 18:07:12 +02:00
|
|
|
- (NSString *) absoluteImap4Name
|
|
|
|
{
|
|
|
|
NSString *name;
|
|
|
|
|
|
|
|
name = [[self imap4URL] path];
|
|
|
|
if (![name hasSuffix: @"/"])
|
|
|
|
name = [name stringByAppendingString: @"/"];
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
2007-08-17 04:27:35 +02:00
|
|
|
|
|
|
|
- (NSMutableString *) imap4URLString
|
|
|
|
{
|
|
|
|
NSMutableString *urlString;
|
|
|
|
|
|
|
|
urlString = [super imap4URLString];
|
|
|
|
[urlString appendString: @"/"];
|
|
|
|
|
|
|
|
return urlString;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* listing the available folders */
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (NSArray *) toManyRelationshipKeys
|
|
|
|
{
|
|
|
|
return [self subfolders];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) subfolders
|
|
|
|
{
|
|
|
|
return [[self imap4Connection] subfoldersForURL: [self imap4URL]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-07-13 00:03:05 +02:00
|
|
|
|
2007-10-31 16:55:47 +01:00
|
|
|
- (BOOL) isSpecialFolder
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2007-10-22 18:07:12 +02:00
|
|
|
- (NSArray *) allFolderPaths
|
|
|
|
{
|
|
|
|
NSMutableArray *deepSubfolders;
|
|
|
|
NSEnumerator *folderNames;
|
|
|
|
NSArray *result;
|
|
|
|
NSString *currentFolderName, *prefix;
|
|
|
|
|
|
|
|
deepSubfolders = [NSMutableArray new];
|
|
|
|
[deepSubfolders autorelease];
|
|
|
|
|
|
|
|
prefix = [self absoluteImap4Name];
|
|
|
|
|
|
|
|
result = [[self mailAccountFolder] allFolderPaths];
|
|
|
|
folderNames = [result objectEnumerator];
|
|
|
|
while ((currentFolderName = [folderNames nextObject]))
|
|
|
|
if ([currentFolderName hasPrefix: prefix])
|
|
|
|
[deepSubfolders addObject: currentFolderName];
|
|
|
|
[deepSubfolders sortUsingSelector: @selector (compare:)];
|
|
|
|
|
|
|
|
return deepSubfolders;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) allFolderURLs
|
2007-05-28 21:07:21 +02:00
|
|
|
{
|
|
|
|
NSURL *selfURL, *currentURL;
|
|
|
|
NSMutableArray *subfoldersURL;
|
|
|
|
NSEnumerator *subfolders;
|
2007-10-22 18:07:12 +02:00
|
|
|
NSString *currentFolder;
|
2007-05-28 21:07:21 +02:00
|
|
|
|
|
|
|
subfoldersURL = [NSMutableArray array];
|
|
|
|
selfURL = [self imap4URL];
|
2007-10-22 18:07:12 +02:00
|
|
|
subfolders = [[self allFolderPaths] objectEnumerator];
|
2007-05-28 21:07:21 +02:00
|
|
|
currentFolder = [subfolders nextObject];
|
|
|
|
while (currentFolder)
|
|
|
|
{
|
|
|
|
currentURL = [[NSURL alloc]
|
|
|
|
initWithScheme: [selfURL scheme]
|
|
|
|
host: [selfURL host]
|
2007-10-22 18:07:12 +02:00
|
|
|
path: currentFolder];
|
2007-05-28 21:07:21 +02:00
|
|
|
[currentURL autorelease];
|
|
|
|
[subfoldersURL addObject: currentURL];
|
|
|
|
currentFolder = [subfolders nextObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
return subfoldersURL;
|
|
|
|
}
|
|
|
|
|
2007-06-01 07:45:12 +02:00
|
|
|
- (NSString *) davContentType
|
|
|
|
{
|
|
|
|
return @"httpd/unix-directory";
|
|
|
|
}
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (NSArray *) toOneRelationshipKeys
|
|
|
|
{
|
2007-07-30 17:55:28 +02:00
|
|
|
NSArray *uids;
|
|
|
|
unsigned int count, max;
|
|
|
|
NSString *filename;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-07-30 17:55:28 +02:00
|
|
|
if (!filenames)
|
|
|
|
{
|
|
|
|
filenames = [NSMutableArray new];
|
|
|
|
uids = [self fetchUIDsMatchingQualifier: nil sortOrdering: @"DATE"];
|
|
|
|
if (![uids isKindOfClass: [NSException class]])
|
|
|
|
{
|
|
|
|
max = [uids count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
filename = [NSString stringWithFormat: @"%@.mail",
|
|
|
|
[uids objectAtIndex: count]];
|
|
|
|
[filenames addObject: filename];
|
|
|
|
}
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-07-30 17:55:28 +02:00
|
|
|
|
2007-05-22 21:17:45 +02:00
|
|
|
return filenames;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* messages */
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (NSArray *) fetchUIDsMatchingQualifier: (id) _q
|
|
|
|
sortOrdering: (id) _so
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* seems to return an NSArray of NSNumber's */
|
2007-08-17 04:27:35 +02:00
|
|
|
return [[self imap4Connection] fetchUIDsInURL: [self imap4URL]
|
|
|
|
qualifier: _q sortOrdering: _so];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (NSArray *) fetchUIDs: (NSArray *) _uids
|
|
|
|
parts: (NSArray *) _parts
|
|
|
|
{
|
2007-08-17 04:27:35 +02:00
|
|
|
return [[self imap4Connection] fetchUIDs: _uids inURL: [self imap4URL]
|
|
|
|
parts: _parts];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (NSException *) postData: (NSData *) _data
|
|
|
|
flags: (id) _flags
|
|
|
|
{
|
2007-08-17 04:27:35 +02:00
|
|
|
return [[self imap4Connection] postData: _data flags: _flags
|
|
|
|
toFolderURL: [self imap4URL]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (NSException *) expunge
|
|
|
|
{
|
|
|
|
return [[self imap4Connection] expungeAtURL: [self imap4URL]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-10-26 16:26:01 +02:00
|
|
|
- (void) markForExpunge
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud;
|
|
|
|
NSMutableDictionary *mailSettings;
|
2008-08-26 20:40:48 +02:00
|
|
|
NSString *urlString;
|
2007-10-26 16:26:01 +02:00
|
|
|
|
|
|
|
ud = [[context activeUser] userSettings];
|
|
|
|
mailSettings = [ud objectForKey: @"Mail"];
|
|
|
|
if (!mailSettings)
|
|
|
|
{
|
|
|
|
mailSettings = [NSMutableDictionary dictionaryWithCapacity: 1];
|
|
|
|
[ud setObject: mailSettings forKey: @"Mail"];
|
|
|
|
}
|
|
|
|
|
2008-08-26 20:40:48 +02:00
|
|
|
urlString = [self imap4URLString];
|
|
|
|
if (![[mailSettings objectForKey: @"folderForExpunge"]
|
|
|
|
isEqualToString: urlString])
|
|
|
|
{
|
|
|
|
[mailSettings setObject: [self imap4URLString]
|
|
|
|
forKey: @"folderForExpunge"];
|
|
|
|
[ud synchronize];
|
|
|
|
}
|
2007-10-26 16:26:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) expungeLastMarkedFolder
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud;
|
|
|
|
NSMutableDictionary *mailSettings;
|
|
|
|
NSString *expungeURL;
|
|
|
|
NSURL *folderURL;
|
|
|
|
|
|
|
|
ud = [[context activeUser] userSettings];
|
|
|
|
mailSettings = [ud objectForKey: @"Mail"];
|
|
|
|
if (mailSettings)
|
|
|
|
{
|
|
|
|
expungeURL = [mailSettings objectForKey: @"folderForExpunge"];
|
2008-09-05 15:12:58 +02:00
|
|
|
if (expungeURL
|
|
|
|
&& ![expungeURL isEqualToString: [self imap4URLString]])
|
2007-10-26 16:26:01 +02:00
|
|
|
{
|
|
|
|
folderURL = [NSURL URLWithString: expungeURL];
|
|
|
|
if (![[self imap4Connection] expungeAtURL: folderURL])
|
|
|
|
{
|
|
|
|
[mailSettings removeObjectForKey: @"folderForExpunge"];
|
|
|
|
[ud synchronize];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* flags */
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (NSException *) addFlagsToAllMessages: (id) _f
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self imap4Connection] addFlags:_f
|
2007-05-28 21:07:21 +02:00
|
|
|
toAllMessagesInURL: [self imap4URL]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* name lookup */
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (id) lookupName: (NSString *) _key
|
|
|
|
inContext: (id)_ctx
|
|
|
|
acquire: (BOOL) _acquire
|
|
|
|
{
|
2007-11-01 13:48:19 +01:00
|
|
|
NSString *folderName, *className;
|
|
|
|
SOGoMailAccount *mailAccount;
|
2006-06-15 21:34:10 +02:00
|
|
|
id obj;
|
2007-02-08 22:55:47 +01:00
|
|
|
|
2007-07-30 17:55:28 +02:00
|
|
|
if ([_key hasPrefix: @"folder"])
|
2007-11-01 13:48:19 +01:00
|
|
|
{
|
|
|
|
mailAccount = [self mailAccountFolder];
|
|
|
|
folderName = [NSString stringWithFormat: @"%@/%@",
|
|
|
|
[self traversalFromMailAccount],
|
|
|
|
[_key substringFromIndex: 6]];
|
|
|
|
if ([folderName
|
|
|
|
isEqualToString: [mailAccount sentFolderNameInContext: _ctx]])
|
|
|
|
className = @"SOGoSentFolder";
|
|
|
|
else if ([folderName isEqualToString:
|
|
|
|
[mailAccount draftsFolderNameInContext: _ctx]])
|
|
|
|
className = @"SOGoDraftsFolder";
|
|
|
|
else if ([folderName isEqualToString:
|
|
|
|
[mailAccount trashFolderNameInContext: _ctx]])
|
|
|
|
className = @"SOGoTrashFolder";
|
|
|
|
/* else if ([folderName isEqualToString:
|
|
|
|
[mailAccount sieveFolderNameInContext: _ctx]])
|
|
|
|
obj = [self lookupFiltersFolder: _key inContext: _ctx]; */
|
|
|
|
else
|
|
|
|
className = @"SOGoMailFolder";
|
|
|
|
|
|
|
|
obj = [NSClassFromString (className)
|
|
|
|
objectWithName: _key inContainer: self];
|
|
|
|
}
|
2007-07-30 17:55:28 +02:00
|
|
|
else
|
|
|
|
{
|
2007-08-24 15:51:41 +02:00
|
|
|
if ([[self imap4Connection] doesMailboxExistAtURL: [self imap4URL]])
|
|
|
|
{
|
|
|
|
if (isdigit ([_key characterAtIndex: 0]))
|
|
|
|
obj = [SOGoMailObject objectWithName: _key inContainer: self];
|
|
|
|
else
|
|
|
|
obj = [super lookupName: _key inContext: _ctx acquire: NO];
|
|
|
|
}
|
2007-07-30 17:55:28 +02:00
|
|
|
else
|
2007-08-24 15:51:41 +02:00
|
|
|
obj = nil;
|
2007-07-30 17:55:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!obj && _acquire)
|
|
|
|
obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
|
|
|
|
|
|
|
|
return obj;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* WebDAV */
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (BOOL) davIsCollection
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (NSException *) davCreateCollection: (NSString *) _name
|
|
|
|
inContext: (id) _ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self imap4Connection] createMailbox:_name atURL:[self imap4URL]];
|
|
|
|
}
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (NSException *) delete
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* Note: overrides SOGoObject -delete */
|
|
|
|
return [[self imap4Connection] deleteMailboxAtURL:[self imap4URL]];
|
|
|
|
}
|
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (NSException *) davMoveToTargetObject: (id) _target
|
|
|
|
newName: (NSString *) _name
|
|
|
|
inContext: (id)_ctx
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
|
|
|
NSURL *destImapURL;
|
|
|
|
|
|
|
|
if ([_name length] == 0) { /* target already exists! */
|
|
|
|
// TODO: check the overwrite request field (should be done by dispatcher)
|
|
|
|
return [NSException exceptionWithHTTPStatus:412 /* Precondition Failed */
|
|
|
|
reason:@"target already exists"];
|
|
|
|
}
|
|
|
|
if (![_target respondsToSelector:@selector(imap4URL)]) {
|
|
|
|
return [NSException exceptionWithHTTPStatus:502 /* Bad Gateway */
|
|
|
|
reason:@"target is not an IMAP4 folder"];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build IMAP4 URL for target */
|
|
|
|
|
|
|
|
destImapURL = [_target imap4URL];
|
2007-07-10 21:23:39 +02:00
|
|
|
// - destImapURL = [NSURL URLWithString:[[destImapURL path]
|
|
|
|
// - stringByAppendingPathComponent:_name]
|
|
|
|
// - relativeToURL:destImapURL];
|
|
|
|
destImapURL = [NSURL URLWithString: _name
|
|
|
|
relativeToURL: destImapURL];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
[self logWithFormat:@"TODO: should move collection as '%@' to: %@",
|
|
|
|
[[self imap4URL] absoluteString],
|
|
|
|
[destImapURL absoluteString]];
|
|
|
|
|
|
|
|
return [[self imap4Connection] moveMailboxAtURL:[self imap4URL]
|
|
|
|
toURL:destImapURL];
|
|
|
|
}
|
2007-05-28 21:07:21 +02:00
|
|
|
|
|
|
|
- (NSException *) davCopyToTargetObject: (id) _target
|
|
|
|
newName: (NSString *) _name
|
|
|
|
inContext: (id) _ctx
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
|
|
|
[self logWithFormat:@"TODO: should copy collection as '%@' to: %@",
|
|
|
|
_name, _target];
|
|
|
|
return [NSException exceptionWithHTTPStatus:501 /* Not Implemented */
|
|
|
|
reason:@"not implemented"];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* folder type */
|
2007-05-30 22:23:54 +02:00
|
|
|
- (NSString *) folderType
|
|
|
|
{
|
|
|
|
return @"Mail";
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-28 21:07:21 +02:00
|
|
|
- (NSString *) outlookFolderClass
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
// TODO: detect Trash/Sent/Drafts folders
|
|
|
|
SOGoMailAccount *account;
|
2007-11-01 13:48:19 +01:00
|
|
|
NSString *name;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-11-01 13:48:19 +01:00
|
|
|
if (!folderType)
|
|
|
|
{
|
|
|
|
account = [self mailAccountFolder];
|
|
|
|
name = [self traversalFromMailAccount];
|
|
|
|
|
|
|
|
if ([name isEqualToString: [account trashFolderNameInContext: nil]])
|
|
|
|
folderType = @"IPF.Trash";
|
|
|
|
else if ([name
|
|
|
|
isEqualToString: [account inboxFolderNameInContext: nil]])
|
|
|
|
folderType = @"IPF.Inbox";
|
|
|
|
else if ([name
|
|
|
|
isEqualToString: [account sentFolderNameInContext: nil]])
|
|
|
|
folderType = @"IPF.Sent";
|
|
|
|
else
|
|
|
|
folderType = @"IPF.Folder";
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-22 21:17:45 +02:00
|
|
|
return folderType;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-05-19 02:46:16 +02:00
|
|
|
/* acls */
|
|
|
|
|
|
|
|
- (NSArray *) _imapAclsToSOGoAcls: (NSString *) imapAcls
|
|
|
|
{
|
|
|
|
unsigned int count, max;
|
|
|
|
NSMutableArray *SOGoAcls;
|
|
|
|
|
|
|
|
SOGoAcls = [NSMutableArray array];
|
|
|
|
max = [imapAcls length];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
switch ([imapAcls characterAtIndex: count])
|
|
|
|
{
|
|
|
|
case 'l':
|
|
|
|
case 'r':
|
2007-11-27 22:06:11 +01:00
|
|
|
[SOGoAcls addObjectUniquely: SOGoRole_ObjectViewer];
|
2007-05-19 02:46:16 +02:00
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
[SOGoAcls addObjectUniquely: SOGoMailRole_SeenKeeper];
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
[SOGoAcls addObjectUniquely: SOGoMailRole_Writer];
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
[SOGoAcls addObjectUniquely: SOGoRole_ObjectCreator];
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
[SOGoAcls addObjectUniquely: SOGoMailRole_Poster];
|
|
|
|
break;
|
2008-05-31 23:04:56 +02:00
|
|
|
case 'c':
|
2007-05-19 02:46:16 +02:00
|
|
|
case 'k':
|
|
|
|
[SOGoAcls addObjectUniquely: SOGoRole_FolderCreator];
|
|
|
|
break;
|
|
|
|
case 'x':
|
2007-06-01 22:57:07 +02:00
|
|
|
[SOGoAcls addObjectUniquely: SOGoRole_FolderEraser];
|
2007-05-19 02:46:16 +02:00
|
|
|
break;
|
2008-05-31 23:04:56 +02:00
|
|
|
case 'd':
|
2007-05-19 02:46:16 +02:00
|
|
|
case 't':
|
2007-06-01 22:57:07 +02:00
|
|
|
[SOGoAcls addObjectUniquely: SOGoRole_ObjectEraser];
|
2007-05-19 02:46:16 +02:00
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
[SOGoAcls addObjectUniquely: SOGoMailRole_Expunger];
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
[SOGoAcls addObjectUniquely: SOGoMailRole_Administrator];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SOGoAcls;
|
|
|
|
}
|
|
|
|
|
2008-05-31 23:04:56 +02:00
|
|
|
- (char) _rfc2086StyleRight: (NSString *) sogoRight
|
|
|
|
{
|
|
|
|
char character;
|
|
|
|
|
|
|
|
if ([sogoRight isEqualToString: SOGoRole_FolderCreator])
|
|
|
|
character = 'c';
|
|
|
|
else if ([sogoRight isEqualToString: SOGoRole_ObjectEraser])
|
|
|
|
character = 'd';
|
|
|
|
else
|
|
|
|
character = 0;
|
|
|
|
|
|
|
|
return character;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (char) _rfc4314StyleRight: (NSString *) sogoRight
|
|
|
|
{
|
|
|
|
char character;
|
|
|
|
|
|
|
|
if ([sogoRight isEqualToString: SOGoRole_FolderCreator])
|
|
|
|
character = 'k';
|
|
|
|
else if ([sogoRight isEqualToString: SOGoRole_FolderEraser])
|
|
|
|
character = 'x';
|
|
|
|
else if ([sogoRight isEqualToString: SOGoRole_ObjectEraser])
|
|
|
|
character = 't';
|
|
|
|
else if ([sogoRight isEqualToString: SOGoMailRole_Expunger])
|
|
|
|
character = 'e';
|
|
|
|
else
|
|
|
|
character = 0;
|
|
|
|
|
|
|
|
return character;
|
|
|
|
}
|
|
|
|
|
2007-05-22 20:33:45 +02:00
|
|
|
- (NSString *) _sogoAclsToImapAcls: (NSArray *) sogoAcls
|
|
|
|
{
|
|
|
|
NSMutableString *imapAcls;
|
|
|
|
NSEnumerator *acls;
|
|
|
|
NSString *currentAcl;
|
|
|
|
char character;
|
|
|
|
|
|
|
|
imapAcls = [NSMutableString string];
|
|
|
|
acls = [sogoAcls objectEnumerator];
|
2008-05-31 23:04:56 +02:00
|
|
|
while ((currentAcl = [acls nextObject]))
|
2007-05-22 20:33:45 +02:00
|
|
|
{
|
|
|
|
if ([currentAcl isEqualToString: SOGoRole_ObjectViewer])
|
2007-11-27 22:06:11 +01:00
|
|
|
{
|
|
|
|
[imapAcls appendFormat: @"lr"];
|
|
|
|
character = 0;
|
|
|
|
}
|
2007-05-22 20:33:45 +02:00
|
|
|
else if ([currentAcl isEqualToString: SOGoMailRole_SeenKeeper])
|
|
|
|
character = 's';
|
|
|
|
else if ([currentAcl isEqualToString: SOGoMailRole_Writer])
|
|
|
|
character = 'w';
|
|
|
|
else if ([currentAcl isEqualToString: SOGoRole_ObjectCreator])
|
|
|
|
character = 'i';
|
|
|
|
else if ([currentAcl isEqualToString: SOGoMailRole_Poster])
|
|
|
|
character = 'p';
|
|
|
|
else if ([currentAcl isEqualToString: SOGoMailRole_Administrator])
|
|
|
|
character = 'a';
|
|
|
|
else
|
2008-05-31 23:04:56 +02:00
|
|
|
{
|
|
|
|
if (aclStyle == rfc2086)
|
|
|
|
character = [self _rfc2086StyleRight: currentAcl];
|
|
|
|
else if (aclStyle == rfc4314)
|
|
|
|
character = [self _rfc4314StyleRight: currentAcl];
|
|
|
|
else
|
|
|
|
character = 0;
|
|
|
|
}
|
2007-05-22 20:33:45 +02:00
|
|
|
|
|
|
|
if (character)
|
|
|
|
[imapAcls appendFormat: @"%c", character];
|
|
|
|
}
|
|
|
|
|
|
|
|
return imapAcls;
|
|
|
|
}
|
|
|
|
|
2008-05-31 23:04:56 +02:00
|
|
|
- (void) _unquoteACLUsernames
|
|
|
|
{
|
|
|
|
NSMutableDictionary *newIMAPAcls;
|
|
|
|
NSEnumerator *usernames;
|
|
|
|
NSString *username, *unquoted;
|
|
|
|
|
|
|
|
newIMAPAcls = [NSMutableDictionary new];
|
|
|
|
|
|
|
|
usernames = [[mailboxACL allKeys] objectEnumerator];
|
|
|
|
while ((username = [usernames nextObject]))
|
|
|
|
{
|
|
|
|
unquoted = [username substringFromRange:
|
|
|
|
NSMakeRange(1, [username length] - 2)];
|
|
|
|
[newIMAPAcls setObject: [mailboxACL objectForKey: username]
|
|
|
|
forKey: unquoted];
|
|
|
|
}
|
|
|
|
[mailboxACL release];
|
|
|
|
mailboxACL = newIMAPAcls;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _removeIMAPExtUsernames
|
|
|
|
{
|
|
|
|
NSMutableDictionary *newIMAPAcls;
|
|
|
|
NSEnumerator *usernames;
|
|
|
|
NSString *username;
|
|
|
|
|
|
|
|
newIMAPAcls = [NSMutableDictionary new];
|
|
|
|
|
|
|
|
usernames = [[mailboxACL allKeys] objectEnumerator];
|
|
|
|
while ((username = [usernames nextObject]))
|
|
|
|
if (!([username isEqualToString: @"administrators"]
|
|
|
|
|| [username isEqualToString: @"owner"]
|
|
|
|
|| [username isEqualToString: @"anonymous"]
|
|
|
|
|| [username isEqualToString: @"authuser"]))
|
|
|
|
[newIMAPAcls setObject: [mailboxACL objectForKey: username]
|
|
|
|
forKey: username];
|
|
|
|
[mailboxACL release];
|
|
|
|
mailboxACL = newIMAPAcls;
|
|
|
|
}
|
|
|
|
|
2007-08-17 04:27:35 +02:00
|
|
|
- (void) _readMailboxACL
|
|
|
|
{
|
2008-05-31 23:04:56 +02:00
|
|
|
[mailboxACL release];
|
|
|
|
|
|
|
|
mailboxACL = [[self imap4Connection] aclForMailboxAtURL: [self imap4URL]];
|
2007-08-17 04:27:35 +02:00
|
|
|
[mailboxACL retain];
|
2008-05-31 23:04:56 +02:00
|
|
|
|
|
|
|
if (aclUsernamesAreQuoted)
|
|
|
|
[self _unquoteACLUsernames];
|
|
|
|
if (aclConformsToIMAPExt)
|
|
|
|
[self _removeIMAPExtUsernames];
|
2007-08-17 04:27:35 +02:00
|
|
|
}
|
|
|
|
|
2007-11-29 17:14:11 +01:00
|
|
|
- (NSArray *) subscriptionRoles
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObjects: SOGoRole_ObjectViewer,
|
|
|
|
SOGoMailRole_SeenKeeper, SOGoMailRole_Writer,
|
|
|
|
SOGoRole_ObjectCreator, SOGoMailRole_Poster,
|
|
|
|
SOGoRole_FolderCreator, SOGoRole_FolderEraser,
|
|
|
|
SOGoRole_ObjectEraser, SOGoMailRole_Expunger,
|
|
|
|
SOGoMailRole_Administrator, nil];
|
|
|
|
}
|
|
|
|
|
2007-05-19 02:46:16 +02:00
|
|
|
- (NSArray *) aclUsers
|
|
|
|
{
|
2007-05-25 23:26:01 +02:00
|
|
|
NSArray *users;
|
2007-05-19 02:46:16 +02:00
|
|
|
|
2007-08-17 04:27:35 +02:00
|
|
|
if (!mailboxACL)
|
|
|
|
[self _readMailboxACL];
|
|
|
|
|
|
|
|
if ([mailboxACL isKindOfClass: [NSDictionary class]])
|
|
|
|
users = [mailboxACL allKeys];
|
2007-05-25 23:26:01 +02:00
|
|
|
else
|
|
|
|
users = nil;
|
|
|
|
|
|
|
|
return users;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMutableArray *) _sharesACLs
|
|
|
|
{
|
|
|
|
NSMutableArray *acls;
|
|
|
|
SOGoMailAccount *mailAccount;
|
2007-06-05 16:59:30 +02:00
|
|
|
NSString *path, *folder;
|
|
|
|
// NSArray *names;
|
2007-06-05 17:43:59 +02:00
|
|
|
// unsigned int count;
|
2007-05-25 23:26:01 +02:00
|
|
|
|
|
|
|
acls = [NSMutableArray array];
|
|
|
|
|
|
|
|
mailAccount = [self mailAccountFolder];
|
2007-05-30 22:23:54 +02:00
|
|
|
path = [[self imap4Connection] imap4FolderNameForURL: [self imap4URL]];
|
2007-06-05 16:59:30 +02:00
|
|
|
// names = [path componentsSeparatedByString: @"/"];
|
2007-06-05 17:43:59 +02:00
|
|
|
// count = [names count];
|
2007-05-25 23:26:01 +02:00
|
|
|
|
2007-06-05 16:59:30 +02:00
|
|
|
folder = [mailAccount sharedFolderName];
|
|
|
|
if (folder && [path hasPrefix: folder])
|
2007-05-30 22:23:54 +02:00
|
|
|
[acls addObject: SOGoRole_ObjectViewer];
|
2007-05-25 23:26:01 +02:00
|
|
|
else
|
2007-06-05 16:59:30 +02:00
|
|
|
{
|
|
|
|
folder = [mailAccount otherUsersFolderName];
|
|
|
|
if (folder && [path hasPrefix: folder])
|
|
|
|
[acls addObject: SOGoRole_ObjectViewer];
|
|
|
|
else
|
|
|
|
[acls addObject: SoRole_Owner];
|
|
|
|
}
|
2007-05-19 02:46:16 +02:00
|
|
|
|
2007-05-25 23:26:01 +02:00
|
|
|
return acls;
|
2007-05-19 02:46:16 +02:00
|
|
|
}
|
|
|
|
|
2007-05-22 20:33:45 +02:00
|
|
|
- (NSArray *) aclsForUser: (NSString *) uid
|
|
|
|
{
|
2007-05-25 23:26:01 +02:00
|
|
|
NSMutableArray *acls;
|
2007-05-22 21:30:36 +02:00
|
|
|
NSString *userAcls;
|
2007-05-22 20:33:45 +02:00
|
|
|
|
2007-05-25 23:26:01 +02:00
|
|
|
acls = [self _sharesACLs];
|
2007-08-17 04:27:35 +02:00
|
|
|
|
|
|
|
if (!mailboxACL)
|
|
|
|
[self _readMailboxACL];
|
|
|
|
|
|
|
|
if ([mailboxACL isKindOfClass: [NSDictionary class]])
|
2007-05-25 23:26:01 +02:00
|
|
|
{
|
2007-08-17 04:27:35 +02:00
|
|
|
userAcls = [mailboxACL objectForKey: uid];
|
2007-05-25 23:26:01 +02:00
|
|
|
if (!([userAcls length] || [uid isEqualToString: defaultUserID]))
|
2007-08-17 04:27:35 +02:00
|
|
|
userAcls = [mailboxACL objectForKey: defaultUserID];
|
2007-05-25 23:26:01 +02:00
|
|
|
if ([userAcls length])
|
|
|
|
[acls addObjectsFromArray: [self _imapAclsToSOGoAcls: userAcls]];
|
|
|
|
}
|
2007-05-22 20:33:45 +02:00
|
|
|
|
2007-05-25 23:26:01 +02:00
|
|
|
return acls;
|
2007-05-22 20:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeAclsForUsers: (NSArray *) users
|
|
|
|
{
|
|
|
|
NSEnumerator *uids;
|
2008-05-31 23:04:56 +02:00
|
|
|
NSString *currentUID, *folderName;
|
2007-05-22 20:33:45 +02:00
|
|
|
NGImap4Client *client;
|
|
|
|
|
2007-05-30 22:23:54 +02:00
|
|
|
folderName = [[self imap4Connection] imap4FolderNameForURL: [self imap4URL]];
|
2007-05-22 20:33:45 +02:00
|
|
|
client = [imap4 client];
|
|
|
|
|
|
|
|
uids = [users objectEnumerator];
|
2008-05-31 23:04:56 +02:00
|
|
|
while ((currentUID = [uids nextObject]))
|
|
|
|
[client deleteACL: folderName uid: currentUID];
|
2007-08-17 04:27:35 +02:00
|
|
|
[mailboxACL release];
|
|
|
|
mailboxACL = nil;
|
2007-05-22 20:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRoles: (NSArray *) roles
|
|
|
|
forUser: (NSString *) uid
|
|
|
|
{
|
|
|
|
NSString *acls, *folderName;
|
|
|
|
|
|
|
|
acls = [self _sogoAclsToImapAcls: roles];
|
2007-05-30 22:23:54 +02:00
|
|
|
folderName = [[self imap4Connection] imap4FolderNameForURL: [self imap4URL]];
|
2007-05-22 20:33:45 +02:00
|
|
|
[[imap4 client] setACL: folderName rights: acls uid: uid];
|
2007-08-17 04:27:35 +02:00
|
|
|
|
|
|
|
[mailboxACL release];
|
|
|
|
mailboxACL = nil;
|
2007-05-22 20:33:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) defaultUserID
|
|
|
|
{
|
2007-05-22 21:16:07 +02:00
|
|
|
return defaultUserID;
|
2007-05-22 20:33:45 +02:00
|
|
|
}
|
|
|
|
|
2007-05-30 22:23:54 +02:00
|
|
|
- (NSString *) otherUsersPathToFolder
|
|
|
|
{
|
|
|
|
NSString *userPath, *selfPath, *otherUsers, *sharedFolders;
|
|
|
|
SOGoMailAccount *account;
|
|
|
|
|
|
|
|
account = [self mailAccountFolder];
|
|
|
|
otherUsers = [account otherUsersFolderName];
|
|
|
|
sharedFolders = [account sharedFolderName];
|
|
|
|
|
|
|
|
selfPath = [[self imap4URL] path];
|
2007-06-05 16:59:30 +02:00
|
|
|
if ((otherUsers
|
|
|
|
&& [selfPath hasPrefix:
|
|
|
|
[NSString stringWithFormat: @"/%@", otherUsers]])
|
|
|
|
|| (sharedFolders
|
|
|
|
&& [selfPath hasPrefix:
|
|
|
|
[NSString stringWithFormat: @"/%@", sharedFolders]]))
|
2007-05-30 22:23:54 +02:00
|
|
|
userPath = selfPath;
|
|
|
|
else
|
2007-06-05 16:59:30 +02:00
|
|
|
{
|
|
|
|
if (otherUsers)
|
|
|
|
userPath = [NSString stringWithFormat: @"/%@/%@%@",
|
|
|
|
[otherUsers stringByEscapingURL],
|
|
|
|
owner, selfPath];
|
|
|
|
else
|
|
|
|
userPath = nil;
|
|
|
|
}
|
2007-05-30 22:23:54 +02:00
|
|
|
|
|
|
|
return userPath;
|
|
|
|
}
|
|
|
|
|
2007-10-14 18:07:22 +02:00
|
|
|
- (NSString *) httpURLForAdvisoryToUser: (NSString *) uid
|
2007-05-30 22:23:54 +02:00
|
|
|
{
|
|
|
|
SOGoUser *user;
|
2007-06-05 16:59:30 +02:00
|
|
|
NSString *otherUsersPath, *url;
|
2007-08-17 04:27:35 +02:00
|
|
|
SOGoMailAccount *thisAccount;
|
|
|
|
NSDictionary *mailAccount;
|
2007-05-30 22:23:54 +02:00
|
|
|
|
|
|
|
user = [SOGoUser userWithLogin: uid roles: nil];
|
2007-06-05 16:59:30 +02:00
|
|
|
otherUsersPath = [self otherUsersPathToFolder];
|
|
|
|
if (otherUsersPath)
|
2007-08-17 04:27:35 +02:00
|
|
|
{
|
|
|
|
thisAccount = [self mailAccountFolder];
|
|
|
|
mailAccount = [[user mailAccounts] objectAtIndex: 0];
|
|
|
|
url = [NSString stringWithFormat: @"%@/%@%@",
|
|
|
|
[self soURLToBaseContainerForUser: uid],
|
|
|
|
[mailAccount objectForKey: @"name"],
|
|
|
|
otherUsersPath];
|
|
|
|
}
|
2007-06-05 16:59:30 +02:00
|
|
|
else
|
|
|
|
url = nil;
|
2007-05-30 22:23:54 +02:00
|
|
|
|
2007-06-05 16:59:30 +02:00
|
|
|
return url;
|
2007-05-30 22:23:54 +02:00
|
|
|
}
|
|
|
|
|
2007-10-14 18:07:22 +02:00
|
|
|
- (NSString *) resourceURLForAdvisoryToUser: (NSString *) uid
|
2007-05-30 22:23:54 +02:00
|
|
|
{
|
|
|
|
NSURL *selfURL, *userURL;
|
|
|
|
|
|
|
|
selfURL = [self imap4URL];
|
|
|
|
userURL = [[NSURL alloc] initWithScheme: [selfURL scheme]
|
|
|
|
host: [selfURL host]
|
|
|
|
path: [self otherUsersPathToFolder]];
|
|
|
|
[userURL autorelease];
|
|
|
|
|
|
|
|
return [userURL absoluteString];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end /* SOGoMailFolder */
|
2007-10-31 16:55:47 +01:00
|
|
|
|
|
|
|
@implementation SOGoSpecialMailFolder
|
|
|
|
|
|
|
|
- (id) initWithName: (NSString *) newName
|
|
|
|
inContainer: (id) newContainer
|
|
|
|
{
|
|
|
|
if ((self = [super initWithName: newName
|
|
|
|
inContainer: newContainer]))
|
|
|
|
{
|
|
|
|
if (![[self imap4Connection] doesMailboxExistAtURL: [self imap4URL]])
|
|
|
|
[imap4 createMailbox: [self relativeImap4Name]
|
|
|
|
atURL: [newContainer imap4URL]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isSpecialFolder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|