]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailAccountView.m
fixed strings file for Cocoa
[scalable-opengroupware.org] / UI / MailerUI / UIxMailAccountView.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 #include <SOGoUI/UIxComponent.h>
23
24 @interface UIxMailAccountView : UIxComponent
25 {
26   id inbox;
27 }
28
29 @end
30
31 #include <NGObjWeb/SoObject+SoDAV.h>
32 #include <SoObjects/Mailer/SOGoMailFolder.h>
33 #include "common.h"
34
35 @interface NSString(DotCutting)
36
37 - (NSString *)titleForSOGoIMAP4String;
38
39 @end
40
41 @interface SOGoMailFolder(UsedPrivates)
42 - (BOOL)isCreateAllowedInACL;
43 @end
44
45 @implementation UIxMailAccountView
46
47 static BOOL useAltNamespace = NO;
48
49 + (void)initialize {
50   NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
51   
52   useAltNamespace = [ud boolForKey:@"SOGoSpecialFoldersInRoot"];
53 }
54
55 - (void)dealloc {
56   [self->inbox release];
57   [super dealloc];
58 }
59
60 /* notifications */
61
62 - (void)sleep {
63   [super sleep];
64   [self->inbox release]; self->inbox = nil;
65 }
66
67 /* title */
68
69 - (NSString *)objectTitle {
70   return [[[self clientObject] nameInContainer] titleForSOGoIMAP4String];
71 }
72
73 - (NSString *)panelTitle {
74   NSString *s;
75   
76   s = [self labelForKey:@"Mail Account"];
77   s = [s stringByAppendingString:@": "];
78   s = [s stringByAppendingString:[self objectTitle]];
79   return s;
80 }
81
82 - (BOOL)showFolderCreateButton {
83   if (!useAltNamespace) {
84     /* in a regular configuration everything must be created below INBOX */
85     return NO;
86   }
87   
88   /* 
89      A hack to manually check whether we have permission to create folders at
90      the root level. We do this by checking the permissions on the INBOX
91      folder (which is technically the root in Cyrus).
92      
93      See OGo bug #1472 for details.
94   */
95   
96   if (self->inbox == nil) {
97     id tmp;
98     
99     tmp = [[self clientObject] lookupName:@"INBOX" 
100                                inContext:[self context]
101                                acquire:NO];
102     if ([tmp isKindOfClass:[NSException class]] || tmp == nil)
103       tmp = [NSNull null];
104     
105     self->inbox = [tmp retain];
106   }
107   
108   if (![self->inbox isNotNull]) {
109     [self warnWithFormat:@"Found no INBOX folder!"];
110     return NO;
111   }
112   
113   return [self->inbox isCreateAllowedInACL];
114 }
115
116 /* error redirects */
117
118 - (id)redirectToViewWithError:(id)_error {
119   // TODO: DUP to UIxMailListView
120   // TODO: improve, localize
121   // TODO: there is a bug in the treeview which preserves the current URL for
122   //       the active object (displaying the error again)
123   id url;
124   
125   if (![_error isNotNull])
126     return [self redirectToLocation:@"view"];
127   
128   if ([_error isKindOfClass:[NSException class]])
129     _error = [_error reason];
130   else if ([_error isKindOfClass:[NSString class]])
131     _error = [_error stringValue];
132   
133   url = [_error stringByEscapingURL];
134   url = [@"view?error=" stringByAppendingString:url];
135   return [self redirectToLocation:url];
136 }
137
138 /* actions */
139
140 - (id)createFolderAction {
141   NSException *error;
142   NSString    *folderName;
143   id client;
144   
145   folderName = [[[self context] request] formValueForKey:@"name"];
146   if ([folderName length] == 0) {
147     error = [NSException exceptionWithHTTPStatus:400 /* Bad Request */
148                          reason:@"missing 'name' query parameter!"];
149     return [self redirectToViewWithError:error];
150   }
151   
152   if ((client = [self clientObject]) == nil) {
153     error = [NSException exceptionWithHTTPStatus:404 /* Not Found */
154                          reason:@"did not find mail folder"];
155     return [self redirectToViewWithError:error];
156   }
157   
158   if ((error = [[self clientObject] davCreateCollection:folderName
159                                     inContext:[self context]]) != nil) {
160     return [self redirectToViewWithError:error];
161   }
162   
163   return [self redirectToLocation:[folderName stringByAppendingString:@"/"]];
164 }
165
166 @end /* UIxMailAccountView */