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+SoObjects.h>
28 #import <NGObjWeb/WORequest.h>
29 #import <NGObjWeb/WOResponse.h>
30 #import <NGImap4/NGImap4Connection.h>
32 #import <SoObjects/Mailer/SOGoMailAccount.h>
33 #import <SoObjects/Mailer/SOGoDraftObject.h>
34 #import <SoObjects/Mailer/SOGoDraftsFolder.h>
35 #import <SoObjects/SOGo/NSArray+Utilities.h>
36 #import <SoObjects/SOGo/NSObject+Utilities.h>
37 #import <SoObjects/SOGo/NSString+Utilities.h>
38 #import <SoObjects/SOGo/SOGoUser.h>
40 #import "../Common/WODirectAction+SOGo.h"
42 #import "UIxMailAccountActions.h"
44 @implementation UIxMailAccountActions
48 if ((self = [super init]))
50 inboxFolderName = nil;
51 draftsFolderName = nil;
53 trashFolderName = nil;
61 [inboxFolderName release];
62 [draftsFolderName release];
63 [sentFolderName release];
64 [trashFolderName release];
68 - (NSString *) _folderType: (NSString *) folderName
72 NSArray *specialFolders;
76 co = [self clientObject];
77 specialFolders = [[NSArray arrayWithObjects:
78 [co inboxFolderNameInContext: context],
79 [co draftsFolderNameInContext: context],
80 [co sentFolderNameInContext: context],
81 [co trashFolderNameInContext: context],
82 nil] stringsWithFormat: @"/%@"];
83 ASSIGN (inboxFolderName, [specialFolders objectAtIndex: 0]);
84 ASSIGN (draftsFolderName, [specialFolders objectAtIndex: 1]);
85 ASSIGN (sentFolderName, [specialFolders objectAtIndex: 2]);
86 ASSIGN (trashFolderName, [specialFolders objectAtIndex: 3]);
89 if ([folderName isEqualToString: inboxFolderName])
90 folderType = @"inbox";
91 else if ([folderName isEqualToString: draftsFolderName])
92 folderType = @"draft";
93 else if ([folderName isEqualToString: sentFolderName])
95 else if ([folderName isEqualToString: trashFolderName])
96 folderType = @"trash";
98 folderType = @"folder";
103 - (NSArray *) _jsonFolders: (NSEnumerator *) rawFolders
105 NSMutableArray *folders;
106 NSString *currentFolder;
107 NSDictionary *folderData;
109 folders = [NSMutableArray array];
110 while ((currentFolder = [rawFolders nextObject]))
112 folderData = [NSDictionary dictionaryWithObjectsAndKeys:
113 currentFolder, @"path",
114 [self _folderType: currentFolder], @"type",
116 [folders addObject: folderData];
122 - (WOResponse *) listMailboxesAction
125 NSEnumerator *rawFolders;
127 WOResponse *response;
129 co = [self clientObject];
131 rawFolders = [[co allFolderPaths] objectEnumerator];
132 folders = [self _jsonFolders: rawFolders];
134 response = [self responseWithStatus: 200];
135 [response setHeader: @"text/plain; charset=utf-8"
136 forKey: @"content-type"];
137 [response appendContentString: [folders jsonRepresentation]];
144 - (WOResponse *) composeAction
146 SOGoDraftsFolder *drafts;
147 SOGoDraftObject *newDraftMessage;
148 NSString *urlBase, *url, *value, *signature;
152 drafts = [[self clientObject] draftsFolderInContext: context];
153 newDraftMessage = [drafts newDraft];
157 value = [[self request] formValueForKey: @"mailto"];
158 if ([value length] > 0)
160 mailTo = [NSArray arrayWithObject: value];
162 setHeaders: [NSDictionary dictionaryWithObject: mailTo
167 signature = [[context activeUser] signature];
168 if ([signature length])
171 setText: [NSString stringWithFormat: @"\r\n--\r\n%@", signature]];
175 [newDraftMessage storeInfo];
177 urlBase = [newDraftMessage baseURLInContext: context];
178 url = [urlBase composeURLWithAction: @"edit"
182 return [self redirectToLocation: url];