return script;
}
+/* error redirects */
+
+- (id)redirectToViewWithError:(id)_error {
+ // TODO: improve, localize
+ // TODO: there is a bug in the treeview which preserves the current URL for
+ // the active object (displaying the error again)
+ id url;
+
+ if (![_error isNotNull])
+ return [self redirectToLocation:@"view"];
+
+ if ([_error isKindOfClass:[NSException class]])
+ _error = [_error reason];
+ else if ([_error isKindOfClass:[NSString class]])
+ _error = [_error stringValue];
+
+ url = [_error stringByEscapingURL];
+ url = [@"view?error=" stringByAppendingString:url];
+ return [self redirectToLocation:url];
+}
+
/* active message */
- (SOGoMailObject *)lookupActiveMessage {
id client;
if ((client = [self clientObject]) == nil) {
- return [NSException exceptionWithHTTPStatus:404 /* Not Found */
- reason:@"did not find mail folder"];
+ error = [NSException exceptionWithHTTPStatus:404 /* Not Found */
+ reason:@"did not find mail folder"];
+ return [self redirectToViewWithError:error];
}
if (![client isKindOfClass:NSClassFromString(@"SOGoTrashFolder")]) {
/* would be better to move the method to an own class, but well .. */
- return [NSException exceptionWithHTTPStatus:400 /* Bad Request */
- reason:@"method cannot be invoked on "
- @"the specified object"];
+ error = [NSException exceptionWithHTTPStatus:400 /* Bad Request */
+ reason:@"method cannot be invoked on "
+ @"the specified object"];
+ return [self redirectToViewWithError:error];
}
/* mark all as deleted */
error = [[self clientObject] addFlagsToAllMessages:@"deleted"];
if (error != nil)
// TODO: improve error
- return error;
+ return [self redirectToViewWithError:error];
/* expunge */
if ((error = [[self clientObject] expunge]) != nil)
// TODO: improve error
- return error;
+ return [self redirectToViewWithError:error];
if ([client respondsToSelector:@selector(flushMailCaches)])
[client flushMailCaches];
folderName = [[[self context] request] formValueForKey:@"name"];
if ([folderName length] == 0) {
- return [NSException exceptionWithHTTPStatus:400 /* Bad Request */
- reason:@"missing 'name' query parameter!"];
+ error = [NSException exceptionWithHTTPStatus:400 /* Bad Request */
+ reason:@"missing 'name' query parameter!"];
+ return [self redirectToViewWithError:error];
}
-
+
if ((client = [self clientObject]) == nil) {
- return [NSException exceptionWithHTTPStatus:404 /* Not Found */
- reason:@"did not find mail folder"];
+ error = [NSException exceptionWithHTTPStatus:404 /* Not Found */
+ reason:@"did not find mail folder"];
+ return [self redirectToViewWithError:error];
}
if ((error = [[self clientObject] davCreateCollection:folderName
- inContext:[self context]]) != nil)
- return error;
+ inContext:[self context]]) != nil) {
+ return [self redirectToViewWithError:error];
+ }
return [self redirectToLocation:[folderName stringByAppendingString:@"/"]];
}
id client;
if ((client = [self clientObject]) == nil) {
- return [NSException exceptionWithHTTPStatus:404 /* Not Found */
- reason:@"did not find mail folder"];
+ error = [NSException exceptionWithHTTPStatus:404 /* Not Found */
+ reason:@"did not find mail folder"];
+ return [self redirectToViewWithError:error];
}
/* jump to parent folder afterwards */
if (![url hasSuffix:@"/"]) url = [url stringByAppendingString:@"/"];
if ((error = [[self clientObject] delete]) != nil)
- return error;
+ return [self redirectToViewWithError:error];
return [self redirectToLocation:url];
}