From 1b9ac03e947e5c85cbcfdb1d252dffd43545f536 Mon Sep 17 00:00:00 2001 From: Alexandre Cloutier Date: Fri, 28 Feb 2014 16:39:27 -0500 Subject: [PATCH 1/5] BugFix #1046; Whenever the sieve server is unavailable an error message will appear. --- .../English.lproj/Localizable.strings | 5 +++ UI/PreferencesUI/UIxPreferences.m | 36 +++++++++++++++++++ UI/WebServerResources/UIxPreferences.js | 28 +++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/UI/PreferencesUI/English.lproj/Localizable.strings b/UI/PreferencesUI/English.lproj/Localizable.strings index afa832c3e..2698aa941 100644 --- a/UI/PreferencesUI/English.lproj/Localizable.strings +++ b/UI/PreferencesUI/English.lproj/Localizable.strings @@ -248,6 +248,11 @@ "Active" = "Active"; "Move Up" = "Move Up"; "Move Down" = "Move Down"; +<<<<<<< HEAD +======= +"ConnectionError" = "Connection error"; +"ServiceTemporarilyUnavailable" = "Service temporarily unavailable"; +>>>>>>> a005b93... bug 1046 finished, if sieve server is not responding an error message will appear /* Filters - UIxFilterEditor */ "Filter name:" = "Filter name:"; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 7ba612cac..6b1d96f84 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -1142,6 +1142,7 @@ static NSArray *reminderValues = nil; id results; WORequest *request; SOGoDomainDefaults *dd; +<<<<<<< HEAD NSString *method; request = [context request]; @@ -1158,6 +1159,23 @@ static NSArray *reminderValues = nil; if ([dd forwardEnabled]) [userDefaults setForwardOptions: forwardOptions]; +======= + 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]){ +>>>>>>> a005b93... bug 1046 finished, if sieve server is not responding an error message will appear [userDefaults synchronize]; folder = [[self clientObject] mailAccountsFolder: @"Mail" @@ -1165,6 +1183,7 @@ static NSArray *reminderValues = nil; account = [folder lookupName: @"0" inContext: context acquire: NO]; [account updateFilters]; +<<<<<<< HEAD if (hasChanged) method = @"window.location.reload()"; else @@ -1175,6 +1194,23 @@ static NSArray *reminderValues = nil; else results = self; +======= + 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; + } + +>>>>>>> a005b93... bug 1046 finished, if sieve server is not responding an error message will appear return results; } diff --git a/UI/WebServerResources/UIxPreferences.js b/UI/WebServerResources/UIxPreferences.js index e1a8880ce..2e6a9f282 100644 --- a/UI/WebServerResources/UIxPreferences.js +++ b/UI/WebServerResources/UIxPreferences.js @@ -80,11 +80,39 @@ function savePreferences(sender) { } if (sendForm) { +<<<<<<< HEAD saveMailAccounts(); $("mainForm").submit(); } return false; +======= + saveMailAccounts(); + + triggerAjaxRequest($("mainForm").readAttribute("action"), function (http) { + if (http.readyState == 4) { + var response = http.responseText.evalJSON(true); + if (http.status == 503) { + showAlertDialog(_(response.textStatus)); + } + 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; + +>>>>>>> a005b93... bug 1046 finished, if sieve server is not responding an error message will appear } function prototypeIfyFilters() { From f4d189ffc893de10d397249dd15427a1de961852 Mon Sep 17 00:00:00 2001 From: Alexandre Cloutier Date: Thu, 6 Mar 2014 15:20:41 -0500 Subject: [PATCH 2/5] Erase the merging conflicts writings --- .../English.lproj/Localizable.strings | 3 -- UI/PreferencesUI/UIxPreferences.m | 47 +++---------------- UI/WebServerResources/UIxPreferences.js | 9 ---- 3 files changed, 6 insertions(+), 53 deletions(-) diff --git a/UI/PreferencesUI/English.lproj/Localizable.strings b/UI/PreferencesUI/English.lproj/Localizable.strings index 2698aa941..10fbf68a3 100644 --- a/UI/PreferencesUI/English.lproj/Localizable.strings +++ b/UI/PreferencesUI/English.lproj/Localizable.strings @@ -248,11 +248,8 @@ "Active" = "Active"; "Move Up" = "Move Up"; "Move Down" = "Move Down"; -<<<<<<< HEAD -======= "ConnectionError" = "Connection error"; "ServiceTemporarilyUnavailable" = "Service temporarily unavailable"; ->>>>>>> a005b93... bug 1046 finished, if sieve server is not responding an error message will appear /* Filters - UIxFilterEditor */ "Filter name:" = "Filter name:"; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 6b1d96f84..09afe22a3 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -1140,61 +1140,27 @@ static NSArray *reminderValues = nil; - (id ) defaultAction { id results; - WORequest *request; SOGoDomainDefaults *dd; -<<<<<<< HEAD - NSString *method; - - request = [context request]; - if ([[request method] isEqualToString: @"POST"]) - { - 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]; - -======= SOGoMailAccount *account; SOGoMailAccounts *folder; WORequest *request; - + request = [context request]; 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]){ ->>>>>>> a005b93... bug 1046 finished, if sieve server is not responding an error message will appear [userDefaults synchronize]; - folder = [[self clientObject] mailAccountsFolder: @"Mail" inContext: context]; account = [folder lookupName: @"0" inContext: context acquire: NO]; - [account updateFilters]; - -<<<<<<< HEAD - if (hasChanged) - method = @"window.location.reload()"; - else - method = nil; - - results = [self jsCloseWithRefreshMethod: method]; - } - else - results = self; - -======= + if([account updateFilters]){ results = [self responseWithStatus: 200 andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:hasChanged], @"hasChanged", nil]]; } @@ -1210,7 +1176,6 @@ static NSArray *reminderValues = nil; results = self; } ->>>>>>> a005b93... bug 1046 finished, if sieve server is not responding an error message will appear return results; } diff --git a/UI/WebServerResources/UIxPreferences.js b/UI/WebServerResources/UIxPreferences.js index 2e6a9f282..c8c6584c6 100644 --- a/UI/WebServerResources/UIxPreferences.js +++ b/UI/WebServerResources/UIxPreferences.js @@ -80,13 +80,6 @@ function savePreferences(sender) { } if (sendForm) { -<<<<<<< HEAD - saveMailAccounts(); - $("mainForm").submit(); - } - - return false; -======= saveMailAccounts(); triggerAjaxRequest($("mainForm").readAttribute("action"), function (http) { @@ -111,8 +104,6 @@ function savePreferences(sender) { { "Content-type": "application/x-www-form-urlencoded" }); } return false; - ->>>>>>> a005b93... bug 1046 finished, if sieve server is not responding an error message will appear } function prototypeIfyFilters() { From f5faa608145ccb70ed89b0d29e9b8adad17d2f0b Mon Sep 17 00:00:00 2001 From: Alexandre Cloutier Date: Mon, 10 Mar 2014 10:33:27 -0400 Subject: [PATCH 3/5] Added missing functions getClient and IsSieveServerConnected and the changes that comes with it --- UI/PreferencesUI/UIxPreferences.h | 4 ++++ UI/PreferencesUI/UIxPreferences.m | 37 +++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/UI/PreferencesUI/UIxPreferences.h b/UI/PreferencesUI/UIxPreferences.h index 3040e67ae..69dd4c075 100644 --- a/UI/PreferencesUI/UIxPreferences.h +++ b/UI/PreferencesUI/UIxPreferences.h @@ -22,6 +22,7 @@ #define UIXPREFERENCES_H #import +#import @class NSString; @@ -32,6 +33,7 @@ { id item; SOGoUser *user; + NGSieveClient *client; // Calendar categories NSString *category; @@ -58,6 +60,8 @@ } - (NSString *) userLongDateFormat; +- (BOOL) isSieveServerAvailable; +- (id) getClient; @end diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 09afe22a3..a383b9edc 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -114,6 +114,8 @@ static NSArray *reminderValues = nil; if ((self = [super init])) { item = nil; + client = [self getClient]; + #warning user should be the owner rather than the activeUser ASSIGN (user, [context activeUser]); ASSIGN (today, [NSCalendarDate date]); @@ -174,6 +176,7 @@ static NSArray *reminderValues = nil; [contactsCategories release]; [forwardOptions release]; [daysOfWeek release]; + [client release]; [super dealloc]; } @@ -840,26 +843,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]; else capabilities = [NSArray array]; - [capabilities retain]; + [capabilities retain]; } return [capabilities jsonRepresentation]; @@ -1137,6 +1129,27 @@ static NSArray *reminderValues = nil; } } +- (id) getClient{ + SOGoMailAccount *account; + SOGoMailAccounts *folder; + SOGoSieveManager *manager; + NGSieveClient *realClient; + + folder = [[self clientObject] mailAccountsFolder: @"Mail" inContext: context]; + account = [folder lookupName: @"0" inContext: context acquire: NO]; + manager = [SOGoSieveManager sieveManagerForUser: [context activeUser]]; + realClient = [manager clientForAccount: account]; + + return realClient; +} + +- (BOOL) isSieveServerAvailable { + return (([client isConnected]) + ? true + : false); +} + + - (id ) defaultAction { id results; From 3a681bd5a5a856a2230e730945c3ed2df076ff0a Mon Sep 17 00:00:00 2001 From: Alexandre Cloutier Date: Mon, 10 Mar 2014 10:53:44 -0400 Subject: [PATCH 4/5] Change the function name getClient to sieveClient --- UI/PreferencesUI/UIxPreferences.h | 2 +- UI/PreferencesUI/UIxPreferences.m | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/UI/PreferencesUI/UIxPreferences.h b/UI/PreferencesUI/UIxPreferences.h index 69dd4c075..4dcb1548b 100644 --- a/UI/PreferencesUI/UIxPreferences.h +++ b/UI/PreferencesUI/UIxPreferences.h @@ -61,7 +61,7 @@ - (NSString *) userLongDateFormat; - (BOOL) isSieveServerAvailable; -- (id) getClient; +- (id) sieveClient; @end diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index a383b9edc..b1a0e1a8c 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -1129,18 +1129,18 @@ static NSArray *reminderValues = nil; } } -- (id) getClient{ +- (id) sieveClient{ SOGoMailAccount *account; SOGoMailAccounts *folder; SOGoSieveManager *manager; - NGSieveClient *realClient; + NGSieveClient *sieveClient; folder = [[self clientObject] mailAccountsFolder: @"Mail" inContext: context]; account = [folder lookupName: @"0" inContext: context acquire: NO]; manager = [SOGoSieveManager sieveManagerForUser: [context activeUser]]; - realClient = [manager clientForAccount: account]; + sieveClient = [manager clientForAccount: account]; - return realClient; + return sieveClient; } - (BOOL) isSieveServerAvailable { From 349f4d824a297f41f2d04087bcff49b49f70cd60 Mon Sep 17 00:00:00 2001 From: Alexandre Cloutier Date: Fri, 4 Apr 2014 15:04:37 -0400 Subject: [PATCH 5/5] 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");