1 /* UIxMailAccountActions.m - this file is part of SOGo
3 * Copyright (C) 2007 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSEnumerator.h>
27 #import <NGObjWeb/WOContext.h>
28 #import <NGObjWeb/WORequest.h>
29 #import <NGObjWeb/WOResponse.h>
30 #import <NGImap4/NGImap4Connection.h>
31 #import <SoObjects/Mailer/SOGoMailAccount.h>
32 #import <SoObjects/Mailer/SOGoDraftObject.h>
33 #import <SoObjects/Mailer/SOGoDraftsFolder.h>
34 #import <SoObjects/SOGo/NSArray+Utilities.h>
35 #import <SoObjects/SOGo/NSObject+Utilities.h>
36 #import <SoObjects/SOGo/NSString+Utilities.h>
38 #import "../Common/WODirectAction+SOGo.h"
40 #import "UIxMailAccountActions.h"
42 @implementation UIxMailAccountActions
46 if ((self = [super init]))
48 inboxFolderName = nil;
49 draftsFolderName = nil;
51 trashFolderName = nil;
59 [inboxFolderName release];
60 [draftsFolderName release];
61 [sentFolderName release];
62 [trashFolderName release];
66 - (NSString *) _folderType: (NSString *) folderName
70 NSArray *specialFolders;
74 co = [self clientObject];
75 specialFolders = [[NSArray arrayWithObjects:
76 [co inboxFolderNameInContext: context],
77 [co draftsFolderNameInContext: context],
78 [co sentFolderNameInContext: context],
79 [co trashFolderNameInContext: context],
80 nil] stringsWithFormat: @"/%@"];
81 ASSIGN (inboxFolderName, [specialFolders objectAtIndex: 0]);
82 ASSIGN (draftsFolderName, [specialFolders objectAtIndex: 1]);
83 ASSIGN (sentFolderName, [specialFolders objectAtIndex: 2]);
84 ASSIGN (trashFolderName, [specialFolders objectAtIndex: 3]);
87 if ([folderName isEqualToString: inboxFolderName])
88 folderType = @"inbox";
89 else if ([folderName isEqualToString: draftsFolderName])
90 folderType = @"draft";
91 else if ([folderName isEqualToString: sentFolderName])
93 else if ([folderName isEqualToString: trashFolderName])
94 folderType = @"trash";
96 folderType = @"folder";
101 - (NSArray *) _jsonFolders: (NSEnumerator *) rawFolders
103 NSMutableArray *folders;
104 NSString *currentFolder;
105 NSDictionary *folderData;
107 folders = [NSMutableArray array];
108 while ((currentFolder = [rawFolders nextObject]))
110 folderData = [NSDictionary dictionaryWithObjectsAndKeys:
111 currentFolder, @"path",
112 [self _folderType: currentFolder], @"type",
114 [folders addObject: folderData];
120 - (WOResponse *) listMailboxesAction
123 NSEnumerator *rawFolders;
125 WOResponse *response;
127 co = [self clientObject];
129 rawFolders = [[co allFolderPaths] objectEnumerator];
130 folders = [self _jsonFolders: rawFolders];
132 response = [self responseWithStatus: 200];
133 [response setHeader: @"text/plain; charset=utf-8"
134 forKey: @"content-type"];
135 [response appendContentString: [folders jsonRepresentation]];
142 - (WOResponse *) composeAction
144 SOGoDraftsFolder *drafts;
145 SOGoDraftObject *newDraftMessage;
146 NSString *urlBase, *url, *value;
150 drafts = [[self clientObject] draftsFolderInContext: context];
151 newDraftMessage = [drafts newDraft];
153 value = [[self request] formValueForKey: @"mailto"];
154 if ([value length] > 0)
156 mailTo = [NSArray arrayWithObject: value];
157 [newDraftMessage setHeaders: [NSDictionary dictionaryWithObject: mailTo
159 [newDraftMessage storeInfo];
162 urlBase = [newDraftMessage baseURLInContext: context];
163 url = [urlBase composeURLWithAction: @"edit"
167 return [self redirectToLocation: url];