mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 01:46:45 +02:00
Merge branch 'MDL-69265-email-headers' of https://github.com/brendanheywood/moodle
This commit is contained in:
commit
78193d34b4
4 changed files with 41 additions and 1 deletions
|
@ -6221,6 +6221,15 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml = '',
|
|||
$mail->addCustomHeader('X-Moodle-Originating-Script: ' . $originheader);
|
||||
}
|
||||
|
||||
if (!empty($CFG->emailheaders)) {
|
||||
$headers = array_map('trim', explode("\n", $CFG->emailheaders));
|
||||
foreach ($headers as $header) {
|
||||
if (!empty($header)) {
|
||||
$mail->addCustomHeader($header);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($from->priority)) {
|
||||
$mail->Priority = $from->priority;
|
||||
}
|
||||
|
|
|
@ -3220,6 +3220,32 @@ class core_moodlelib_testcase extends advanced_testcase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test email with custom headers
|
||||
*/
|
||||
public function test_send_email_with_custom_header() {
|
||||
global $DB, $CFG;
|
||||
$this->preventResetByRollback();
|
||||
$this->resetAfterTest();
|
||||
|
||||
$touser = $this->getDataGenerator()->create_user();
|
||||
$fromuser = $this->getDataGenerator()->create_user();
|
||||
$fromuser->customheaders = 'X-Custom-Header: foo';
|
||||
|
||||
set_config('allowedemaildomains', 'example.com');
|
||||
set_config('emailheaders', 'X-Fixed-Header: bar');
|
||||
|
||||
$sink = $this->redirectEmails();
|
||||
email_to_user($touser, $fromuser, 'subject', 'message');
|
||||
|
||||
$emails = $sink->get_messages();
|
||||
$this->assertCount(1, $emails);
|
||||
$email = reset($emails);
|
||||
$this->assertContains('X-Custom-Header: foo', $email->header);
|
||||
$this->assertContains("X-Fixed-Header: bar", $email->header);
|
||||
$sink->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* A data provider for testing email diversion
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue