Skip to content

Commit

Permalink
Merge branch 'MDL-69600-divertemails' of https://github.com/brendanhe…
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Sep 29, 2020
2 parents 76b5863 + 0983a1c commit 83cf43b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
11 changes: 11 additions & 0 deletions admin/settings/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,17 @@
new lang_string('configallowedemaildomains', 'admin'),
''));

$temp->add(new admin_setting_heading('divertallemailsheading', new lang_string('divertallemails', 'admin'),
new lang_string('divertallemailsdetail', 'admin')));
$temp->add(new admin_setting_configtext('divertallemailsto',
new lang_string('divertallemailsto', 'admin'),
new lang_string('divertallemailsto_desc', 'admin'),
''));
$temp->add(new admin_setting_configtextarea('divertallemailsexcept',
new lang_string('divertallemailsexcept', 'admin'),
new lang_string('divertallemailsexcept_desc', 'admin'),
'', PARAM_RAW, '50', '4'));

$url = new moodle_url('/admin/testoutgoingmailconf.php');
$link = html_writer::link($url, get_string('testoutgoingmailconf', 'admin'));
$temp->add(new admin_setting_heading('testoutgoinmailc', new lang_string('testoutgoingmailconf', 'admin'),
Expand Down
9 changes: 9 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,15 @@
$string['disableuserimages'] = 'Disable user profile images';
$string['displayerrorswarning'] = 'Enabling the PHP setting <em>display_errors</em> is not recommended on production sites because some error messages may reveal sensitive information about your server.';
$string['displayloginfailures'] = 'Display login failures';
$string['divertallemails'] = 'Email diverting';
$string['divertallemailsdetail'] = 'Used as a safeguard in development environments when testing emails and should not be used in production.';
$string['divertallemailsexcept'] = 'Email diversion exceptions';
$string['divertallemailsexcept_desc'] = 'A list of email exception rules separated by either commas or new lines. Each rule is interpreted as a regular expression, eg<pre>[email protected]
.*@acme.com
fred(\\+.*)[email protected]
</pre>';
$string['divertallemailsto'] = 'Divert all emails';
$string['divertallemailsto_desc'] = 'If set then all emails will be diverted to this single email address instead.';
$string['dndallowtextandlinks'] = 'Drag and drop upload of text/links';
$string['doclang'] = 'Language for docs';
$string['docroot'] = 'Moodle Docs document root';
Expand Down
2 changes: 1 addition & 1 deletion lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5984,7 +5984,7 @@ function email_should_be_diverted($email) {
return true;
}

$patterns = array_map('trim', explode(',', $CFG->divertallemailsexcept));
$patterns = array_map('trim', preg_split("/[\s,]+/", $CFG->divertallemailsexcept));
foreach ($patterns as $pattern) {
if (preg_match("/$pattern/", $email)) {
return false;
Expand Down
20 changes: 20 additions & 0 deletions lib/tests/moodlelib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3297,6 +3297,26 @@ public function diverted_emails_provider() {
),
false,
),
'divertsexceptionsnewline' => array(
'divertallemailsto' => '[email protected]',
'divertallemailsexcept' => "@dev.com\nfred(\+.*)[email protected]",
array(
'[email protected]',
'[email protected]',
'[email protected]',
),
false,
),
'alsodivertsnewline' => array(
'divertallemailsto' => '[email protected]',
'divertallemailsexcept' => "@dev.com\nfred(\+.*)[email protected]",
array(
'[email protected]',
'[email protected]',
'[email protected]',
),
true,
),
);
}

Expand Down

0 comments on commit 83cf43b

Please sign in to comment.