From 349f4d824a297f41f2d04087bcff49b49f70cd60 Mon Sep 17 00:00:00 2001 From: Alexandre Cloutier Date: Fri, 4 Apr 2014 15:04:37 -0400 Subject: [PATCH] Fix function sieveClient and the way the iVar Client is handled. Change behaviour of saveMailAccounts()so sogo wont crash if the user tries to resave his preferences after a connection error. --- .gitignore | 1 + .../English.lproj/Localizable.strings | 4 +- UI/PreferencesUI/UIxPreferences.m | 57 +++--- UI/WebServerResources/UIxPreferences.js | 165 +++++++++--------- 4 files changed, 118 insertions(+), 109 deletions(-) diff --git a/.gitignore b/.gitignore index 88becdaa6..2b228461b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ config.make tags */obj/ +*._* */*/obj/ */*/*/obj/ */*/*.SOGo/ diff --git a/UI/PreferencesUI/English.lproj/Localizable.strings b/UI/PreferencesUI/English.lproj/Localizable.strings index 10fbf68a3..75e7c4be7 100644 --- a/UI/PreferencesUI/English.lproj/Localizable.strings +++ b/UI/PreferencesUI/English.lproj/Localizable.strings @@ -248,8 +248,8 @@ "Active" = "Active"; "Move Up" = "Move Up"; "Move Down" = "Move Down"; -"ConnectionError" = "Connection error"; -"ServiceTemporarilyUnavailable" = "Service temporarily unavailable"; +"Connection error" = "Connection error"; +"Service temporarily unavailable" = "Service temporarily unavailable"; /* Filters - UIxFilterEditor */ "Filter name:" = "Filter name:"; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index b1a0e1a8c..bd66f8761 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -114,7 +114,7 @@ static NSArray *reminderValues = nil; if ((self = [super init])) { item = nil; - client = [self getClient]; + client = nil; #warning user should be the owner rather than the activeUser ASSIGN (user, [context activeUser]); @@ -847,8 +847,8 @@ static NSArray *reminderValues = nil; if (!capabilities) { - if (client) - capabilities = [client capabilities]; + if ([self sieveClient]) + capabilities = [[self sieveClient] capabilities]; else capabilities = [NSArray array]; [capabilities retain]; @@ -1129,22 +1129,26 @@ static NSArray *reminderValues = nil; } } -- (id) sieveClient{ +- (id) sieveClient +{ SOGoMailAccount *account; SOGoMailAccounts *folder; SOGoSieveManager *manager; - NGSieveClient *sieveClient; - folder = [[self clientObject] mailAccountsFolder: @"Mail" inContext: context]; - account = [folder lookupName: @"0" inContext: context acquire: NO]; - manager = [SOGoSieveManager sieveManagerForUser: [context activeUser]]; - sieveClient = [manager clientForAccount: account]; + if (client == nil) + { + folder = [[self clientObject] mailAccountsFolder: @"Mail" inContext: context]; + account = [folder lookupName: @"0" inContext: context acquire: NO]; + manager = [SOGoSieveManager sieveManagerForUser: [context activeUser]]; + client = [manager clientForAccount: account]; + } - return sieveClient; + return client; } -- (BOOL) isSieveServerAvailable { - return (([client isConnected]) +- (BOOL) isSieveServerAvailable +{ + return (([[self sieveClient] isConnected]) ? true : false); } @@ -1159,35 +1163,34 @@ static NSArray *reminderValues = nil; WORequest *request; request = [context request]; - if ([[request method] isEqualToString: @"POST"]){ + if ([[request method] isEqualToString: @"POST"]) + { dd = [[context activeUser] domainDefaults]; if ([dd sieveScriptsEnabled]) - [userDefaults setSieveFilters: sieveFilters]; + [userDefaults setSieveFilters: sieveFilters]; if ([dd vacationEnabled]) - [userDefaults setVacationOptions: vacationOptions]; + [userDefaults setVacationOptions: vacationOptions]; if ([dd forwardEnabled]) - [userDefaults setForwardOptions: forwardOptions]; + [userDefaults setForwardOptions: forwardOptions]; - if([self isSieveServerAvailable]){ + if([self isSieveServerAvailable]) + { [userDefaults synchronize]; folder = [[self clientObject] mailAccountsFolder: @"Mail" inContext: context]; account = [folder lookupName: @"0" inContext: context acquire: NO]; - if([account updateFilters]){ + if([account updateFilters]) results = [self responseWithStatus: 200 andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:hasChanged], @"hasChanged", nil]]; - } - else{ - results = [self responseWithStatus: 502 andJSONRepresentation:[NSDictionary dictionaryWithObjectsAndKeys: @"ConnectionError", @"textStatus", nil]]; - } - } - else{ - results = [self responseWithStatus: 503 andJSONRepresentation:[NSDictionary dictionaryWithObjectsAndKeys: @"ServiceTemporarilyUnavailable", @"textStatus", nil]]; + + else + results = [self responseWithStatus: 502 andJSONRepresentation:[NSDictionary dictionaryWithObjectsAndKeys: @"Connection error", @"textStatus", nil]]; } + else + results = [self responseWithStatus: 503 andJSONRepresentation:[NSDictionary dictionaryWithObjectsAndKeys: @"Service temporarily unavailable", @"textStatus", nil]]; } - else{ + else results = self; - } return results; } diff --git a/UI/WebServerResources/UIxPreferences.js b/UI/WebServerResources/UIxPreferences.js index c8c6584c6..306873924 100644 --- a/UI/WebServerResources/UIxPreferences.js +++ b/UI/WebServerResources/UIxPreferences.js @@ -3,85 +3,85 @@ var mailAccounts = null; var dialogs = {}; function savePreferences(sender) { - var sendForm = true; - - var sigList = $("signaturePlacementList"); - if (sigList) - sigList.disabled = false; - - if ($("calendarCategoriesListWrapper")) { - serializeCalendarCategories(); + var sendForm = true; + + var sigList = $("signaturePlacementList"); + if (sigList) + sigList.disabled = false; + + if ($("calendarCategoriesListWrapper")) + serializeCalendarCategories(); + + if ($("contactsCategoriesListWrapper")) + serializeContactsCategories(); + + if ($("mailLabelsListWrapper")) + serializeMailLabels(); + + if (typeof mailCustomFromEnabled !== "undefined" && !emailRE.test($("email").value)) { + showAlertDialog(_("Please specify a valid sender address.")); + sendForm = false; + } + + if ($("replyTo")) { + var replyTo = $("replyTo").value; + if (!replyTo.blank() && !emailRE.test(replyTo)) { + showAlertDialog(_("Please specify a valid reply-to address.")); + sendForm = false; } - if ($("contactsCategoriesListWrapper")) { - serializeContactsCategories(); + } + + if ($("dayStartTime")) { + var start = $("dayStartTime"); + var selectedStart = parseInt(start.options[start.selectedIndex].value); + var end = $("dayEndTime"); + var selectedEnd = parseInt(end.options[end.selectedIndex].value); + + if (selectedStart >= selectedEnd) { + showAlertDialog (_("Day start time must be prior to day end time.")); + sendForm = false; } - - if ($("mailLabelsListWrapper")) { - serializeMailLabels(); + } + + if ($("enableVacation") && $("enableVacation").checked) { + if ($("autoReplyText").value.strip().length == 0 || $("autoReplyEmailAddresses").value.strip().length == 0) { + showAlertDialog(_("Please specify your message and your email addresses for which you want to enable auto reply.")); + sendForm = false; } - - if (typeof mailCustomFromEnabled !== "undefined" && !emailRE.test($("email").value)) { - showAlertDialog(_("Please specify a valid sender address.")); - sendForm = false; - } - - if ($("replyTo")) { - var replyTo = $("replyTo").value; - if (!replyTo.blank() && !emailRE.test(replyTo)) { - showAlertDialog(_("Please specify a valid reply-to address.")); - sendForm = false; - } - } - - if ($("dayStartTime")) { - var start = $("dayStartTime"); - var selectedStart = parseInt(start.options[start.selectedIndex].value); - var end = $("dayEndTime"); - var selectedEnd = parseInt(end.options[end.selectedIndex].value); - if (selectedStart >= selectedEnd) { - showAlertDialog (_("Day start time must be prior to day end time.")); - sendForm = false; - } - } - - if ($("enableVacation") && $("enableVacation").checked) { - if ($("autoReplyText").value.strip().length == 0 - || $("autoReplyEmailAddresses").value.strip().length == 0) { - showAlertDialog(_("Please specify your message and your email addresses for which you want to enable auto reply.")); - sendForm = false; - } - if ($("autoReplyText").value.strip().endsWith('\n.')) { - showAlertDialog(_("Your vacation message must not end with a single dot on a line.")); + + if ($("autoReplyText").value.strip().endsWith('\n.')) { + showAlertDialog(_("Your vacation message must not end with a single dot on a line.")); sendForm = false; - } - if ($("enableVacationEndDate") && $("enableVacationEndDate").checked) { - var e = $("vacationEndDate_date"); - var endDate = e.inputAsDate(); - var now = new Date(); - if (isNaN(endDate.getTime()) || endDate.getTime() < now.getTime()) { - showAlertDialog(_("End date of your auto reply must be in the future.")); - sendForm = false; - } - } } - - if ($("enableForward") && $("enableForward").checked) { - var addresses = $("forwardAddress").value.split(","); - for (var i = 0; i < addresses.length && sendForm; i++) - if (!emailRE.test(addresses[i].strip())) { - showAlertDialog(_("Please specify an address to which you want to forward your messages.")); - sendForm = false; - } + + if ($("enableVacationEndDate") && $("enableVacationEndDate").checked) { + var e = $("vacationEndDate_date"); + var endDate = e.inputAsDate(); + var now = new Date(); + if (isNaN(endDate.getTime()) || endDate.getTime() < now.getTime()) { + showAlertDialog(_("End date of your auto reply must be in the future.")); + sendForm = false; + } } - - if (typeof sieveCapabilities != "undefined") { - var jsonFilters = prototypeIfyFilters(); - $("sieveFilters").setValue(Object.toJSON(jsonFilters)); - } - - if (sendForm) { - saveMailAccounts(); - + } + + if ($("enableForward") && $("enableForward").checked) { + var addresses = $("forwardAddress").value.split(","); + for (var i = 0; i < addresses.length && sendForm; i++) + if (!emailRE.test(addresses[i].strip())) { + showAlertDialog(_("Please specify an address to which you want to forward your messages.")); + sendForm = false; + } + } + + if (typeof sieveCapabilities != "undefined") { + var jsonFilters = prototypeIfyFilters(); + $("sieveFilters").setValue(Object.toJSON(jsonFilters)); + } + + if (sendForm) { + saveMailAccounts(); + triggerAjaxRequest($("mainForm").readAttribute("action"), function (http) { if (http.readyState == 4) { var response = http.responseText.evalJSON(true); @@ -91,17 +91,21 @@ function savePreferences(sender) { else if (http.status == 200) { if (response.hasChanged == 1) { window.opener.location.reload(); - window.close();} + window.close(); + } else { - window.close();}} + window.close(); + } + } else { showAlertDialog(_(response.textStatus)); } } - }, - null, - Form.serialize($("mainForm")), // excludes the file input - { "Content-type": "application/x-www-form-urlencoded" }); + }, + null, + Form.serialize($("mainForm")), // excludes the file input + { "Content-type": "application/x-www-form-urlencoded"} + ); } return false; } @@ -879,7 +883,8 @@ function saveMailAccounts() { // Could be null if ModuleConstraints disables email access if (editor) - editor.parentNode.removeChild(editor); + //Instead of removing the modules, we disable it. This will prevent the window to crash if we have a connection error. + editor.select('input, select').each(function(i) { i.disable(); }) compactMailAccounts(); var mailAccountsJSON = $("mailAccountsJSON");