From 506393090bf33ea1aa3a18983748e6a5b4078d4d Mon Sep 17 00:00:00 2001 From: Jens-Christian Fischer Date: Fri, 24 Jan 2014 14:04:37 +0100 Subject: [PATCH 1/3] Add 'mail_from_address' configuration In environments where there are rules for the email addresses, the "from address" that owncloud uses has to be configurable. This patch adds a new configuration variable 'mail_from_address'. If it is configured, owncloud will use this as the sender of *all* emails. (OwnCloud uses 'sharing-noreply' and 'password-noreply' by default). By using the 'mail_from_address' configuration, only this email address will be used. --- lib/public/util.php | 1 + tests/lib/util.php | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/public/util.php b/lib/public/util.php index 8e85f9afc3..8514a168b4 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -256,6 +256,7 @@ class Util { * it would return 'lostpassword-noreply@example.com' */ public static function getDefaultEmailAddress($user_part) { + $user_part = \OC_Config::getValue('mail_from_address', $user_part); $host_name = self::getServerHostName(); $host_name = \OC_Config::getValue('mail_domain', $host_name); $defaultEmailAddress = $user_part.'@'.$host_name; diff --git a/tests/lib/util.php b/tests/lib/util.php index 852caaeccc..bfe68f5f68 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -88,6 +88,15 @@ class Test_Util extends PHPUnit_Framework_TestCase { OC_Config::deleteKey('mail_domain'); } + function testGetConfiguredEmailAddressFromConfig() { + OC_Config::setValue('mail_domain', 'example.com'); + OC_Config::setValue('mail_from_address', 'owncloud'); + $email = \OCP\Util::getDefaultEmailAddress("no-reply"); + $this->assertEquals('owncloud@example.com', $email); + OC_Config::deleteKey('mail_domain'); + OC_Config::deleteKey('mail_from_address'); + } + function testGetInstanceIdGeneratesValidId() { OC_Config::deleteKey('instanceid'); $this->assertStringStartsWith('oc', OC_Util::getInstanceId()); From 0f6c60717140c885ebb33dfc38d94081a894dd6d Mon Sep 17 00:00:00 2001 From: Jens-Christian Fischer Date: Fri, 24 Jan 2014 14:22:42 +0100 Subject: [PATCH 2/3] added function documentation --- lib/public/util.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/public/util.php b/lib/public/util.php index 8514a168b4..6317f10a66 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -254,6 +254,10 @@ class Util { * Example: when given lostpassword-noreply as $user_part param, * and is currently accessed via http(s)://example.com/, * it would return 'lostpassword-noreply@example.com' + * + * If the configuration value 'mail_from_address' is set in + * config.php, this value will override the $user_part that + * is passed to this function */ public static function getDefaultEmailAddress($user_part) { $user_part = \OC_Config::getValue('mail_from_address', $user_part); From 3ca85cd841bae985082318cba1d88bae9fdac65a Mon Sep 17 00:00:00 2001 From: Jens-Christian Fischer Date: Fri, 24 Jan 2014 16:24:52 +0100 Subject: [PATCH 3/3] updated config.sample.php with mail_from_address parameter --- config/config.sample.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/config.sample.php b/config/config.sample.php index 1070ef72ed..01abc58368 100755 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -80,6 +80,12 @@ $CONFIG = array( /* Domain name used by ownCloud for the sender mail address, e.g. no-reply@example.com */ "mail_domain" => "example.com", +/* FROM address used by ownCloud for the sender mail address, e.g. owncloud@example.com + This setting overwrites the built in 'sharing-noreply' and 'lostpassword-noreply' + FROM addresses, that ownCloud uses +*/ +"mail_from_address" => "owncloud", + /* Enable SMTP class debugging */ "mail_smtpdebug" => false,