Skip to content

Commit

Permalink
Merge branch 'MDL-43669-m' of git://github.com/micaherne/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed May 20, 2014
2 parents 4d46c88 + 8561492 commit 4cc89d5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5796,6 +5796,14 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '',
$mail->Sender = $supportuser->email;
}

if (!empty($CFG->emailonlyfromnoreplyaddress)) {
$usetrueaddress = false;
if (empty($replyto) && $from->maildisplay) {
$replyto = $from->email;
$replytoname = fullname($from);
}
}

if (is_string($from)) { // So we can pass whatever we want if there is need.
$mail->From = $CFG->noreplyaddress;
$mail->FromName = $from;
Expand Down
12 changes: 12 additions & 0 deletions lib/tests/moodlelib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,18 @@ public function test_email_to_user() {

email_to_user($user1, $user2, $subject, $messagetext);
$this->assertDebuggingCalled('Unit tests must not send real emails! Use $this->redirectEmails()');

// Test $CFG->emailonlyfromnoreplyaddress.
set_config('emailonlyfromnoreplyaddress', 1);
$this->assertNotEmpty($CFG->emailonlyfromnoreplyaddress);
$sink = $this->redirectEmails();
email_to_user($user1, $user2, $subject, $messagetext);
unset_config('emailonlyfromnoreplyaddress');
email_to_user($user1, $user2, $subject, $messagetext);
$result = $sink->get_messages();
$this->assertEquals($CFG->noreplyaddress, $result[0]->from);
$this->assertNotEquals($CFG->noreplyaddress, $result[1]->from);
$sink->close();
}

/**
Expand Down
2 changes: 2 additions & 0 deletions message/output/email/lang/en/message_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
$string['configallowusermailcharset'] = 'If enabled, users can choose an email charset in their profile settings.';
$string['configmailnewline'] = 'Newline characters used in mail messages. CRLF is required according to RFC 822bis, some mail servers do automatic conversion from LF to CRLF, other mail servers do incorrect conversion from CRLF to CRCRLF, yet others reject mails with bare LF (qmail for example). Try changing this setting if you are having problems with undelivered emails or double newlines.';
$string['confignoreplyaddress'] = 'Emails are sometimes sent out on behalf of a user (eg forum posts). The email address you specify here will be used as the "From" address in those cases when the recipients should not be able to reply directly to the user (eg when a user chooses to keep their address private).';
$string['configemailonlyfromnoreplyaddress'] = 'If enabled, all email will be sent using the no-reply address as the "from" address. This can be used to stop anti-spoofing controls in external mail systems blocking emails.';
$string['configsitemailcharset'] = 'This setting specifies the default charset for all emails sent from the site.';
$string['configsmtphosts'] = 'Give the full name of one or more local SMTP servers that Moodle should use to send mail (eg \'mail.a.com\' or \'mail.a.com;mail.b.com\'). To specify a non-default port (i.e other than port 25), you can use the [server]:[port] syntax (eg \'mail.a.com:587\'). For secure connections, port 465 is usually used with SSL, port 587 is usually used with TLS, specify security protocol below if required. If you leave this field blank, Moodle will use the PHP default method of sending mail.';
$string['configsmtpmaxbulk'] = 'Maximum number of messages sent per SMTP session. Grouping messages may speed up the sending of emails. Values lower than 2 force creation of new SMTP session for each email.';
$string['configsmtpsecure'] = 'If SMTP server requires secure connection, specify the correct protocol type.';
$string['configsmtpuser'] = 'If you have specified an SMTP server above, and the server requires authentication, then enter the username and password here.';
$string['email'] = 'Send email notifications to';
$string['emailonlyfromnoreplyaddress'] = 'Always send email from the no-reply address?';
$string['ifemailleftempty'] = 'Leave empty to send notifications to {$a}';
$string['mailnewline'] = 'Newline characters in mail';
$string['none'] = 'None';
Expand Down
3 changes: 3 additions & 0 deletions message/output/email/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
$settings->add(new admin_setting_configpasswordunmask('smtppass', get_string('smtppass', 'message_email'), get_string('configsmtpuser', 'message_email'), ''));
$settings->add(new admin_setting_configtext('smtpmaxbulk', get_string('smtpmaxbulk', 'message_email'), get_string('configsmtpmaxbulk', 'message_email'), 1, PARAM_INT));
$settings->add(new admin_setting_configtext('noreplyaddress', get_string('noreplyaddress', 'message_email'), get_string('confignoreplyaddress', 'message_email'), 'noreply@' . get_host_from_url($CFG->wwwroot), PARAM_NOTAGS));
$settings->add(new admin_setting_configcheckbox('emailonlyfromnoreplyaddress',
get_string('emailonlyfromnoreplyaddress', 'message_email'),
get_string('configemailonlyfromnoreplyaddress', 'message_email'), 0));

$charsets = get_list_of_charsets();
unset($charsets['UTF-8']); // not needed here
Expand Down

0 comments on commit 4cc89d5

Please sign in to comment.