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 #include <SOGoUI/UIxComponent.h>
24 @interface UIxMailAccountView : UIxComponent
31 #include <NGObjWeb/SoObject+SoDAV.h>
32 #include <SoObjects/Mailer/SOGoMailFolder.h>
35 @interface NSString(DotCutting)
37 - (NSString *)titleForSOGoIMAP4String;
41 @interface SOGoMailFolder(UsedPrivates)
42 - (BOOL)isCreateAllowedInACL;
45 @implementation UIxMailAccountView
47 static BOOL useAltNamespace = NO;
50 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
52 useAltNamespace = [ud boolForKey:@"SOGoSpecialFoldersInRoot"];
56 [self->inbox release];
64 [self->inbox release]; self->inbox = nil;
69 - (NSString *)objectTitle {
70 return [[[self clientObject] nameInContainer] titleForSOGoIMAP4String];
73 - (NSString *)panelTitle {
76 s = [self labelForKey:@"Mail Account"];
77 s = [s stringByAppendingString:@": "];
78 s = [s stringByAppendingString:[self objectTitle]];
82 - (BOOL)showFolderCreateButton {
83 if (!useAltNamespace) {
84 /* in a regular configuration everything must be created below INBOX */
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).
93 See OGo bug #1472 for details.
96 if (self->inbox == nil) {
99 tmp = [[self clientObject] lookupName:@"INBOX"
100 inContext:[self context]
102 if ([tmp isKindOfClass:[NSException class]] || tmp == nil)
105 self->inbox = [tmp retain];
108 if (![self->inbox isNotNull]) {
109 [self warnWithFormat:@"Found no INBOX folder!"];
113 return [self->inbox isCreateAllowedInACL];
116 /* error redirects */
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)
125 if (![_error isNotNull])
126 return [self redirectToLocation:@"view"];
128 if ([_error isKindOfClass:[NSException class]])
129 _error = [_error reason];
130 else if ([_error isKindOfClass:[NSString class]])
131 _error = [_error stringValue];
133 url = [_error stringByEscapingURL];
134 url = [@"view?error=" stringByAppendingString:url];
135 return [self redirectToLocation:url];
140 - (id)createFolderAction {
142 NSString *folderName;
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];
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];
158 if ((error = [[self clientObject] davCreateCollection:folderName
159 inContext:[self context]]) != nil) {
160 return [self redirectToViewWithError:error];
163 return [self redirectToLocation:[folderName stringByAppendingString:@"/"]];
166 @end /* UIxMailAccountView */