refactor(preferences): conditionally activate the Sieve script

All the user defaults are now editable through the Preferences module,
even if an external Sieve script is enabled. However, the user can
disable the external Sieve script and force the activation of the
"sogo" Sieve script.
This commit is contained in:
Francis Lachapelle
2019-11-15 14:37:35 -05:00
parent 350677bbce
commit 5b3d84ee24
8 changed files with 137 additions and 94 deletions
+2 -20
View File
@@ -728,25 +728,6 @@ static NSArray *reminderValues = nil;
return [[user domainDefaults] sieveScriptsEnabled];
}
- (NSString *) hasActiveExternalSieveScripts
{
NSDictionary *scripts;
NSEnumerator *keys;
NSString *key;
scripts = [[self _sieveClient] listScripts];
keys = [scripts keyEnumerator];
while ((key = [keys nextObject]))
{
if ([key caseInsensitiveCompare: @"sogo"] != NSOrderedSame &&
[[scripts objectForKey: key] boolValue])
return @"true";
}
return @"false";
}
//
// Used by wox template
//
@@ -1645,12 +1626,13 @@ static NSArray *reminderValues = nil;
// 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])
{
BOOL forceActivation = ![[v objectForKey: @"hasActiveExternalSieveScripts"] boolValue];
folder = [[[context activeUser] homeFolderInContext: context] mailAccountsFolder: @"Mail"
inContext: context];
account = [folder lookupName: @"0" inContext: context acquire: NO];
if (![account updateFilters])
if (![account updateFiltersAndForceActivation: forceActivation])
{
results = (id <WOActionResults>) [self responseWithStatus: 502
andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys: @"Connection error", @"message", nil]];