2005-07-12 Helge Hess <helge.hess@opengroupware.org>
+ * UIxMailEditor.m: perform some validation plus error handling prior
+ trying to send a mail (check whether we have recipients, check
+ whether the subject is set) (#1451) (v0.9.139)
+
* UIxMailEditor.m: properly determine from-email addresses (v0.9.138)
* UIxMailEditor.m: use new SoUser API instead of AgenorUserManager
return [self->bcc isNotNull] ? self->bcc : [NSArray array];
}
+- (BOOL)hasOneOrMoreRecipients {
+ if ([[self to] count] > 0) return YES;
+ if ([[self cc] count] > 0) return YES;
+ if ([[self bcc] count] > 0) return YES;
+ return NO;
+}
+
/* from addresses */
- (NSArray *)fromEMails {
return [self _saveFormInfo] ? self : [self failedToSaveFormResponse];
}
+- (NSException *)validateForSend {
+ // TODO: localize errors
+
+ if (![self hasOneOrMoreRecipients]) {
+ return [NSException exceptionWithHTTPStatus:400 /* Bad Request */
+ reason:@"Please select a recipient!"];
+ }
+ if ([[self subject] length] == 0) {
+ return [NSException exceptionWithHTTPStatus:400 /* Bad Request */
+ reason:@"Please set a subject!"];
+ }
+
+ return nil;
+}
+
- (id)sendAction {
NSException *error;
NSString *mailPath;
if (![self _saveFormInfo])
return [self failedToSaveFormResponse];
-
+
+ /* validate for send */
+
+ if ((error = [self validateForSend]) != nil) {
+ id url;
+
+ url = [[error reason] stringByEscapingURL];
+ url = [@"edit?error=" stringByAppendingString:url];
+ return [self redirectToLocation:url];
+ }
+
/* setup some extra headers if required */
h = [self isInternetRequest] ? internetMailHeaders : nil;