]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailMainFrame.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1254 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / MailerUI / UIxMailMainFrame.m
1 /*
2   Copyright (C) 2004-2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #import <Foundation/NSUserDefaults.h>
23 #import <NGObjWeb/WOContext.h>
24 #import <NGObjWeb/WORequest.h>
25 #import <NGObjWeb/SoComponent.h>
26 #import <NGExtensions/NSString+misc.h>
27
28 #import <SoObjects/Mailer/SOGoMailObject.h>
29 #import <SoObjects/Mailer/SOGoMailAccounts.h>
30 #import <SoObjects/SOGo/NSDictionary+URL.h>
31 #import <SoObjects/SOGo/NSArray+Utilities.h>
32 #import <SoObjects/SOGo/SOGoUser.h>
33 #import <SOGoUI/UIxComponent.h>
34
35 #import "UIxMailMainFrame.h"
36
37 @implementation UIxMailMainFrame
38
39 /* accessors */
40 - (NSString *) mailAccounts
41 {
42   NSArray *accounts, *accountNames;
43
44   accounts = [[context activeUser] mailAccounts];
45   accountNames = [accounts objectsForKey: @"name"];
46
47   return [accountNames jsonRepresentation];
48 }
49
50 - (NSString *) pageFormURL
51 {
52   NSString *u;
53   NSRange  r;
54   
55   u = [[[self context] request] uri];
56   if ((r = [u rangeOfString:@"?"]).length > 0) {
57     /* has query parameters */
58     // TODO: this is ugly, create reusable link facility in SOPE
59     // TODO: remove 'search' and 'filterpopup', preserve sorting
60     NSMutableString *ms;
61     NSArray  *qp;
62     unsigned i, count;
63     
64     qp    = [[u substringFromIndex:(r.location + r.length)] 
65                 componentsSeparatedByString:@"&"];
66     count = [qp count];
67     ms    = [NSMutableString stringWithCapacity:count * 12];
68     
69     for (i = 0; i < count; i++) {
70       NSString *s;
71       
72       s = [qp objectAtIndex:i];
73       
74       /* filter out */
75       if ([s hasPrefix:@"search="]) continue;
76       if ([s hasPrefix:@"filterpopup="]) continue;
77       
78       if ([ms length] > 0) [ms appendString:@"&"];
79       [ms appendString:s];
80     }
81     
82     if ([ms length] == 0) {
83       /* no other query params */
84       u = [u substringToIndex:r.location];
85     }
86     else {
87       u = [u substringToIndex:r.location + r.length];
88       u = [u stringByAppendingString:ms];
89     }
90     return u;
91   }
92   return [u hasSuffix:@"/"] ? @"view" : @"#";
93 }
94
95 - (id <WOActionResults>) composeAction
96 {
97   NSArray *accounts;
98   NSString *firstAccount, *newLocation;
99   SOGoMailAccounts *co;
100   NSDictionary *formValues;
101
102   co = [self clientObject];
103   accounts = [[context activeUser] mailAccounts];
104   firstAccount = [[accounts objectsForKey: @"name"] objectAtIndex: 0];
105   formValues = [[context request] formValues];
106   newLocation = [NSString stringWithFormat: @"%@/%@/compose%@",
107                           [co baseURLInContext: context],
108                           firstAccount,
109                           [formValues asURLParameters]];
110
111   return [self redirectToLocation: newLocation];
112 }
113
114 @end /* UIxMailMainFrame */