sogo/UI/MailerUI/UIxMailAccountActions.m
Wolfgang Sourdeau 1da963ff19 Monotone-Parent: 4f12ba210dcd4149e7496ee80e06c65b94793dd3
Monotone-Revision: 7db08f6967ccc793434ea22058755fb137e85d45

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2007-11-01T12:48:19
Monotone-Branch: ca.inverse.sogo
2007-11-01 12:48:19 +00:00

171 lines
4.6 KiB
Objective-C

/* 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>
#import <NGObjWeb/WOContext.h>
#import <NGObjWeb/WORequest.h>
#import <NGObjWeb/WOResponse.h>
#import <NGImap4/NGImap4Connection.h>
#import <SoObjects/Mailer/SOGoMailAccount.h>
#import <SoObjects/Mailer/SOGoDraftObject.h>
#import <SoObjects/Mailer/SOGoDraftsFolder.h>
#import <SoObjects/SOGo/NSArray+Utilities.h>
#import <SoObjects/SOGo/NSObject+Utilities.h>
#import <SoObjects/SOGo/NSString+Utilities.h>
#import "../Common/WODirectAction+SOGo.h"
#import "UIxMailAccountActions.h"
@implementation UIxMailAccountActions
- (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
{
NSString *folderType;
SOGoMailAccount *co;
NSArray *specialFolders;
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])
folderType = @"inbox";
else if ([folderName isEqualToString: draftsFolderName])
folderType = @"draft";
else if ([folderName isEqualToString: sentFolderName])
folderType = @"sent";
else if ([folderName isEqualToString: trashFolderName])
folderType = @"trash";
else
folderType = @"folder";
return folderType;
}
- (NSArray *) _jsonFolders: (NSEnumerator *) rawFolders
{
NSMutableArray *folders;
NSString *currentFolder;
NSDictionary *folderData;
folders = [NSMutableArray array];
while ((currentFolder = [rawFolders nextObject]))
{
folderData = [NSDictionary dictionaryWithObjectsAndKeys:
currentFolder, @"path",
[self _folderType: currentFolder], @"type",
nil];
[folders addObject: folderData];
}
return folders;
}
- (WOResponse *) listMailboxesAction
{
SOGoMailAccount *co;
NSEnumerator *rawFolders;
NSArray *folders;
WOResponse *response;
co = [self clientObject];
rawFolders = [[co allFolderPaths] objectEnumerator];
folders = [self _jsonFolders: rawFolders];
response = [self responseWithStatus: 200];
[response setHeader: @"text/plain; charset=utf-8"
forKey: @"content-type"];
[response appendContentString: [folders jsonRepresentation]];
return response;
}
/* compose */
- (WOResponse *) composeAction
{
SOGoDraftsFolder *drafts;
SOGoDraftObject *newDraftMessage;
NSString *urlBase, *url, *value;
NSArray *mailTo;
drafts = [[self clientObject] draftsFolderInContext: context];
newDraftMessage = [drafts newDraft];
value = [[self request] formValueForKey: @"mailto"];
if ([value length] > 0)
{
mailTo = [NSArray arrayWithObject: value];
[newDraftMessage setHeaders: [NSDictionary dictionaryWithObject: mailTo
forKey: @"to"]];
[newDraftMessage storeInfo];
}
urlBase = [newDraftMessage baseURLInContext: context];
url = [urlBase composeURLWithAction: @"edit"
parameters: nil
andHash: NO];
return [self redirectToLocation: url];
}
@end