diff --git a/SoObjects/SOGo/SOGoSieveManager.m b/SoObjects/SOGo/SOGoSieveManager.m index 765ad32d6..3254e70ce 100644 --- a/SoObjects/SOGo/SOGoSieveManager.m +++ b/SoObjects/SOGo/SOGoSieveManager.m @@ -755,7 +755,7 @@ static NSString *sieveScriptName = @"sogo"; return nil; } - return client; + return [client autorelease]; } diff --git a/UI/PreferencesUI/English.lproj/Localizable.strings b/UI/PreferencesUI/English.lproj/Localizable.strings index ccd8890a4..99a3c2258 100644 --- a/UI/PreferencesUI/English.lproj/Localizable.strings +++ b/UI/PreferencesUI/English.lproj/Localizable.strings @@ -252,6 +252,8 @@ "Active" = "Active"; "Move Up" = "Move Up"; "Move Down" = "Move Down"; +"Connection error" = "Connection error"; +"Service temporarily unavailable" = "Service temporarily unavailable"; /* Filters - UIxFilterEditor */ "Filter name:" = "Filter name:"; diff --git a/UI/PreferencesUI/UIxPreferences.h b/UI/PreferencesUI/UIxPreferences.h index 9c8a3483f..bbbb0a2b1 100644 --- a/UI/PreferencesUI/UIxPreferences.h +++ b/UI/PreferencesUI/UIxPreferences.h @@ -22,6 +22,7 @@ #define UIXPREFERENCES_H #import +#import @class NSString; @@ -32,7 +33,8 @@ { id item; SOGoUser *user; - + NGSieveClient *client; + // Addressbook NSMutableDictionary *addressBooksIDWithDisplayName; @@ -61,6 +63,8 @@ } - (NSString *) userLongDateFormat; +- (BOOL) isSieveServerAvailable; +- (id) sieveClient; @end diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 9d9a35a5a..94723a047 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -119,6 +119,7 @@ static NSArray *reminderValues = nil; { item = nil; addressBooksIDWithDisplayName = nil; + client = nil; #warning user should be the owner rather than the activeUser ASSIGN (user, [context activeUser]); ASSIGN (today, [NSCalendarDate date]); @@ -180,6 +181,7 @@ static NSArray *reminderValues = nil; [forwardOptions release]; [daysOfWeek release]; [addressBooksIDWithDisplayName release]; + [client release]; [super dealloc]; } @@ -919,26 +921,15 @@ static NSArray *reminderValues = nil; - (NSString *) sieveCapabilities { -#warning sieve caps should be deduced from the server static NSArray *capabilities = nil; - SOGoMailAccounts *folder; - SOGoMailAccount *account; - SOGoSieveManager *manager; - NGSieveClient *client; if (!capabilities) { - folder = [[self clientObject] mailAccountsFolder: @"Mail" - inContext: context]; - account = [folder lookupName: @"0" inContext: context acquire: NO]; - manager = [SOGoSieveManager sieveManagerForUser: [context activeUser]]; - client = [manager clientForAccount: account]; - - if (client) - capabilities = [client capabilities]; + if ([self sieveClient]) + capabilities = [[self sieveClient] capabilities]; else capabilities = [NSArray array]; - [capabilities retain]; + [capabilities retain]; } return [capabilities jsonRepresentation]; @@ -1222,44 +1213,68 @@ static NSArray *reminderValues = nil; return [NSString stringWithString: SOGoVersion]; } +- (id) sieveClient +{ + SOGoMailAccount *account; + SOGoMailAccounts *folder; + SOGoSieveManager *manager; + + if (!client) + { + folder = [[self clientObject] mailAccountsFolder: @"Mail" inContext: context]; + account = [folder lookupName: @"0" inContext: context acquire: NO]; + manager = [SOGoSieveManager sieveManagerForUser: [context activeUser]]; + client = [[manager clientForAccount: account] retain]; + } + + return client; +} + +- (BOOL) isSieveServerAvailable +{ + return (([[self sieveClient] isConnected]) + ? true + : false); +} + - (id ) defaultAction { id results; - WORequest *request; SOGoDomainDefaults *dd; - NSString *method; - + SOGoMailAccount *account; + SOGoMailAccounts *folder; + WORequest *request; + request = [context request]; if ([[request method] isEqualToString: @"POST"]) + { + dd = [[context activeUser] domainDefaults]; + if ([dd sieveScriptsEnabled]) + [userDefaults setSieveFilters: sieveFilters]; + if ([dd vacationEnabled]) + [userDefaults setVacationOptions: vacationOptions]; + if ([dd forwardEnabled]) + [userDefaults setForwardOptions: forwardOptions]; + + if([self isSieveServerAvailable]) { - SOGoMailAccount *account; - SOGoMailAccounts *folder; - - dd = [[context activeUser] domainDefaults]; - if ([dd sieveScriptsEnabled]) - [userDefaults setSieveFilters: sieveFilters]; - if ([dd vacationEnabled]) - [userDefaults setVacationOptions: vacationOptions]; - if ([dd forwardEnabled]) - [userDefaults setForwardOptions: forwardOptions]; - [userDefaults synchronize]; - folder = [[self clientObject] mailAccountsFolder: @"Mail" inContext: context]; account = [folder lookupName: @"0" inContext: context acquire: NO]; - [account updateFilters]; - - if (hasChanged) - method = @"window.location.reload()"; + + if([account updateFilters]) + results = [self responseWithStatus: 200 andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:hasChanged], @"hasChanged", nil]]; + else - method = nil; - - results = [self jsCloseWithRefreshMethod: method]; + 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 results = self; - + return results; } diff --git a/UI/WebServerResources/UIxPreferences.js b/UI/WebServerResources/UIxPreferences.js index c342ffa1f..396fd2206 100644 --- a/UI/WebServerResources/UIxPreferences.js +++ b/UI/WebServerResources/UIxPreferences.js @@ -3,88 +3,111 @@ 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 ($("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 (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); + if (http.status == 503) { + showAlertDialog(_(response.textStatus)); } - } - - 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(); - $("mainForm").submit(); - } - - return false; + else if (http.status == 200) { + if (response.hasChanged == 1) { + window.opener.location.reload(); + window.close(); + } + else { + window.close(); + } + } + else { + showAlertDialog(_(response.textStatus)); + } + } + }, + null, + Form.serialize($("mainForm")), // excludes the file input + { "Content-type": "application/x-www-form-urlencoded"} + ); + } + return false; } function prototypeIfyFilters() { @@ -860,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");