if (!empty($user->mailformat) && $user->mailformat == 1) {
// Only process html templates if the user preferences allow html email.
- if ($messagehtml) {
- // If html has been given then pass it through the template.
- $context['body'] = $messagehtml;
- $messagehtml = $renderer->render_from_template('core/email_html', $context);
-
- } else {
+ if (!$messagehtml) {
// If no html has been given, BUT there is an html wrapping template then
// auto convert the text to html and then wrap it.
- $autohtml = trim(text_to_html($messagetext));
- $context['body'] = $autohtml;
- $temphtml = $renderer->render_from_template('core/email_html', $context);
- if ($autohtml != $temphtml) {
- $messagehtml = $temphtml;
- }
+ $messagehtml = trim(text_to_html($messagetext));
}
+ $context['body'] = $messagehtml;
+ $messagehtml = $renderer->render_from_template('core/email_html', $context);
}
- $context['body'] = $messagetext;
+ $context['body'] = html_to_text(nl2br($messagetext));
$mail->Subject = $renderer->render_from_template('core/email_subject', $context);
$mail->FromName = $renderer->render_from_template('core/email_fromname', $context);
$messagetext = $renderer->render_from_template('core/email_text', $context);
$message = get_string('emailconfirmation', '', $data);
$messagehtml = text_to_html(get_string('emailconfirmation', '', $data), false, false, true);
- $user->mailformat = 1; // Always send HTML version as well.
-
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
return email_to_user($user, $supportuser, $subject, $message, $messagehtml);
}
$this->resetAfterTest();
- $user1 = $this->getDataGenerator()->create_user(array('maildisplay' => 1));
- $user2 = $this->getDataGenerator()->create_user(array('maildisplay' => 1));
+ $user1 = $this->getDataGenerator()->create_user(array('maildisplay' => 1, 'mailformat' => 0));
+ $user2 = $this->getDataGenerator()->create_user(array('maildisplay' => 1, 'mailformat' => 1));
$user3 = $this->getDataGenerator()->create_user(array('maildisplay' => 0));
set_config('allowedemaildomains', "example.com\r\nmoodle.org");
$subject = 'subject';
$messagetext = 'message text';
$subject2 = 'subject 2';
- $messagetext2 = 'message text 2';
+ $messagetext2 = '<b>message text 2</b>';
// Close the default email sink.
$sink = $this->redirectEmails();
$this->assertSame($messagetext, trim($result[0]->body));
$this->assertSame($user1->email, $result[0]->to);
$this->assertSame($user2->email, $result[0]->from);
+ $this->assertContains('Content-Type: text/plain', $result[0]->header);
$this->assertSame($subject2, $result[1]->subject);
- $this->assertSame($messagetext2, trim($result[1]->body));
+ $this->assertContains($messagetext2, quoted_printable_decode($result[1]->body));
$this->assertSame($user2->email, $result[1]->to);
$this->assertSame($user1->email, $result[1]->from);
+ $this->assertNotContains('Content-Type: text/plain', $result[1]->header);
email_to_user($user1, $user2, $subject, $messagetext);
$this->assertDebuggingCalled('Unit tests must not send real emails! Use $this->redirectEmails()');
$result = $sink->get_messages();
$sink->close();
- $this->assertContains('passwords cannot be reset on this site', $result[0]->body);
+ $this->assertContains('passwords cannot be reset on this site', quoted_printable_decode($result[0]->body));
}
}
$this->assertSame($user->email, $email->to);
$this->assertNotEmpty($email->header);
$this->assertNotEmpty($email->body);
- $this->assertRegExp('/A password reset was requested for your account/', $email->body);
+ $this->assertRegExp('/A password reset was requested for your account/', quoted_printable_decode($email->body));
$sink->clear();
}
$this->assertSame($user->email, $email->to);
$this->assertNotEmpty($email->header);
$this->assertNotEmpty($email->body);
- $this->assertRegExp('/A password reset was requested for your account/', $email->body);
+ $this->assertRegExp('/A password reset was requested for your account/', quoted_printable_decode($email->body));
$sink->clear();
}
$this->assertSame($user->email, $email->to);
$this->assertNotEmpty($email->header);
$this->assertNotEmpty($email->body);
- $this->assertRegExp('/A password reset was requested for your account/', $email->body);
+ $this->assertRegExp('/A password reset was requested for your account/', quoted_printable_decode($email->body));
$sink->clear();
}
$this->assertSame($user->email, $email->to);
$this->assertNotEmpty($email->header);
$this->assertNotEmpty($email->body);
- $this->assertRegExp('/A password reset was requested for your account/', $email->body);
+ $this->assertRegExp('/A password reset was requested for your account/', quoted_printable_decode($email->body));
$sink->clear();
}
$this->assertSame($user->email, $email->to);
$this->assertNotEmpty($email->header);
$this->assertNotEmpty($email->body);
- $this->assertRegExp('/Unfortunately your account on this site is disabled/', $email->body);
+ $this->assertRegExp('/Unfortunately your account on this site is disabled/', quoted_printable_decode($email->body));
$sink->clear();
}
$this->assertSame($user->email, $email->to);
$this->assertNotEmpty($email->header);
$this->assertNotEmpty($email->body);
- $this->assertRegExp('/Unfortunately passwords cannot be reset on this site/', $email->body);
+ $this->assertRegExp('/Unfortunately passwords cannot be reset on this site/', quoted_printable_decode($email->body));
$sink->clear();
}