fix(core): don't disable the current script if we aren't doing anything

pull/281/head
Ludovic Marcotte 2019-11-07 15:27:43 -05:00
parent ac91a303c9
commit 2bc24eca82
1 changed files with 22 additions and 21 deletions

View File

@ -1079,6 +1079,7 @@ static NSString *sieveScriptName = @"sogo";
v = [self _extractRequirementsFromContent: content v = [self _extractRequirementsFromContent: content
intoArray: req]; intoArray: req];
[script insertString: v atIndex: 0]; [script insertString: v atIndex: 0];
b = YES;
} }
} }
@ -1101,38 +1102,38 @@ static NSString *sieveScriptName = @"sogo";
header = [NSString stringWithFormat: @"require [\"%@\"];\r\n", header = [NSString stringWithFormat: @"require [\"%@\"];\r\n",
[[req uniqueObjects] componentsJoinedByString: @"\",\""]]; [[req uniqueObjects] componentsJoinedByString: @"\",\""]];
[script insertString: header atIndex: 0]; [script insertString: header atIndex: 0];
b = YES;
} }
/* We ensure to deactive the current active script since it could prevent /* We ensure to deactive the current active script since it could prevent
its deletion from the server. */ its deletion from the server. */
result = [client setActiveScript: @""];
// We delete the existing Sieve script
result = [client deleteScript: sieveScriptName];
if (![[result valueForKey:@"result"] boolValue]) {
[self logWithFormat: @"WARNING: Could not delete Sieve script - continuing...: %@", result];
}
// We put and activate the script only if we actually have a script
// that does something...
if (b && [script length]) if (b && [script length])
{ {
result = [client setActiveScript: @""];
// We delete the existing Sieve script
result = [client deleteScript: sieveScriptName];
if (![[result valueForKey:@"result"] boolValue])
[self logWithFormat: @"WARNING: Could not delete Sieve script - continuing...: %@", result];
result = [client putScript: sieveScriptName script: script]; result = [client putScript: sieveScriptName script: script];
if (![[result valueForKey:@"result"] boolValue]) { if (![[result valueForKey:@"result"] boolValue])
[self logWithFormat: @"Could not upload Sieve script: %@", result]; {
[client closeConnection]; [self logWithFormat: @"Could not upload Sieve script: %@", result];
return NO; [client closeConnection];
} return NO;
}
result = [client setActiveScript: sieveScriptName]; result = [client setActiveScript: sieveScriptName];
if (![[result valueForKey:@"result"] boolValue]) { if (![[result valueForKey:@"result"] boolValue])
[self logWithFormat: @"Could not enable Sieve script: %@", result]; {
[client closeConnection]; [self logWithFormat: @"Could not enable Sieve script: %@", result];
return NO; [client closeConnection];
} return NO;
} }
}
[client closeConnection]; [client closeConnection];
return YES; return YES;