From e1d8854d104a171e3a1eac701cc967b31bb0f941 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Tue, 28 Apr 2015 11:19:37 -0400 Subject: [PATCH] (fix) correctly generate the Sieve script --- UI/PreferencesUI/UIxPreferences.m | 43 ++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index b5733748e..d53cdce13 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -2077,19 +2077,20 @@ static NSArray *reminderValues = nil; // - (id ) saveAction { + id results; id o, v; o = [[[context request] contentAsString] objectFromJSONString]; - + results = nil; + // Proceed with data sanitization of the "defaults" if ((v = [o objectForKey: @"defaults"])) { - NSArray *allKeys, *accounts, *addresses; NSMutableDictionary *sanitizedLabels; + NSArray *allKeys, *accounts; NSDictionary *newLabels; - NSString *name, *reminder; + NSString *name; - NSUInteger index; int i; // We convert our object into a mutable one @@ -2140,7 +2141,32 @@ static NSArray *reminderValues = nil; } [[[user userDefaults] source] setValues: v]; - [[user userDefaults] synchronize]; + + if ([[user userDefaults] synchronize]) + { + SOGoMailAccount *account; + SOGoMailAccounts *folder; + SOGoDomainDefaults *dd; + + dd = [[context activeUser] domainDefaults]; + + // We check if the Sieve server is available *ONLY* if at least one of the option is enabled + if (!([dd sieveScriptsEnabled] || [dd vacationEnabled] || [dd forwardEnabled]) || [self _isSieveServerAvailable]) + { + + folder = [[self clientObject] mailAccountsFolder: @"Mail" + inContext: context]; + account = [folder lookupName: @"0" inContext: context acquire: NO]; + + if (![account updateFilters]) + { + results = [self responseWithStatus: 502 + andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys: @"Connection error", @"textStatus", nil]]; + } + } + results = [self responseWithStatus: 503 + andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys: @"Service temporarily unavailable", @"textStatus", nil]]; + } } if ((v = [o objectForKey: @"settings"])) @@ -2148,8 +2174,11 @@ static NSArray *reminderValues = nil; [[[user userSettings] source] setValues: v]; [[user userSettings] synchronize]; } - - return [self responseWithStatus: 200]; + + if (!results) + results = [self responseWithStatus: 200]; + + return results; } @end