2007-05-25 23:14:53 +02:00
|
|
|
/* UIxMailAccountActions.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-11-19 23:44:12 +01:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2007-08-17 04:30:28 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2007-05-25 23:14:53 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGImap4/NGImap4Connection.h>
|
2007-11-19 23:44:12 +01:00
|
|
|
|
2007-05-25 23:14:53 +02:00
|
|
|
#import <SoObjects/Mailer/SOGoMailAccount.h>
|
2007-08-17 04:30:28 +02:00
|
|
|
#import <SoObjects/Mailer/SOGoDraftObject.h>
|
|
|
|
#import <SoObjects/Mailer/SOGoDraftsFolder.h>
|
2007-11-01 13:48:19 +01:00
|
|
|
#import <SoObjects/SOGo/NSArray+Utilities.h>
|
2007-05-25 23:14:53 +02:00
|
|
|
#import <SoObjects/SOGo/NSObject+Utilities.h>
|
2007-08-17 04:30:28 +02:00
|
|
|
#import <SoObjects/SOGo/NSString+Utilities.h>
|
2007-11-19 23:44:12 +01:00
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
2007-08-17 04:30:28 +02:00
|
|
|
|
|
|
|
#import "../Common/WODirectAction+SOGo.h"
|
2007-05-25 23:14:53 +02:00
|
|
|
|
|
|
|
#import "UIxMailAccountActions.h"
|
|
|
|
|
|
|
|
@implementation UIxMailAccountActions
|
|
|
|
|
2007-11-01 13:48:19 +01:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
inboxFolderName = nil;
|
|
|
|
draftsFolderName = nil;
|
|
|
|
sentFolderName = nil;
|
|
|
|
trashFolderName = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[inboxFolderName release];
|
|
|
|
[draftsFolderName release];
|
|
|
|
[sentFolderName release];
|
|
|
|
[trashFolderName release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _folderType: (NSString *) folderName
|
2007-05-25 23:14:53 +02:00
|
|
|
{
|
|
|
|
NSString *folderType;
|
2007-11-01 13:48:19 +01:00
|
|
|
SOGoMailAccount *co;
|
|
|
|
NSArray *specialFolders;
|
2007-05-25 23:14:53 +02:00
|
|
|
|
2007-11-01 13:48:19 +01:00
|
|
|
if (!inboxFolderName)
|
|
|
|
{
|
|
|
|
co = [self clientObject];
|
|
|
|
specialFolders = [[NSArray arrayWithObjects:
|
|
|
|
[co inboxFolderNameInContext: context],
|
|
|
|
[co draftsFolderNameInContext: context],
|
|
|
|
[co sentFolderNameInContext: context],
|
|
|
|
[co trashFolderNameInContext: context],
|
|
|
|
nil] stringsWithFormat: @"/%@"];
|
|
|
|
ASSIGN (inboxFolderName, [specialFolders objectAtIndex: 0]);
|
|
|
|
ASSIGN (draftsFolderName, [specialFolders objectAtIndex: 1]);
|
|
|
|
ASSIGN (sentFolderName, [specialFolders objectAtIndex: 2]);
|
|
|
|
ASSIGN (trashFolderName, [specialFolders objectAtIndex: 3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([folderName isEqualToString: inboxFolderName])
|
2007-05-25 23:14:53 +02:00
|
|
|
folderType = @"inbox";
|
2007-11-01 13:48:19 +01:00
|
|
|
else if ([folderName isEqualToString: draftsFolderName])
|
2007-05-25 23:14:53 +02:00
|
|
|
folderType = @"draft";
|
2007-11-01 13:48:19 +01:00
|
|
|
else if ([folderName isEqualToString: sentFolderName])
|
2007-05-25 23:14:53 +02:00
|
|
|
folderType = @"sent";
|
2007-11-01 13:48:19 +01:00
|
|
|
else if ([folderName isEqualToString: trashFolderName])
|
2007-05-25 23:14:53 +02:00
|
|
|
folderType = @"trash";
|
|
|
|
else
|
|
|
|
folderType = @"folder";
|
|
|
|
|
|
|
|
return folderType;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) _jsonFolders: (NSEnumerator *) rawFolders
|
|
|
|
{
|
|
|
|
NSMutableArray *folders;
|
|
|
|
NSString *currentFolder;
|
2007-11-01 13:48:19 +01:00
|
|
|
NSDictionary *folderData;
|
2007-05-25 23:14:53 +02:00
|
|
|
|
|
|
|
folders = [NSMutableArray array];
|
2007-11-01 13:48:19 +01:00
|
|
|
while ((currentFolder = [rawFolders nextObject]))
|
2007-05-25 23:14:53 +02:00
|
|
|
{
|
2007-11-01 13:48:19 +01:00
|
|
|
folderData = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
currentFolder, @"path",
|
|
|
|
[self _folderType: currentFolder], @"type",
|
|
|
|
nil];
|
|
|
|
[folders addObject: folderData];
|
2007-05-25 23:14:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return folders;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) listMailboxesAction
|
|
|
|
{
|
2007-05-28 21:05:00 +02:00
|
|
|
SOGoMailAccount *co;
|
2007-11-01 13:48:19 +01:00
|
|
|
NSEnumerator *rawFolders;
|
|
|
|
NSArray *folders;
|
2007-05-25 23:14:53 +02:00
|
|
|
WOResponse *response;
|
|
|
|
|
2007-05-28 21:05:00 +02:00
|
|
|
co = [self clientObject];
|
2007-11-01 13:48:19 +01:00
|
|
|
|
|
|
|
rawFolders = [[co allFolderPaths] objectEnumerator];
|
|
|
|
folders = [self _jsonFolders: rawFolders];
|
2007-05-25 23:14:53 +02:00
|
|
|
|
2007-09-11 21:42:41 +02:00
|
|
|
response = [self responseWithStatus: 200];
|
2007-08-09 04:30:41 +02:00
|
|
|
[response setHeader: @"text/plain; charset=utf-8"
|
|
|
|
forKey: @"content-type"];
|
2007-05-25 23:14:53 +02:00
|
|
|
[response appendContentString: [folders jsonRepresentation]];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-08-17 04:30:28 +02:00
|
|
|
/* compose */
|
|
|
|
|
|
|
|
- (WOResponse *) composeAction
|
|
|
|
{
|
|
|
|
SOGoDraftsFolder *drafts;
|
|
|
|
SOGoDraftObject *newDraftMessage;
|
2007-11-19 23:44:12 +01:00
|
|
|
NSString *urlBase, *url, *value, *signature;
|
2007-08-21 16:47:26 +02:00
|
|
|
NSArray *mailTo;
|
2007-11-19 23:44:12 +01:00
|
|
|
BOOL save;
|
2007-08-17 04:30:28 +02:00
|
|
|
|
|
|
|
drafts = [[self clientObject] draftsFolderInContext: context];
|
|
|
|
newDraftMessage = [drafts newDraft];
|
|
|
|
|
2007-11-19 23:44:12 +01:00
|
|
|
save = NO;
|
|
|
|
|
2007-08-21 16:47:26 +02:00
|
|
|
value = [[self request] formValueForKey: @"mailto"];
|
|
|
|
if ([value length] > 0)
|
2007-08-17 04:30:28 +02:00
|
|
|
{
|
2007-08-21 16:47:26 +02:00
|
|
|
mailTo = [NSArray arrayWithObject: value];
|
2007-11-19 23:44:12 +01:00
|
|
|
[newDraftMessage
|
|
|
|
setHeaders: [NSDictionary dictionaryWithObject: mailTo
|
|
|
|
forKey: @"to"]];
|
|
|
|
save = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
signature = [[context activeUser] signature];
|
|
|
|
if ([signature length])
|
|
|
|
{
|
|
|
|
[newDraftMessage
|
|
|
|
setText: [NSString stringWithFormat: @"\r\n--\r\n%@", signature]];
|
|
|
|
save = YES;
|
2007-08-17 04:30:28 +02:00
|
|
|
}
|
2007-11-19 23:44:12 +01:00
|
|
|
if (save)
|
|
|
|
[newDraftMessage storeInfo];
|
2007-08-17 04:30:28 +02:00
|
|
|
|
|
|
|
urlBase = [newDraftMessage baseURLInContext: context];
|
|
|
|
url = [urlBase composeURLWithAction: @"edit"
|
|
|
|
parameters: nil
|
|
|
|
andHash: NO];
|
|
|
|
|
|
|
|
return [self redirectToLocation: url];
|
|
|
|
}
|
|
|
|
|
2007-05-25 23:14:53 +02:00
|
|
|
@end
|