Commit 7ae2e547 authored by catch's avatar catch

Issue #310315 by Waltemath, justafish, naxoc: Fixed drupal_wrap_mail() strips...

Issue #310315 by Waltemath, justafish, naxoc: Fixed drupal_wrap_mail() strips trailing blanks from standard hyphen-hyphen-space-newline e-mail signature separator.
parent e482865e
...@@ -313,8 +313,9 @@ function drupal_wrap_mail($text, $indent = '') { ...@@ -313,8 +313,9 @@ function drupal_wrap_mail($text, $indent = '') {
$soft = strpos($clean_indent, ' ') === FALSE; $soft = strpos($clean_indent, ' ') === FALSE;
// Check if the string has line breaks. // Check if the string has line breaks.
if (strpos($text, "\n") !== FALSE) { if (strpos($text, "\n") !== FALSE) {
// Remove trailing spaces to make existing breaks hard. // Remove trailing spaces to make existing breaks hard, but leave signature
$text = preg_replace('/ +\n/m', "\n", $text); // marker untouched (RFC 3676, Section 4.3).
$text = preg_replace('/(?(?<!^--) +\n| +\n)/m', "\n", $text);
// Wrap each line at the needed width. // Wrap each line at the needed width.
$lines = explode("\n", $text); $lines = explode("\n", $text);
array_walk($lines, '_drupal_wrap_mail_line', array('soft' => $soft, 'length' => strlen($indent))); array_walk($lines, '_drupal_wrap_mail_line', array('soft' => $soft, 'length' => strlen($indent)));
......
...@@ -97,4 +97,31 @@ public function format(array $message) { ...@@ -97,4 +97,31 @@ public function format(array $message) {
public function mail(array $message) { public function mail(array $message) {
self::$sent_message = $message; self::$sent_message = $message;
} }
/**
* Tests that drupal_wrap_mail() removes trailing whitespace before newlines.
*/
public function testRemoveTrailingWhitespace() {
$text = "Hi there! \nHerp Derp";
$mail_lines = explode("\n", drupal_wrap_mail($text));
$this->assertNotEqual(" ", substr($mail_lines[0], -1), 'Trailing whitespace removed.');
}
/**
* Tests that drupal_wrap_mail() does not remove the trailing whitespace from
* Usenet style signatures.
*
* RFC 3676 says, "This is a special case; an (optionally quoted or quoted and
* stuffed) line consisting of DASH DASH SP is neither fixed nor flowed."
*/
public function testUsenetSignature() {
$text = "Hi there!\n-- \nHerp Derp";
$mail_lines = explode("\n", drupal_wrap_mail($text));
$this->assertEqual("-- ", $mail_lines[1], 'Trailing whitespace not removed for dash-dash-space signatures.');
$text = "Hi there!\n-- \nHerp Derp";
$mail_lines = explode("\n", drupal_wrap_mail($text));
$this->assertEqual("--", $mail_lines[1], 'Trailing whitespace removed for incorrect dash-dash-space signatures.');
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment