2007-05-28 15:15:27 +02:00
|
|
|
/* UIxMailFolderActions.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
2007-05-28 18:03:19 +02:00
|
|
|
#import <Foundation/NSURL.h>
|
2007-05-28 15:15:27 +02:00
|
|
|
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
#import <NGImap4/NGImap4Connection.h>
|
|
|
|
|
|
|
|
#import <SoObjects/Mailer/SOGoMailFolder.h>
|
2007-05-28 21:05:00 +02:00
|
|
|
#import <SoObjects/Mailer/SOGoTrashFolder.h>
|
|
|
|
#import <SoObjects/Mailer/SOGoMailAccount.h>
|
2007-05-28 15:15:27 +02:00
|
|
|
|
|
|
|
#import "UIxMailFolderActions.h"
|
|
|
|
|
|
|
|
@implementation UIxMailFolderActions
|
|
|
|
|
|
|
|
- (WOResponse *) createFolderAction
|
|
|
|
{
|
|
|
|
SOGoMailFolder *co;
|
|
|
|
WOResponse *response;
|
|
|
|
NGImap4Connection *connection;
|
|
|
|
NSException *error;
|
|
|
|
NSString *folderName;
|
|
|
|
|
|
|
|
co = [self clientObject];
|
|
|
|
response = [context response];
|
|
|
|
|
|
|
|
folderName = [[context request] formValueForKey: @"name"];
|
|
|
|
if ([folderName length] > 0)
|
|
|
|
{
|
|
|
|
connection = [co imap4Connection];
|
|
|
|
error = [connection createMailbox: folderName atURL: [co imap4URL]];
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
[response setStatus: 403];
|
|
|
|
[response appendContentString: @"Unable to create folder."];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[response setStatus: 204];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[response setStatus: 403];
|
|
|
|
[response appendContentString: @"Missing 'name' parameter."];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-05-28 18:03:19 +02:00
|
|
|
- (NSURL *) _urlOfFolder: (NSURL *) srcURL
|
|
|
|
renamedTo: (NSString *) folderName
|
|
|
|
{
|
|
|
|
NSString *path;
|
|
|
|
NSURL *destURL;
|
|
|
|
|
2007-05-28 21:05:00 +02:00
|
|
|
path = [[srcURL path] stringByDeletingLastPathComponent];
|
|
|
|
|
2007-05-28 18:03:19 +02:00
|
|
|
destURL = [[NSURL alloc] initWithScheme: [srcURL scheme]
|
|
|
|
host: [srcURL host]
|
2007-05-28 21:05:00 +02:00
|
|
|
path: [NSString stringWithFormat: @"%@%@",
|
|
|
|
path, folderName]];
|
2007-05-28 18:03:19 +02:00
|
|
|
[destURL autorelease];
|
|
|
|
|
|
|
|
return destURL;
|
|
|
|
}
|
|
|
|
|
2007-05-28 15:15:27 +02:00
|
|
|
- (WOResponse *) renameFolderAction
|
|
|
|
{
|
|
|
|
SOGoMailFolder *co;
|
|
|
|
WOResponse *response;
|
|
|
|
NGImap4Connection *connection;
|
|
|
|
NSException *error;
|
|
|
|
NSString *folderName;
|
2007-05-28 18:03:19 +02:00
|
|
|
NSURL *srcURL, *destURL;
|
2007-05-28 15:15:27 +02:00
|
|
|
|
|
|
|
co = [self clientObject];
|
|
|
|
response = [context response];
|
|
|
|
|
|
|
|
folderName = [[context request] formValueForKey: @"name"];
|
|
|
|
if ([folderName length] > 0)
|
|
|
|
{
|
2007-05-28 18:03:19 +02:00
|
|
|
srcURL = [co imap4URL];
|
|
|
|
destURL = [self _urlOfFolder: srcURL renamedTo: folderName];
|
|
|
|
connection = [co imap4Connection];
|
|
|
|
error = [connection moveMailboxAtURL: srcURL
|
|
|
|
toURL: destURL];
|
|
|
|
if (error)
|
|
|
|
{
|
2007-05-28 15:15:27 +02:00
|
|
|
[response setStatus: 403];
|
|
|
|
[response appendContentString: @"Unable to rename folder."];
|
2007-05-28 18:03:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
[response setStatus: 204];
|
2007-05-28 15:15:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[response setStatus: 403];
|
|
|
|
[response appendContentString: @"Missing 'name' parameter."];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-05-28 21:05:00 +02:00
|
|
|
- (NSURL *) _trashedURLOfFolder: (NSURL *) srcURL
|
|
|
|
withCO: (SOGoMailFolder *) co
|
|
|
|
{
|
|
|
|
NSURL *destURL;
|
|
|
|
NSString *trashFolderName, *folderName;
|
|
|
|
|
|
|
|
folderName = [[srcURL path] lastPathComponent];
|
|
|
|
trashFolderName
|
|
|
|
= [[co mailAccountFolder] trashFolderNameInContext: context];
|
|
|
|
|
|
|
|
destURL = [[NSURL alloc] initWithScheme: [srcURL scheme]
|
|
|
|
host: [srcURL host]
|
|
|
|
path: [NSString stringWithFormat: @"/%@/%@",
|
|
|
|
trashFolderName, folderName]];
|
|
|
|
[destURL autorelease];
|
|
|
|
|
|
|
|
return destURL;
|
|
|
|
}
|
|
|
|
|
2007-05-28 15:15:27 +02:00
|
|
|
- (WOResponse *) deleteFolderAction
|
|
|
|
{
|
|
|
|
SOGoMailFolder *co;
|
|
|
|
WOResponse *response;
|
|
|
|
NGImap4Connection *connection;
|
|
|
|
NSException *error;
|
2007-05-28 21:05:00 +02:00
|
|
|
NSURL *srcURL, *destURL;
|
2007-05-28 15:15:27 +02:00
|
|
|
|
|
|
|
co = [self clientObject];
|
|
|
|
response = [context response];
|
|
|
|
connection = [co imap4Connection];
|
2007-05-28 21:05:00 +02:00
|
|
|
srcURL = [co imap4URL];
|
|
|
|
destURL = [self _trashedURLOfFolder: srcURL
|
|
|
|
withCO: co];
|
|
|
|
connection = [co imap4Connection];
|
|
|
|
error = [connection moveMailboxAtURL: srcURL
|
|
|
|
toURL: destURL];
|
2007-05-28 15:15:27 +02:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
[response setStatus: 403];
|
2007-05-28 21:05:00 +02:00
|
|
|
[response appendContentString: @"Unable to move folder."];
|
2007-05-28 15:15:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
[response setStatus: 204];
|
|
|
|
|
2007-05-28 21:05:00 +02:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) emptyTrashAction
|
|
|
|
{
|
|
|
|
NSException *error;
|
|
|
|
SOGoTrashFolder *co;
|
|
|
|
NSEnumerator *subfolders;
|
|
|
|
WOResponse *response;
|
|
|
|
NGImap4Connection *connection;
|
|
|
|
NSURL *currentURL;
|
|
|
|
|
|
|
|
co = [self clientObject];
|
|
|
|
response = [context response];
|
|
|
|
|
|
|
|
error = [co addFlagsToAllMessages: @"deleted"];
|
|
|
|
if (!error)
|
|
|
|
error = [co expunge];
|
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
[co flushMailCaches];
|
|
|
|
connection = [co imap4Connection];
|
|
|
|
subfolders = [[co subfoldersURL] objectEnumerator];
|
|
|
|
currentURL = [subfolders nextObject];
|
|
|
|
while (currentURL)
|
|
|
|
{
|
|
|
|
[connection deleteMailboxAtURL: currentURL];
|
|
|
|
currentURL = [subfolders nextObject];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
[response setStatus: 403];
|
|
|
|
[response appendContentString: @"Unable to empty the trash folder."];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[response setStatus: 204];
|
|
|
|
|
|
|
|
return response;
|
2007-05-28 15:15:27 +02:00
|
|
|
}
|
|
|
|
|
2007-05-30 22:12:53 +02:00
|
|
|
#warning here should be done what should be done: IMAP subscription
|
|
|
|
- (WOResponse *) _subscriptionStubAction
|
|
|
|
{
|
|
|
|
NSString *mailInvitationParam, *mailInvitationURL;
|
|
|
|
WOResponse *response;
|
|
|
|
SOGoMailFolder *clientObject;
|
|
|
|
|
|
|
|
response = [context response];
|
|
|
|
mailInvitationParam
|
|
|
|
= [[context request] formValueForKey: @"mail-invitation"];
|
|
|
|
if ([mailInvitationParam boolValue])
|
|
|
|
{
|
|
|
|
clientObject = [self clientObject];
|
|
|
|
mailInvitationURL
|
|
|
|
= [[clientObject soURLToBaseContainerForCurrentUser]
|
|
|
|
absoluteString];
|
|
|
|
[response setStatus: 302];
|
|
|
|
[response setHeader: mailInvitationURL
|
|
|
|
forKey: @"location"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[response setStatus: 403];
|
|
|
|
[response appendContentString: @"How did you end up here?"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) subscribeAction
|
|
|
|
{
|
|
|
|
return [self _subscriptionStubAction];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) unsubscribeAction
|
|
|
|
{
|
|
|
|
return [self _subscriptionStubAction];
|
|
|
|
}
|
|
|
|
|
2007-05-28 15:15:27 +02:00
|
|
|
@end
|