2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <Foundation/NSUserDefaults.h>
24 #import <NGObjWeb/WOContext.h>
25 #import <NGObjWeb/WORequest.h>
26 #import <NGObjWeb/WOResponse.h>
27 #import <NGObjWeb/SoComponent.h>
28 #import <NGExtensions/NSString+misc.h>
30 #import <SoObjects/Mailer/SOGoMailObject.h>
31 #import <SoObjects/Mailer/SOGoMailAccounts.h>
32 #import <SoObjects/SOGo/NSDictionary+URL.h>
33 #import <SoObjects/SOGo/NSArray+Utilities.h>
34 #import <SoObjects/SOGo/SOGoUser.h>
35 #import <SOGoUI/UIxComponent.h>
37 #import "UIxMailMainFrame.h"
39 @implementation UIxMailMainFrame
41 - (void) _setupContext
44 NSString *login, *module;
45 SOGoMailAccounts *clientObject;
47 activeUser = [context activeUser];
48 login = [activeUser login];
49 clientObject = [self clientObject];
51 module = [clientObject nameInContainer];
53 ud = [activeUser userSettings];
54 moduleSettings = [ud objectForKey: module];
57 moduleSettings = [NSMutableDictionary new];
58 [moduleSettings autorelease];
60 [ud setObject: moduleSettings forKey: module];
64 - (NSString *) mailAccounts
66 NSArray *accounts, *accountNames;
68 accounts = [[context activeUser] mailAccounts];
69 accountNames = [accounts objectsForKey: @"name"];
71 return [accountNames jsonRepresentation];
74 - (NSString *) pageFormURL
79 u = [[[self context] request] uri];
80 if ((r = [u rangeOfString:@"?"]).length > 0) {
81 /* has query parameters */
82 // TODO: this is ugly, create reusable link facility in SOPE
83 // TODO: remove 'search' and 'filterpopup', preserve sorting
88 qp = [[u substringFromIndex:(r.location + r.length)]
89 componentsSeparatedByString:@"&"];
91 ms = [NSMutableString stringWithCapacity:count * 12];
93 for (i = 0; i < count; i++) {
96 s = [qp objectAtIndex:i];
99 if ([s hasPrefix:@"search="]) continue;
100 if ([s hasPrefix:@"filterpopup="]) continue;
102 if ([ms length] > 0) [ms appendString:@"&"];
106 if ([ms length] == 0) {
107 /* no other query params */
108 u = [u substringToIndex:r.location];
111 u = [u substringToIndex:r.location + r.length];
112 u = [u stringByAppendingString:ms];
116 return [u hasSuffix:@"/"] ? @"view" : @"#";
119 - (id <WOActionResults>) composeAction
122 NSString *firstAccount, *newLocation, *parameters;
123 SOGoMailAccounts *co;
124 NSDictionary *formValues;
126 co = [self clientObject];
127 accounts = [[context activeUser] mailAccounts];
128 firstAccount = [[accounts objectsForKey: @"name"] objectAtIndex: 0];
129 formValues = [[context request] formValues];
130 parameters = [formValues count] > 0 ? [formValues asURLParameters] : @"?mailto=";
131 newLocation = [NSString stringWithFormat: @"%@/%@/compose%@",
132 [co baseURLInContext: context],
136 return [self redirectToLocation: newLocation];
139 - (WOResponse *) getFoldersStateAction
141 NSString *expandedFolders;
143 [self _setupContext];
144 expandedFolders = [moduleSettings objectForKey: @"ExpandedFolders"];
146 return [self responseWithStatus: 200 andString: expandedFolders];
149 - (WOResponse *) saveFoldersStateAction
152 NSString *expandedFolders;
154 [self _setupContext];
155 request = [context request];
156 expandedFolders = [request formValueForKey: @"expandedFolders"];
158 [moduleSettings setObject: expandedFolders
159 forKey: @"ExpandedFolders"];
163 return [self responseWithStatus: 204];
166 @end /* UIxMailMainFrame */