2007-05-28 15:15:27 +02:00
|
|
|
/* UIxMailFolderActions.m - this file is part of SOGo
|
|
|
|
*
|
2016-01-22 16:30:27 +01:00
|
|
|
* Copyright (C) 2007-2016 Inverse inc.
|
2007-05-28 15:15:27 +02:00
|
|
|
*
|
|
|
|
* 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>
|
2010-08-12 22:51:10 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2007-05-28 15:15:27 +02:00
|
|
|
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
2007-10-17 23:03:39 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2007-05-28 15:15:27 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
2014-03-06 15:27:43 +01:00
|
|
|
|
2007-05-28 15:15:27 +02:00
|
|
|
#import <NGImap4/NGImap4Connection.h>
|
2007-07-11 07:05:03 +02:00
|
|
|
#import <NGImap4/NGImap4Client.h>
|
2014-03-06 15:27:43 +01:00
|
|
|
#import <NGImap4/NSString+Imap4.h>
|
|
|
|
|
2010-08-12 22:51:10 +02:00
|
|
|
#import <EOControl/EOQualifier.h>
|
2007-05-28 15:15:27 +02:00
|
|
|
|
2009-12-01 15:29:56 +01:00
|
|
|
#import <Mailer/SOGoMailAccount.h>
|
2010-08-06 16:29:41 +02:00
|
|
|
#import <Mailer/SOGoMailFolder.h>
|
2009-12-01 15:29:56 +01:00
|
|
|
#import <Mailer/SOGoMailObject.h>
|
2010-08-06 16:29:41 +02:00
|
|
|
#import <Mailer/SOGoTrashFolder.h>
|
|
|
|
|
2009-12-01 15:29:56 +01:00
|
|
|
#import <SOGo/NSObject+Utilities.h>
|
2014-03-13 13:41:42 +01:00
|
|
|
#import <SOGo/NSString+Utilities.h>
|
2010-08-06 16:29:41 +02:00
|
|
|
#import <SOGo/SOGoDomainDefaults.h>
|
2009-12-01 15:29:56 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
2010-02-19 15:52:05 +01:00
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
2010-04-21 16:35:58 +02:00
|
|
|
#import <SOGo/SOGoUserSettings.h>
|
2007-05-28 15:15:27 +02:00
|
|
|
|
2007-09-11 21:42:41 +02:00
|
|
|
#import <UI/Common/WODirectAction+SOGo.h>
|
|
|
|
|
2007-05-28 15:15:27 +02:00
|
|
|
#import "UIxMailFolderActions.h"
|
|
|
|
|
|
|
|
@implementation UIxMailFolderActions
|
|
|
|
|
2015-01-08 17:31:24 +01:00
|
|
|
/**
|
2015-01-13 17:30:23 +01:00
|
|
|
* @api {post} /so/:username/Mail/:accountId/:parentMailboxPath/createFolder Create mailbox
|
2015-01-08 17:31:24 +01:00
|
|
|
* @apiVersion 1.0.0
|
2015-06-15 17:32:09 +02:00
|
|
|
* @apiName PostCreateMailbox
|
2015-01-08 17:31:24 +01:00
|
|
|
* @apiGroup Mail
|
2015-01-13 17:30:23 +01:00
|
|
|
* @apiExample {curl} Example usage:
|
|
|
|
* curl -i http://localhost/SOGo/so/sogo1/Mail/0/folderINBOX/createFolder \
|
|
|
|
* -H "Content-Type: application/json" \
|
|
|
|
* -d '{ "name": "test" }'
|
2015-01-08 17:31:24 +01:00
|
|
|
*
|
|
|
|
* @apiParam {String} name Name of the mailbox
|
|
|
|
*
|
|
|
|
* @apiError (Error 500) {Object} error The error message
|
|
|
|
*/
|
2014-12-18 19:50:32 +01:00
|
|
|
- (id <WOActionResults>) createFolderAction
|
2007-05-28 15:15:27 +02:00
|
|
|
{
|
2010-09-28 17:07:27 +02:00
|
|
|
SOGoMailFolder *co, *newFolder;
|
2014-12-18 19:50:32 +01:00
|
|
|
WORequest *request;
|
2007-05-28 15:15:27 +02:00
|
|
|
WOResponse *response;
|
2014-12-18 19:50:32 +01:00
|
|
|
NSDictionary *params, *jsonResponse;
|
|
|
|
NSString *folderName, *encodedFolderName, *errorFormat;
|
2007-05-28 15:15:27 +02:00
|
|
|
|
|
|
|
co = [self clientObject];
|
|
|
|
|
2014-12-18 19:50:32 +01:00
|
|
|
request = [context request];
|
|
|
|
params = [[request contentAsString] objectFromJSONString];
|
|
|
|
folderName = [params objectForKey: @"name"];
|
2007-05-28 15:15:27 +02:00
|
|
|
if ([folderName length] > 0)
|
|
|
|
{
|
2014-12-18 19:50:32 +01:00
|
|
|
encodedFolderName = [folderName stringByEncodingImap4FolderName];
|
|
|
|
newFolder = [co lookupName: [NSString stringWithFormat: @"folder%@", encodedFolderName]
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
2010-09-28 17:07:27 +02:00
|
|
|
if ([newFolder create])
|
2014-12-18 19:50:32 +01:00
|
|
|
{
|
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
2010-09-28 17:07:27 +02:00
|
|
|
else
|
2009-07-02 19:06:21 +02:00
|
|
|
{
|
2015-08-19 16:39:10 +02:00
|
|
|
errorFormat = [self labelForKey: @"The folder with name \"%@\" could not be created." inContext: context];
|
2014-12-18 19:50:32 +01:00
|
|
|
jsonResponse = [NSDictionary dictionaryWithObject: [NSString stringWithFormat: errorFormat, folderName]
|
|
|
|
forKey: @"error"];
|
2015-12-22 03:07:43 +01:00
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: jsonResponse];
|
2009-07-02 19:06:21 +02:00
|
|
|
}
|
2007-05-28 15:15:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-19 16:39:10 +02:00
|
|
|
jsonResponse = [NSDictionary dictionaryWithObject: [self labelForKey: @"Missing 'name' parameter." inContext: context]
|
2014-12-18 19:50:32 +01:00
|
|
|
forKey: @"error"];
|
2015-12-22 03:07:43 +01:00
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: jsonResponse];
|
2007-05-28 15:15:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2015-01-08 17:31:24 +01:00
|
|
|
/**
|
2015-01-13 17:30:23 +01:00
|
|
|
* @api {post} /so/:username/Mail/:accountId/:mailboxPath/renameFolder Rename mailbox
|
2015-01-08 17:31:24 +01:00
|
|
|
* @apiVersion 1.0.0
|
|
|
|
* @apiName PostRenameFolder
|
|
|
|
* @apiGroup Mail
|
|
|
|
*
|
|
|
|
* @apiParam {String} name Name of the mailbox
|
|
|
|
*
|
|
|
|
* @apiSuccess (Success 200) {String} path New mailbox path relative to account
|
|
|
|
* @apiError (Error 500) {Object} error The error message
|
|
|
|
*/
|
2007-05-28 15:15:27 +02:00
|
|
|
- (WOResponse *) renameFolderAction
|
|
|
|
{
|
2012-01-30 21:47:07 +01:00
|
|
|
SOGoMailFolder *co;
|
2014-08-28 23:55:35 +02:00
|
|
|
SOGoUserSettings *us;
|
2015-01-08 17:31:24 +01:00
|
|
|
WORequest *request;
|
2007-05-28 15:15:27 +02:00
|
|
|
WOResponse *response;
|
|
|
|
NSException *error;
|
2015-01-08 17:31:24 +01:00
|
|
|
NSString *newFolderName, *newFolderPath, *currentMailbox, *currentAccount, *keyForMsgUIDs, *newKeyForMsgUIDs;
|
|
|
|
NSMutableDictionary *params, *moduleSettings, *threadsCollapsed, *message;
|
2014-08-28 23:55:35 +02:00
|
|
|
NSArray *values;
|
2007-05-28 15:15:27 +02:00
|
|
|
|
|
|
|
co = [self clientObject];
|
2015-01-08 17:31:24 +01:00
|
|
|
|
|
|
|
// Prepare the variables need to verify if the current folder have any collapsed threads saved in userSettings
|
2014-08-28 23:55:35 +02:00
|
|
|
us = [[context activeUser] userSettings];
|
|
|
|
moduleSettings = [us objectForKey: @"Mail"];
|
|
|
|
threadsCollapsed = [moduleSettings objectForKey:@"threadsCollapsed"];
|
|
|
|
currentMailbox = [co nameInContainer];
|
|
|
|
currentAccount = [[co container] nameInContainer];
|
|
|
|
keyForMsgUIDs = [NSString stringWithFormat:@"/%@/%@", currentAccount, currentMailbox];
|
|
|
|
|
2015-01-08 17:31:24 +01:00
|
|
|
// Retrieve new folder name from JSON payload
|
|
|
|
request = [context request];
|
|
|
|
params = [[request contentAsString] objectFromJSONString];
|
|
|
|
newFolderName = [params objectForKey: @"name"];
|
|
|
|
|
|
|
|
if (!newFolderName || [newFolderName length] == 0)
|
2007-05-28 15:15:27 +02:00
|
|
|
{
|
2015-08-19 16:39:10 +02:00
|
|
|
message = [NSDictionary dictionaryWithObject: [self labelForKey: @"Missing name parameter" inContext: context]
|
2015-12-22 03:07:43 +01:00
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: message];
|
2007-05-28 15:15:27 +02:00
|
|
|
}
|
2012-01-30 21:47:07 +01:00
|
|
|
else
|
2014-08-28 23:55:35 +02:00
|
|
|
{
|
2015-11-05 15:59:31 +01:00
|
|
|
newKeyForMsgUIDs = [NSString stringWithFormat:@"/%@/folder%@", [currentAccount asCSSIdentifier], [newFolderName asCSSIdentifier]];
|
2015-01-08 17:31:24 +01:00
|
|
|
error = [co renameTo: newFolderName];
|
|
|
|
if (error)
|
|
|
|
{
|
2015-08-19 16:39:10 +02:00
|
|
|
message = [NSDictionary dictionaryWithObject: [self labelForKey: @"Unable to rename folder." inContext: context]
|
2015-12-22 03:07:43 +01:00
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: message];
|
2015-01-08 17:31:24 +01:00
|
|
|
}
|
|
|
|
else
|
2014-08-28 23:55:35 +02:00
|
|
|
{
|
2015-01-08 17:31:24 +01:00
|
|
|
// Verify if the current folder have any collapsed threads save under it old name and adjust the folderName
|
|
|
|
if (threadsCollapsed)
|
2014-08-28 23:55:35 +02:00
|
|
|
{
|
2015-01-08 17:31:24 +01:00
|
|
|
if ([threadsCollapsed objectForKey:keyForMsgUIDs])
|
|
|
|
{
|
|
|
|
values = [NSArray arrayWithArray:[threadsCollapsed objectForKey:keyForMsgUIDs]];
|
|
|
|
[threadsCollapsed setObject:values forKey:newKeyForMsgUIDs];
|
|
|
|
[threadsCollapsed removeObjectForKey:keyForMsgUIDs];
|
|
|
|
[us synchronize];
|
|
|
|
}
|
2014-08-28 23:55:35 +02:00
|
|
|
}
|
2015-01-08 17:31:24 +01:00
|
|
|
newFolderPath = [[[co imap4URL] path] substringFromIndex: 1]; // remove slash at beginning of path
|
|
|
|
message = [NSDictionary dictionaryWithObject: newFolderPath
|
|
|
|
forKey: @"path"];
|
2015-12-22 03:07:43 +01:00
|
|
|
response = [self responseWithStatus: 200 andJSONRepresentation: message];
|
2014-08-28 23:55:35 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-08 17:31:24 +01:00
|
|
|
|
2008-09-19 16:03:56 +02:00
|
|
|
return response;
|
2007-05-28 15:15:27 +02:00
|
|
|
}
|
|
|
|
|
2007-05-28 21:05:00 +02:00
|
|
|
- (NSURL *) _trashedURLOfFolder: (NSURL *) srcURL
|
2016-02-09 21:46:52 +01:00
|
|
|
withObject: (SOGoMailFolder *) co
|
2007-05-28 21:05:00 +02:00
|
|
|
{
|
2009-07-01 21:28:44 +02:00
|
|
|
NSString *trashFolderName, *folderName, *path, *testPath;
|
|
|
|
NGImap4Connection *connection;
|
2016-02-09 21:46:52 +01:00
|
|
|
NSURL *destURL;
|
2009-07-01 21:28:44 +02:00
|
|
|
id test;
|
2016-02-09 21:46:52 +01:00
|
|
|
int i;
|
2009-07-01 21:28:44 +02:00
|
|
|
|
|
|
|
connection = [co imap4Connection];
|
2007-05-28 21:05:00 +02:00
|
|
|
folderName = [[srcURL path] lastPathComponent];
|
|
|
|
trashFolderName
|
|
|
|
= [[co mailAccountFolder] trashFolderNameInContext: context];
|
2007-08-08 18:20:42 +02:00
|
|
|
path = [NSString stringWithFormat: @"/%@/%@",
|
2007-11-01 13:48:19 +01:00
|
|
|
trashFolderName, folderName];
|
2009-07-01 21:28:44 +02:00
|
|
|
testPath = path;
|
2016-02-09 21:46:52 +01:00
|
|
|
i = 1;
|
|
|
|
|
2009-07-01 21:28:44 +02:00
|
|
|
while ( i < 10 )
|
|
|
|
{
|
|
|
|
test = [[connection client] select: testPath];
|
|
|
|
if (test && [[test objectForKey: @"result"] boolValue])
|
|
|
|
{
|
|
|
|
testPath = [NSString stringWithFormat: @"%@%x", path, i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = testPath;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-05-28 21:05:00 +02:00
|
|
|
destURL = [[NSURL alloc] initWithScheme: [srcURL scheme]
|
2016-02-09 21:46:52 +01:00
|
|
|
host: [srcURL host] path: path];
|
2007-05-28 21:05:00 +02:00
|
|
|
[destURL autorelease];
|
|
|
|
|
|
|
|
return destURL;
|
|
|
|
}
|
|
|
|
|
2009-06-01 19:52:24 +02:00
|
|
|
- (WOResponse *) deleteAction
|
2007-05-28 15:15:27 +02:00
|
|
|
{
|
2016-02-09 21:46:52 +01:00
|
|
|
NSString *currentMailbox, *currentAccount, *keyForMsgUIDs;
|
|
|
|
NSMutableDictionary *moduleSettings, *threadsCollapsed;
|
|
|
|
NGImap4Connection *connection;
|
2008-05-21 18:46:12 +02:00
|
|
|
SOGoMailFolder *co, *inbox;
|
2016-02-09 21:46:52 +01:00
|
|
|
NSDictionary *jsonResponse;
|
|
|
|
NSURL *srcURL, *destURL;
|
2014-08-28 23:55:35 +02:00
|
|
|
SOGoUserSettings *us;
|
2007-05-28 15:15:27 +02:00
|
|
|
WOResponse *response;
|
|
|
|
NSException *error;
|
2016-02-09 21:46:52 +01:00
|
|
|
|
|
|
|
BOOL moved;
|
2007-05-28 15:15:27 +02:00
|
|
|
|
|
|
|
co = [self clientObject];
|
2016-02-09 21:46:52 +01:00
|
|
|
moved = YES;
|
|
|
|
|
2012-09-25 16:29:24 +02:00
|
|
|
if ([co ensureTrashFolder])
|
2016-02-09 21:46:52 +01:00
|
|
|
{
|
|
|
|
connection = [co imap4Connection];
|
|
|
|
srcURL = [co imap4URL];
|
|
|
|
destURL = [self _trashedURLOfFolder: srcURL withObject: co];
|
|
|
|
connection = [co imap4Connection];
|
|
|
|
inbox = [[co mailAccountFolder] inboxFolderInContext: context];
|
|
|
|
[[connection client] select: [inbox absoluteImap4Name]];
|
|
|
|
|
|
|
|
// If srcURL is a prefix of destURL, that means we are deleting
|
|
|
|
// the folder within the 'Trash' folder, as it's getting renamed
|
|
|
|
// over and over with an integer suffix (in trashedURLOfFolder:...)
|
|
|
|
// If that is the case, we simple delete the folder, instead of renaming it
|
|
|
|
if ([[destURL path] hasPrefix: [srcURL path]])
|
|
|
|
{
|
|
|
|
error = [connection deleteMailboxAtURL: srcURL];
|
|
|
|
moved = NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error = [connection moveMailboxAtURL: srcURL toURL: destURL];
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
jsonResponse = [NSDictionary dictionaryWithObject: [self labelForKey: @"Unable to move/delete folder." inContext: context]
|
|
|
|
forKey: @"error"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: jsonResponse];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We unsubscribe to the old one, and subscribe back to the new one
|
|
|
|
if (moved)
|
|
|
|
[[connection client] subscribe: [destURL path]];
|
|
|
|
[[connection client] unsubscribe: [srcURL path]];
|
|
|
|
|
|
|
|
// Verify if the current folder have any collapsed threads save under it name and erase it
|
|
|
|
us = [[context activeUser] userSettings];
|
|
|
|
moduleSettings = [us objectForKey: @"Mail"];
|
|
|
|
threadsCollapsed = [moduleSettings objectForKey: @"threadsCollapsed"];
|
|
|
|
currentMailbox = [co nameInContainer];
|
|
|
|
currentAccount = [[co container] nameInContainer];
|
|
|
|
keyForMsgUIDs = [NSString stringWithFormat:@"/%@/%@", currentAccount, currentMailbox];
|
|
|
|
|
|
|
|
if (threadsCollapsed)
|
|
|
|
{
|
|
|
|
if ([threadsCollapsed objectForKey: keyForMsgUIDs])
|
|
|
|
{
|
|
|
|
[threadsCollapsed removeObjectForKey: keyForMsgUIDs];
|
2014-08-28 23:55:35 +02:00
|
|
|
[us synchronize];
|
2016-02-09 21:46:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
|
|
|
}
|
2007-05-28 15:15:27 +02:00
|
|
|
else
|
2016-02-09 21:46:52 +01:00
|
|
|
{
|
|
|
|
jsonResponse = [NSDictionary dictionaryWithObject: [self labelForKey: @"Unable to move/delete folder." inContext: context]
|
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: jsonResponse];
|
|
|
|
}
|
2007-05-28 15:15:27 +02:00
|
|
|
|
2007-05-28 21:05:00 +02:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2009-06-01 19:52:24 +02:00
|
|
|
- (WOResponse *) batchDeleteAction
|
2008-09-05 21:07:16 +02:00
|
|
|
{
|
2016-01-12 21:57:43 +01:00
|
|
|
NSMutableDictionary *moduleSettings, *threadsCollapsed;
|
|
|
|
NSString *currentMailbox, *currentAccount, *keyForMsgUIDs;
|
|
|
|
NSMutableArray *mailboxThreadsCollapsed;
|
2011-07-07 15:58:50 +02:00
|
|
|
SOGoMailAccount *account;
|
2014-08-28 23:55:35 +02:00
|
|
|
SOGoUserSettings *us;
|
2008-09-05 21:07:16 +02:00
|
|
|
WOResponse *response;
|
2016-01-12 21:57:43 +01:00
|
|
|
SOGoMailFolder *co;
|
2011-07-07 15:58:50 +02:00
|
|
|
NSDictionary *data;
|
2016-01-12 21:57:43 +01:00
|
|
|
WORequest *request;
|
|
|
|
|
|
|
|
id uids, quota;
|
|
|
|
|
2011-07-13 20:55:44 +02:00
|
|
|
BOOL withTrash;
|
2014-08-28 23:55:35 +02:00
|
|
|
int i;
|
2008-09-05 21:07:16 +02:00
|
|
|
|
|
|
|
response = nil;
|
2014-12-11 17:24:22 +01:00
|
|
|
request = [context request];
|
|
|
|
co = [self clientObject];
|
|
|
|
data = [[request contentAsString] objectFromJSONString];
|
|
|
|
withTrash = ![[data objectForKey: @"withoutTrash"] boolValue];
|
2008-09-05 21:07:16 +02:00
|
|
|
|
2015-08-05 20:39:58 +02:00
|
|
|
if ((uids = [data objectForKey: @"uids"]) && [uids isKindOfClass: [NSArray class]] && [uids count] > 0)
|
2008-09-05 21:07:16 +02:00
|
|
|
{
|
2011-07-13 20:55:44 +02:00
|
|
|
response = (WOResponse *) [co deleteUIDs: uids useTrashFolder: &withTrash inContext: context];
|
2008-09-22 23:31:42 +02:00
|
|
|
if (!response)
|
2011-07-07 15:58:50 +02:00
|
|
|
{
|
2011-07-13 20:55:44 +02:00
|
|
|
if (!withTrash)
|
2011-07-08 19:38:27 +02:00
|
|
|
{
|
|
|
|
// When not using a trash folder, return the quota
|
|
|
|
account = [co mailAccountFolder];
|
2016-01-12 22:02:10 +01:00
|
|
|
if ((quota = [account getInboxQuota]))
|
2016-01-12 21:57:43 +01:00
|
|
|
{
|
|
|
|
data = [NSDictionary dictionaryWithObjectsAndKeys: quota, @"quotas", nil];
|
|
|
|
response = [self responseWithStatus: 200
|
|
|
|
andString: [data jsonRepresentation]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response = [self responseWithStatus: 200];
|
2011-07-08 19:38:27 +02:00
|
|
|
}
|
|
|
|
else
|
2014-08-28 23:55:35 +02:00
|
|
|
{
|
|
|
|
// Verify if the message beeing delete is saved as the root of a collapsed thread
|
|
|
|
us = [[context activeUser] userSettings];
|
|
|
|
moduleSettings = [us objectForKey: @"Mail"];
|
|
|
|
threadsCollapsed = [moduleSettings objectForKey:@"threadsCollapsed"];
|
|
|
|
currentMailbox = [co nameInContainer];
|
|
|
|
currentAccount = [[co container] nameInContainer];
|
|
|
|
keyForMsgUIDs = [NSString stringWithFormat:@"/%@/%@", currentAccount, currentMailbox];
|
|
|
|
|
2014-09-08 18:39:55 +02:00
|
|
|
if (threadsCollapsed)
|
2014-08-28 23:55:35 +02:00
|
|
|
{
|
2014-09-08 18:39:55 +02:00
|
|
|
if ((mailboxThreadsCollapsed = [threadsCollapsed objectForKey:keyForMsgUIDs]))
|
2014-08-28 23:55:35 +02:00
|
|
|
{
|
|
|
|
for (i = 0; i < [uids count]; i++)
|
2014-08-29 15:30:40 +02:00
|
|
|
[mailboxThreadsCollapsed removeObject:[uids objectAtIndex:i]];
|
2014-08-28 23:55:35 +02:00
|
|
|
[us synchronize];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
2011-07-07 15:58:50 +02:00
|
|
|
}
|
2008-09-22 23:31:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-22 03:07:43 +01:00
|
|
|
data = [NSDictionary dictionaryWithObject: [self labelForKey: @"Missing 'uids' parameter." inContext: context]
|
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: data];
|
2008-09-05 21:07:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2008-09-30 15:42:48 +02:00
|
|
|
- (WOResponse *) saveMessagesAction
|
|
|
|
{
|
|
|
|
SOGoMailFolder *co;
|
|
|
|
WOResponse *response;
|
|
|
|
NSArray *uids;
|
2015-12-22 03:07:43 +01:00
|
|
|
NSDictionary *jsonResponse;
|
2008-09-30 15:42:48 +02:00
|
|
|
NSString *value;
|
|
|
|
|
|
|
|
co = [self clientObject];
|
|
|
|
value = [[context request] formValueForKey: @"uid"];
|
|
|
|
response = nil;
|
|
|
|
|
|
|
|
if ([value length] > 0)
|
|
|
|
{
|
|
|
|
uids = [value componentsSeparatedByString: @","];
|
2010-04-15 20:27:08 +02:00
|
|
|
response = [co archiveUIDs: uids
|
2015-08-19 16:39:10 +02:00
|
|
|
inArchiveNamed: [self labelForKey: @"Saved Messages.zip" inContext: context]
|
2010-04-15 20:27:08 +02:00
|
|
|
inContext: context];
|
2008-09-30 15:42:48 +02:00
|
|
|
if (!response)
|
|
|
|
response = [self responseWith204];
|
2008-10-03 21:01:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-22 03:07:43 +01:00
|
|
|
jsonResponse = [NSDictionary dictionaryWithObject: [self labelForKey: @"Missing 'uid' parameter." inContext: context]
|
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: jsonResponse];
|
2008-10-03 21:01:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2013-03-15 16:06:26 +01:00
|
|
|
- (id) markFolderReadAction
|
|
|
|
{
|
|
|
|
id response;
|
|
|
|
|
|
|
|
response = [[self clientObject] addFlagsToAllMessages: @"seen"];
|
|
|
|
if (!response)
|
|
|
|
response = [self responseWith204];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2010-04-15 20:27:08 +02:00
|
|
|
- (WOResponse *) exportFolderAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [[self clientObject] archiveAllMessagesInContext: context];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2008-10-03 21:01:29 +02:00
|
|
|
- (WOResponse *) copyMessagesAction
|
|
|
|
{
|
2015-07-31 20:31:38 +02:00
|
|
|
NSString *destinationFolder;
|
2011-03-17 22:26:51 +01:00
|
|
|
SOGoMailAccount *account;
|
2008-10-03 21:01:29 +02:00
|
|
|
WOResponse *response;
|
2015-06-30 23:13:55 +02:00
|
|
|
SOGoMailFolder *co;
|
2011-03-17 22:26:51 +01:00
|
|
|
NSDictionary *data;
|
2015-06-30 23:13:55 +02:00
|
|
|
NSArray *uids;
|
2008-10-03 21:01:29 +02:00
|
|
|
|
2016-01-12 21:57:43 +01:00
|
|
|
id quota;
|
|
|
|
|
2008-10-03 21:01:29 +02:00
|
|
|
co = [self clientObject];
|
2015-06-30 23:13:55 +02:00
|
|
|
data = [[[context request] contentAsString] objectFromJSONString];
|
|
|
|
uids = [data objectForKey: @"uids"];
|
|
|
|
destinationFolder = [data objectForKey: @"folder"];
|
2008-10-03 21:01:29 +02:00
|
|
|
response = nil;
|
|
|
|
|
2015-06-30 23:13:55 +02:00
|
|
|
if ([uids count] > 0)
|
|
|
|
{
|
|
|
|
response = [co copyUIDs: uids toFolder: destinationFolder inContext: context];
|
|
|
|
if (!response)
|
|
|
|
{
|
|
|
|
// We return the inbox quota
|
|
|
|
account = [co mailAccountFolder];
|
2016-01-12 22:02:10 +01:00
|
|
|
if ((quota = [account getInboxQuota]))
|
2016-01-12 21:57:43 +01:00
|
|
|
{
|
|
|
|
data = [NSDictionary dictionaryWithObject: quota forKey: @"quotas"];
|
|
|
|
response = [self responseWithStatus: 200 andJSONRepresentation: data];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response = [self responseWithStatus: 200];
|
2015-06-30 23:13:55 +02:00
|
|
|
}
|
|
|
|
}
|
2008-10-03 21:01:29 +02:00
|
|
|
else
|
2015-06-30 23:13:55 +02:00
|
|
|
{
|
2015-12-22 03:07:43 +01:00
|
|
|
data = [NSDictionary dictionaryWithObject: [self labelForKey: @"Error copying messages." inContext: context]
|
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: data];
|
2015-06-30 23:13:55 +02:00
|
|
|
}
|
2008-10-03 21:01:29 +02:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) moveMessagesAction
|
|
|
|
{
|
2015-06-30 23:13:55 +02:00
|
|
|
NSString *currentMailbox, *currentAccount, *keyForMsgUIDs;
|
|
|
|
NSMutableDictionary *moduleSettings, *threadsCollapsed;
|
|
|
|
NSMutableArray *mailboxThreadsCollapsed;
|
2015-07-31 20:31:38 +02:00
|
|
|
NSString *destinationFolder;
|
2015-10-31 07:10:03 +01:00
|
|
|
SOGoUserSettings *us=nil;
|
2008-10-03 21:01:29 +02:00
|
|
|
WOResponse *response;
|
2015-06-30 23:13:55 +02:00
|
|
|
NSDictionary *data;
|
|
|
|
SOGoMailFolder *co;
|
2008-10-03 21:01:29 +02:00
|
|
|
NSArray *uids;
|
2015-06-30 23:13:55 +02:00
|
|
|
|
2014-08-28 23:55:35 +02:00
|
|
|
int i;
|
2008-10-03 21:01:29 +02:00
|
|
|
|
|
|
|
co = [self clientObject];
|
2015-06-30 23:13:55 +02:00
|
|
|
data = [[[context request] contentAsString] objectFromJSONString];
|
|
|
|
uids = [data objectForKey: @"uids"];
|
|
|
|
destinationFolder = [data objectForKey: @"folder"];
|
2008-10-03 21:01:29 +02:00
|
|
|
response = nil;
|
|
|
|
|
2015-06-30 23:13:55 +02:00
|
|
|
if ([uids count] > 0)
|
|
|
|
{
|
|
|
|
response = [co moveUIDs: uids toFolder: destinationFolder inContext: context];
|
|
|
|
if (!response)
|
2014-08-28 23:55:35 +02:00
|
|
|
{
|
2016-02-03 22:48:04 +01:00
|
|
|
// Verify if the message being deleted is saved as the root of a collapsed thread
|
2015-06-30 23:13:55 +02:00
|
|
|
us = [[context activeUser] userSettings];
|
|
|
|
moduleSettings = [us objectForKey: @"Mail"];
|
|
|
|
threadsCollapsed = [moduleSettings objectForKey: @"threadsCollapsed"];
|
|
|
|
currentMailbox = [co nameInContainer];
|
|
|
|
currentAccount = [[co container] nameInContainer];
|
|
|
|
keyForMsgUIDs = [NSString stringWithFormat:@"/%@/%@", currentAccount, currentMailbox];
|
|
|
|
|
|
|
|
if (threadsCollapsed)
|
2014-08-28 23:55:35 +02:00
|
|
|
{
|
2015-06-30 23:13:55 +02:00
|
|
|
if ((mailboxThreadsCollapsed = [threadsCollapsed objectForKey: keyForMsgUIDs]))
|
|
|
|
{
|
|
|
|
for (i = 0; i < [uids count]; i++)
|
|
|
|
[mailboxThreadsCollapsed removeObject:[uids objectAtIndex:i]];
|
|
|
|
[us synchronize];
|
|
|
|
}
|
2014-08-28 23:55:35 +02:00
|
|
|
}
|
2015-06-30 23:13:55 +02:00
|
|
|
response = [self responseWith204];
|
2014-08-28 23:55:35 +02:00
|
|
|
}
|
2015-06-30 23:13:55 +02:00
|
|
|
}
|
2008-09-30 15:42:48 +02:00
|
|
|
else
|
2015-06-30 23:13:55 +02:00
|
|
|
{
|
2015-12-22 03:07:43 +01:00
|
|
|
data = [NSDictionary dictionaryWithObject: [self labelForKey: @"Error moving messages." inContext: context]
|
2016-02-03 22:48:04 +01:00
|
|
|
forKey: @"message"];
|
2015-12-22 03:07:43 +01:00
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: data];
|
2015-06-30 23:13:55 +02:00
|
|
|
}
|
2008-09-30 15:42:48 +02:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2010-08-06 16:29:41 +02:00
|
|
|
- (void) _setFolderPurposeOnMainAccount: (NSString *) purpose
|
|
|
|
inUserDefaults: (SOGoUserDefaults *) ud
|
|
|
|
to: (NSString *) value
|
|
|
|
{
|
|
|
|
NSString *selName;
|
|
|
|
SEL setter;
|
|
|
|
|
|
|
|
selName = [NSString stringWithFormat: @"set%@FolderName:", purpose];
|
|
|
|
setter = NSSelectorFromString (selName);
|
|
|
|
[ud performSelector: setter withObject: value];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) _setFolderPurpose: (NSString *) purpose
|
|
|
|
onAuxAccount: (int) accountIdx
|
|
|
|
inUserDefaults: (SOGoUserDefaults *) ud
|
|
|
|
to: (NSString *) value
|
|
|
|
{
|
|
|
|
NSArray *accounts;
|
|
|
|
int realIdx;
|
2015-12-22 03:07:43 +01:00
|
|
|
NSDictionary *jsonResponse;
|
2010-08-06 16:29:41 +02:00
|
|
|
NSMutableDictionary *account, *mailboxes;
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
if (accountIdx > 0)
|
|
|
|
{
|
|
|
|
realIdx = accountIdx - 1;
|
|
|
|
accounts = [ud auxiliaryMailAccounts];
|
|
|
|
if ([accounts count] > realIdx)
|
|
|
|
{
|
|
|
|
account = [accounts objectAtIndex: realIdx];
|
|
|
|
mailboxes = [account objectForKey: @"mailboxes"];
|
|
|
|
if (!mailboxes)
|
|
|
|
{
|
|
|
|
mailboxes = [NSMutableDictionary new];
|
|
|
|
[account setObject: mailboxes forKey: @"mailboxes"];
|
|
|
|
[mailboxes release];
|
|
|
|
}
|
|
|
|
[mailboxes setObject: value forKey: purpose];
|
|
|
|
[ud setAuxiliaryMailAccounts: accounts];
|
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
|
|
|
else
|
2015-12-22 03:07:43 +01:00
|
|
|
{
|
|
|
|
jsonResponse = [NSDictionary dictionaryWithObject: @"You reached an impossible end."
|
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: jsonResponse];
|
|
|
|
}
|
2010-08-06 16:29:41 +02:00
|
|
|
}
|
|
|
|
else
|
2015-12-22 03:07:43 +01:00
|
|
|
{
|
|
|
|
jsonResponse = [NSDictionary dictionaryWithObject: @"You reached an impossible end."
|
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: jsonResponse];
|
|
|
|
}
|
2010-08-06 16:29:41 +02:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-10-17 23:03:39 +02:00
|
|
|
- (WOResponse *) _setFolderPurpose: (NSString *) purpose
|
|
|
|
{
|
|
|
|
SOGoMailFolder *co;
|
|
|
|
WOResponse *response;
|
2010-08-06 16:29:41 +02:00
|
|
|
SOGoUser *owner;
|
|
|
|
SOGoUserDefaults *ud;
|
2015-12-22 03:07:43 +01:00
|
|
|
NSDictionary *jsonResponse;
|
2010-08-06 16:29:41 +02:00
|
|
|
NSString *accountIdx, *traversal;
|
2007-10-17 23:03:39 +02:00
|
|
|
|
|
|
|
co = [self clientObject];
|
2010-08-06 16:29:41 +02:00
|
|
|
if ([co isKindOfClass: [SOGoMailFolder class]])
|
2007-10-17 23:03:39 +02:00
|
|
|
{
|
2010-08-06 16:29:41 +02:00
|
|
|
accountIdx = [[co mailAccountFolder] nameInContainer];
|
|
|
|
owner = [SOGoUser userWithLogin: [co ownerInContext: nil]];
|
|
|
|
ud = [owner userDefaults];
|
|
|
|
traversal = [co traversalFromMailAccount];
|
|
|
|
if ([accountIdx isEqualToString: @"0"])
|
|
|
|
{
|
|
|
|
/* default account: we directly set the corresponding pref in the ud
|
|
|
|
*/
|
|
|
|
[self _setFolderPurposeOnMainAccount: purpose
|
|
|
|
inUserDefaults: ud
|
|
|
|
to: traversal];
|
|
|
|
response = [self responseWith204];
|
|
|
|
}
|
|
|
|
else if ([[owner domainDefaults] mailAuxiliaryUserAccountsEnabled])
|
|
|
|
response = [self _setFolderPurpose: purpose
|
|
|
|
onAuxAccount: [accountIdx intValue]
|
|
|
|
inUserDefaults: ud
|
|
|
|
to: traversal];
|
|
|
|
else
|
2015-12-22 03:07:43 +01:00
|
|
|
{
|
|
|
|
jsonResponse = [NSDictionary dictionaryWithObject: @"You reached an impossible end."
|
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: jsonResponse];
|
|
|
|
}
|
|
|
|
|
2010-08-06 16:29:41 +02:00
|
|
|
if ([response status] == 204)
|
|
|
|
[ud synchronize];
|
2007-10-17 23:03:39 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-22 03:07:43 +01:00
|
|
|
jsonResponse = [NSDictionary dictionaryWithObject: [self labelForKey: @"Unable to change the purpose of this folder." inContext: context]
|
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: jsonResponse];
|
2007-10-17 23:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) setAsDraftsFolderAction
|
|
|
|
{
|
|
|
|
return [self _setFolderPurpose: @"Drafts"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) setAsSentFolderAction
|
|
|
|
{
|
|
|
|
return [self _setFolderPurpose: @"Sent"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) setAsTrashFolderAction
|
|
|
|
{
|
|
|
|
return [self _setFolderPurpose: @"Trash"];
|
|
|
|
}
|
|
|
|
|
2016-01-22 16:30:27 +01:00
|
|
|
- (WOResponse *) setAsJunkFolderAction
|
|
|
|
{
|
|
|
|
return [self _setFolderPurpose: @"Junk"];
|
|
|
|
}
|
|
|
|
|
2007-08-17 04:33:44 +02:00
|
|
|
- (WOResponse *) expungeAction
|
|
|
|
{
|
2011-03-17 22:26:51 +01:00
|
|
|
SOGoMailAccount *account;
|
2007-08-17 04:33:44 +02:00
|
|
|
WOResponse *response;
|
2016-01-12 22:02:10 +01:00
|
|
|
SOGoTrashFolder *co;
|
|
|
|
NSException *error;
|
|
|
|
NSDictionary *data;
|
|
|
|
|
|
|
|
id quota;
|
2007-08-17 04:33:44 +02:00
|
|
|
|
|
|
|
co = [self clientObject];
|
|
|
|
|
|
|
|
error = [co expunge];
|
|
|
|
if (error)
|
|
|
|
{
|
2015-12-22 03:07:43 +01:00
|
|
|
data = [NSDictionary dictionaryWithObject: [self labelForKey: @"Unable to expunge folder." inContext: context]
|
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: data];
|
2007-08-17 04:33:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[co flushMailCaches];
|
2011-03-17 22:26:51 +01:00
|
|
|
|
|
|
|
// We return the inbox quota
|
2011-03-30 21:15:51 +02:00
|
|
|
account = [co mailAccountFolder];
|
2016-01-12 22:02:10 +01:00
|
|
|
if ((quota = [account getInboxQuota]))
|
|
|
|
{
|
|
|
|
data = [NSDictionary dictionaryWithObject: quota forKey: @"quotas"];
|
|
|
|
response = [self responseWithStatus: 200 andJSONRepresentation: data];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response = [self responseWithStatus: 200];
|
2007-08-17 04:33:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2011-03-17 22:26:51 +01:00
|
|
|
- (WOResponse *) emptyTrashAction
|
2007-05-28 21:05:00 +02:00
|
|
|
{
|
|
|
|
NSException *error;
|
|
|
|
SOGoTrashFolder *co;
|
2011-03-17 22:26:51 +01:00
|
|
|
SOGoMailAccount *account;
|
2007-05-28 21:05:00 +02:00
|
|
|
NSEnumerator *subfolders;
|
|
|
|
WOResponse *response;
|
|
|
|
NGImap4Connection *connection;
|
|
|
|
NSURL *currentURL;
|
2011-03-17 22:26:51 +01:00
|
|
|
NSDictionary *data;
|
2007-05-28 21:05:00 +02:00
|
|
|
|
2016-01-29 16:03:56 +01:00
|
|
|
id quota;
|
|
|
|
|
2007-05-28 21:05:00 +02:00
|
|
|
co = [self clientObject];
|
|
|
|
|
|
|
|
error = [co addFlagsToAllMessages: @"deleted"];
|
|
|
|
if (!error)
|
|
|
|
error = [co expunge];
|
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
[co flushMailCaches];
|
2011-07-07 15:58:50 +02:00
|
|
|
|
|
|
|
// Delete folders within the trash
|
2007-05-28 21:05:00 +02:00
|
|
|
connection = [co imap4Connection];
|
2007-10-22 18:07:12 +02:00
|
|
|
subfolders = [[co allFolderURLs] objectEnumerator];
|
2008-07-30 16:48:36 +02:00
|
|
|
while ((currentURL = [subfolders nextObject]))
|
2012-03-22 18:15:29 +01:00
|
|
|
{
|
|
|
|
[[connection client] unsubscribe: [currentURL path]];
|
|
|
|
[connection deleteMailboxAtURL: currentURL];
|
|
|
|
}
|
2007-05-28 21:05:00 +02:00
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
{
|
2015-12-22 03:07:43 +01:00
|
|
|
data = [NSDictionary dictionaryWithObject: [self labelForKey: @"Unable to empty the trash folder." inContext: context]
|
|
|
|
forKey: @"message"];
|
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: data];
|
2007-05-28 21:05:00 +02:00
|
|
|
}
|
|
|
|
else
|
2011-03-17 22:26:51 +01:00
|
|
|
{
|
|
|
|
// We return the inbox quota
|
2011-03-30 21:15:51 +02:00
|
|
|
account = [co mailAccountFolder];
|
2016-01-29 16:03:56 +01:00
|
|
|
if ((quota = [account getInboxQuota]))
|
|
|
|
{
|
|
|
|
data = [NSDictionary dictionaryWithObjectsAndKeys: quota, @"quotas", nil];
|
|
|
|
response = [self responseWithStatus: 200
|
|
|
|
andString: [data jsonRepresentation]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response = [self responseWithStatus: 200];
|
2011-03-17 22:26:51 +01:00
|
|
|
}
|
2007-05-28 21:05:00 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
mailInvitationParam
|
|
|
|
= [[context request] formValueForKey: @"mail-invitation"];
|
|
|
|
if ([mailInvitationParam boolValue])
|
|
|
|
{
|
|
|
|
clientObject = [self clientObject];
|
|
|
|
mailInvitationURL
|
|
|
|
= [[clientObject soURLToBaseContainerForCurrentUser]
|
|
|
|
absoluteString];
|
2007-11-27 23:52:34 +01:00
|
|
|
response = [self responseWithStatus: 302];
|
2007-05-30 22:12:53 +02:00
|
|
|
[response setHeader: mailInvitationURL
|
|
|
|
forKey: @"location"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-11 21:42:41 +02:00
|
|
|
response = [self responseWithStatus: 500];
|
2007-05-30 22:12:53 +02:00
|
|
|
[response appendContentString: @"How did you end up here?"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) subscribeAction
|
|
|
|
{
|
|
|
|
return [self _subscriptionStubAction];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) unsubscribeAction
|
|
|
|
{
|
|
|
|
return [self _subscriptionStubAction];
|
|
|
|
}
|
|
|
|
|
2014-09-02 19:42:04 +02:00
|
|
|
- (WOResponse *) addOrRemoveLabelAction
|
2014-09-02 16:11:27 +02:00
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
WORequest *request;
|
|
|
|
SOGoMailFolder *co;
|
2015-02-05 17:14:53 +01:00
|
|
|
NSArray *msgUIDs;
|
|
|
|
NSMutableArray *flags;
|
2014-09-02 16:11:27 +02:00
|
|
|
NSString *operation;
|
2014-09-02 19:42:04 +02:00
|
|
|
NSDictionary *content, *result;
|
2014-09-02 16:11:27 +02:00
|
|
|
BOOL addOrRemove;
|
|
|
|
NGImap4Client *client;
|
2015-09-10 17:44:09 +02:00
|
|
|
id flag;
|
2014-09-02 16:11:27 +02:00
|
|
|
|
2015-02-05 17:14:53 +01:00
|
|
|
int i;
|
|
|
|
|
2014-09-02 16:11:27 +02:00
|
|
|
request = [context request];
|
|
|
|
content = [[request contentAsString] objectFromJSONString];
|
2015-02-05 17:14:53 +01:00
|
|
|
flags = [NSMutableArray arrayWithObject:[content objectForKey:@"flags"]];
|
2014-09-02 19:42:04 +02:00
|
|
|
msgUIDs = [NSArray arrayWithArray:[content objectForKey:@"msgUIDs"]];
|
2014-09-02 16:11:27 +02:00
|
|
|
operation = [content objectForKey:@"operation"];
|
2014-09-02 20:31:46 +02:00
|
|
|
addOrRemove = ([operation isEqualToString:@"add"]? YES: NO);
|
2014-09-02 16:11:27 +02:00
|
|
|
|
2015-02-05 17:14:53 +01:00
|
|
|
// We unescape our flags
|
|
|
|
for (i = [flags count]-1; i >= 0; i--)
|
2015-09-10 17:44:09 +02:00
|
|
|
{
|
|
|
|
flag = [flags objectAtIndex: i];
|
|
|
|
if ([flag isKindOfClass: [NSString class]])
|
|
|
|
[flags replaceObjectAtIndex: i withObject: [flag fromCSSIdentifier]];
|
|
|
|
else
|
|
|
|
[flags removeObjectAtIndex: i];
|
|
|
|
}
|
2015-02-05 17:14:53 +01:00
|
|
|
|
2014-09-02 16:11:27 +02:00
|
|
|
co = [self clientObject];
|
|
|
|
client = [[co imap4Connection] client];
|
2014-09-02 19:42:04 +02:00
|
|
|
[[co imap4Connection] selectFolder: [co imap4URL]];
|
|
|
|
result = [client storeFlags:flags forUIDs:msgUIDs addOrRemove:addOrRemove];
|
2014-09-09 18:51:59 +02:00
|
|
|
if ([[result valueForKey: @"result"] boolValue])
|
2014-09-02 16:11:27 +02:00
|
|
|
response = [self responseWith204];
|
|
|
|
else
|
2015-12-22 03:07:43 +01:00
|
|
|
response = [self responseWithStatus: 500 andJSONRepresentation: result];
|
2014-09-02 19:42:04 +02:00
|
|
|
|
2014-09-02 16:11:27 +02:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) removeAllLabelsAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
2014-09-02 19:42:04 +02:00
|
|
|
WORequest *request;
|
|
|
|
SOGoMailFolder *co;
|
|
|
|
NGImap4Client *client;
|
|
|
|
NSArray *msgUIDs;
|
|
|
|
NSMutableArray *flags;
|
|
|
|
NSDictionary *v, *content, *result;
|
|
|
|
|
|
|
|
request = [context request];
|
|
|
|
content = [[request contentAsString] objectFromJSONString];
|
|
|
|
msgUIDs = [NSArray arrayWithArray:[content objectForKey:@"msgUIDs"]];
|
|
|
|
|
2014-09-02 16:11:27 +02:00
|
|
|
// We always unconditionally remove the Mozilla tags
|
|
|
|
flags = [NSMutableArray arrayWithObjects: @"$Label1", @"$Label2", @"$Label3",
|
|
|
|
@"$Label4", @"$Label5", nil];
|
2014-09-02 19:42:04 +02:00
|
|
|
|
|
|
|
co = [self clientObject];
|
|
|
|
v = [[[context activeUser] userDefaults] mailLabelsColors];
|
2014-09-02 16:11:27 +02:00
|
|
|
[flags addObjectsFromArray: [v allKeys]];
|
2014-09-02 20:31:46 +02:00
|
|
|
|
2014-09-02 19:42:04 +02:00
|
|
|
client = [[co imap4Connection] client];
|
|
|
|
[[co imap4Connection] selectFolder: [co imap4URL]];
|
|
|
|
result = [client storeFlags:flags forUIDs:msgUIDs addOrRemove:NO];
|
2014-09-02 20:31:46 +02:00
|
|
|
|
2014-09-09 18:51:59 +02:00
|
|
|
if ([[result valueForKey: @"result"] boolValue])
|
2014-09-02 16:11:27 +02:00
|
|
|
response = [self responseWith204];
|
2014-09-02 19:42:04 +02:00
|
|
|
else
|
2014-09-02 20:31:46 +02:00
|
|
|
response = [self responseWithStatus:500 andJSONRepresentation:result];
|
|
|
|
|
2014-09-02 16:11:27 +02:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2016-01-22 16:30:27 +01:00
|
|
|
- (WOResponse *) _markMessagesAsJunkOrNotJunk: (BOOL) isJunk
|
|
|
|
{
|
|
|
|
NSDictionary *content;
|
|
|
|
WOResponse *response;
|
|
|
|
WORequest *request;
|
|
|
|
SOGoMailFolder *co;
|
|
|
|
NSArray *uids;
|
|
|
|
|
|
|
|
request = [context request];
|
|
|
|
content = [[request contentAsString] objectFromJSONString];
|
|
|
|
uids = [NSArray arrayWithArray: [content objectForKey:@"uids"]];
|
|
|
|
|
|
|
|
co = [self clientObject];
|
|
|
|
|
|
|
|
if ([co markMessagesAsJunkOrNotJunk: uids junk: isJunk])
|
|
|
|
response = [self responseWithStatus: 500];
|
|
|
|
else
|
|
|
|
response = [self responseWith204];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) markMessagesAsJunkAction
|
|
|
|
{
|
|
|
|
return [self _markMessagesAsJunkOrNotJunk: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) markMessagesAsNotJunkAction
|
|
|
|
{
|
|
|
|
return [self _markMessagesAsJunkOrNotJunk: NO];
|
|
|
|
}
|
2014-09-02 16:11:27 +02:00
|
|
|
|
2007-05-28 15:15:27 +02:00
|
|
|
@end
|