From 322f72626a3253f9d290cfb6d83ff8f5fac2a4e4 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Wed, 11 Feb 2015 14:30:40 -0500 Subject: [PATCH] now possible to limit automatic forwards to internal/external domains --- Documentation/SOGoInstallationGuide.asciidoc | 6 ++++ NEWS | 1 + SoObjects/SOGo/SOGoDomainDefaults.h | 3 +- SoObjects/SOGo/SOGoDomainDefaults.m | 11 ++++++- UI/PreferencesUI/UIxPreferences.m | 11 ++++++- UI/Templates/PreferencesUI/UIxPreferences.wox | 4 +++ UI/WebServerResources/UIxPreferences.js | 31 +++++++++++++++++++ 7 files changed, 64 insertions(+), 3 deletions(-) diff --git a/Documentation/SOGoInstallationGuide.asciidoc b/Documentation/SOGoInstallationGuide.asciidoc index 70c39876c..7fa4dff3d 100644 --- a/Documentation/SOGoInstallationGuide.asciidoc +++ b/Documentation/SOGoInstallationGuide.asciidoc @@ -1792,6 +1792,12 @@ host. Defaults to `NO` when unset. +|D |SOGoForwardConstraints +|Parameter used to set constraints on possible addresses used when +automatically forwarding mails. When set to `0` (default), no constraint +is enforced. When set to `1`, only internal domains can be used. When +set to `2`, only external domains can be used. + |D |SOGoSieveScriptsEnabled |Parameter used to activate the edition from the preferences windows of server-side mail filters. Requires Sieve script support on the IMAP diff --git a/NEWS b/NEWS index 157b65a22..083535106 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ New features - now possible for SOGo to change the sambaNTPassword/sambaLMPassword + - now possible to limit automatic forwards to internal/external domains Enhancements - added support for email categories using EAS (#2995) diff --git a/SoObjects/SOGo/SOGoDomainDefaults.h b/SoObjects/SOGo/SOGoDomainDefaults.h index 4743917af..fbc665852 100644 --- a/SoObjects/SOGo/SOGoDomainDefaults.h +++ b/SoObjects/SOGo/SOGoDomainDefaults.h @@ -1,6 +1,6 @@ /* SOGoDomainDefaults.h - this file is part of SOGo * - * Copyright (C) 2009-2014 Inverse inc. + * Copyright (C) 2009-2015 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,6 +49,7 @@ - (BOOL) forceExternalLoginWithEmail; - (BOOL) sieveScriptsEnabled; - (BOOL) forwardEnabled; +- (int) forwardConstraints; - (BOOL) vacationEnabled; - (NSString *) mailingMechanism; - (NSString *) smtpServer; diff --git a/SoObjects/SOGo/SOGoDomainDefaults.m b/SoObjects/SOGo/SOGoDomainDefaults.m index 35a078b3f..ff02b6a96 100644 --- a/SoObjects/SOGo/SOGoDomainDefaults.m +++ b/SoObjects/SOGo/SOGoDomainDefaults.m @@ -1,6 +1,6 @@ /* SOGoDomainDefaults.m - this file is part of SOGo * - * Copyright (C) 2009-2014 Inverse inc. + * Copyright (C) 2009-2015 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -201,6 +201,15 @@ return [self boolForKey: @"SOGoForwardEnabled"]; } +- (int) forwardConstraints +{ + unsigned int v; + + v = [self integerForKey: @"SOGoForwardConstraints"]; + + return (v > 2 ? 0 : v); +} + - (BOOL) vacationEnabled { return [self boolForKey: @"SOGoVacationEnabled"]; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 49d5ab350..6e54bc043 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -1,6 +1,6 @@ /* UIxPreferences.m - this file is part of SOGo * - * Copyright (C) 2007-2014 Inverse inc. + * Copyright (C) 2007-2015 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1238,6 +1238,15 @@ static NSArray *reminderValues = nil; return [[forwardOptions objectForKey: @"keepCopy"] boolValue]; } +- (NSString *) forwardConstraints +{ + SOGoDomainDefaults *dd; + + dd = [[context activeUser] domainDefaults]; + + return [NSString stringWithFormat: @"%d", [dd forwardConstraints]]; +} + /* main */ - (NSArray *) availableModules diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index efafdabef..4d08baaa8 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -654,6 +654,10 @@ const:id="forwardKeepCopy" var:checked="forwardKeepCopy" />
+ + diff --git a/UI/WebServerResources/UIxPreferences.js b/UI/WebServerResources/UIxPreferences.js index 7c2d12652..071ba6da8 100644 --- a/UI/WebServerResources/UIxPreferences.js +++ b/UI/WebServerResources/UIxPreferences.js @@ -70,11 +70,42 @@ function savePreferences(sender) { if ($("enableForward") && $("enableForward").checked) { var addresses = $("forwardAddress").value.split(","); + + // We check if all addresses are valid 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; } + + // We check if we can only to internal/external addresses. + var constraints = parseInt($("forwardConstraints").value); + + if (constraints > 0) { + // We first extract the list of 'known domains' to SOGo + var defaultAddresses = $("defaultEmailAddresses").value.split(/, */); + var domains = new Array(); + + defaultAddresses.each(function(adr) { + var domain = adr.split("@")[1]; + if (domain) { + domains.push(domain.toLowerCase()); + } + }); + + // We check if we're allowed or not to forward based on the domain defaults + for (var i = 0; i < addresses.length && sendForm; i++) { + var domain = addresses[i].split("@")[1].toLowerCase(); + if (domains.indexOf(domain) < 0 && constraints == 1) { + showAlertDialog(_("You are not allowed to forward your messages to an external email address.")); + sendForm = false; + } + else if (domains.indexOf(domain) >= 0 && constraints == 2) { + showAlertDialog(_("You are not allowed to forward your messages to an internal email address.")); + sendForm = false; + } + } + } } if (typeof sieveCapabilities != "undefined") {