diff options
author | David Rothstein <drothstein@gmail.com> | 2013-12-25 16:49:17 -0500 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2013-12-25 16:49:17 -0500 |
commit | 58081593e9d37eb17c687e6ab8a0eb3ec3d36d8a (patch) | |
tree | 4d644c5b53913621be96d86f445f062d9380d568 | |
parent | 59b82ed9fae50d516c023369a9ffca94bccc9b6a (diff) | |
download | brdo-58081593e9d37eb17c687e6ab8a0eb3ec3d36d8a.tar.gz brdo-58081593e9d37eb17c687e6ab8a0eb3ec3d36d8a.tar.bz2 |
Issue #310315 by superspring, justafish, naxoc, Waltemath | fonant: drupal_wrap_mail() strips trailing blanks from standard hyphen-hyphen-space-newline e-mail signature separator.
-rw-r--r-- | includes/mail.inc | 11 | ||||
-rw-r--r-- | modules/simpletest/tests/mail.test | 25 |
2 files changed, 31 insertions, 5 deletions
diff --git a/includes/mail.inc b/includes/mail.inc index bbb55357d..34a4d10fa 100644 --- a/includes/mail.inc +++ b/includes/mail.inc @@ -339,13 +339,13 @@ interface MailSystemInterface { * * We deliberately use LF rather than CRLF, see drupal_mail(). * - * @param $text + * @param string $text * The plain text to process. - * @param $indent (optional) + * @param string $indent (optional) * A string to indent the text with. Only '>' characters are repeated on * subsequent wrapped lines. Others are replaced by spaces. * - * @return + * @return string * The content of the email as a string with formatting applied. */ function drupal_wrap_mail($text, $indent = '') { @@ -356,8 +356,9 @@ function drupal_wrap_mail($text, $indent = '') { $soft = strpos($clean_indent, ' ') === FALSE; // Check if the string has line breaks. if (strpos($text, "\n") !== FALSE) { - // Remove trailing spaces to make existing breaks hard. - $text = preg_replace('/ +\n/m', "\n", $text); + // Remove trailing spaces to make existing breaks hard, but leave signature + // marker untouched (RFC 3676, Section 4.3). + $text = preg_replace('/(?(?<!^--) +\n| +\n)/m', "\n", $text); // Wrap each line at the needed width. $lines = explode("\n", $text); array_walk($lines, '_drupal_wrap_mail_line', array('soft' => $soft, 'length' => strlen($indent))); diff --git a/modules/simpletest/tests/mail.test b/modules/simpletest/tests/mail.test index 8024010ab..70a43cb45 100644 --- a/modules/simpletest/tests/mail.test +++ b/modules/simpletest/tests/mail.test @@ -268,6 +268,31 @@ class DrupalHtmlToTextTestCase extends DrupalWebTestCase { } /** + * Tests that drupal_wrap_mail() removes trailing whitespace before newlines. + */ + function testDrupalHtmltoTextRemoveTrailingWhitespace() { + $text = "Hi there! \nHerp Derp"; + $mail_lines = explode("\n", drupal_wrap_mail($text)); + $this->assertNotEqual(" ", substr($mail_lines[0], -1), 'Trailing whitespace removed.'); + } + + /** + * Tests drupal_wrap_mail() retains 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." + */ + function testDrupalHtmltoTextUsenetSignature() { + $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.'); + } + + /** * Test that whitespace is collapsed. */ function testDrupalHtmltoTextCollapsesWhitespace() { |