diff options
| author | thomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2010-05-20 21:28:30 +0000 |
|---|---|---|
| committer | thomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2010-05-20 21:28:30 +0000 |
| commit | 83b297e2b198bd9034fb82d942353be51d003dea (patch) | |
| tree | 0217411e199512df81188a1a75d64f7b0a8fc96c /roundcubemail/program/include/rcube_message.php | |
| parent | 36077f1171371c85657d646c7fc34485ff0a5ce0 (diff) | |
Display and send messages with format=flowed (#1484370), fixes word wrapping issues (#1486543)
git-svn-id: https://svn.roundcube.net/trunk@3644 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program/include/rcube_message.php')
| -rw-r--r-- | roundcubemail/program/include/rcube_message.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/roundcubemail/program/include/rcube_message.php b/roundcubemail/program/include/rcube_message.php index 05b0151ef..47fe3d7c1 100644 --- a/roundcubemail/program/include/rcube_message.php +++ b/roundcubemail/program/include/rcube_message.php @@ -198,6 +198,10 @@ class rcube_message if ($mimetype == 'text/plain') { $out = $this->imap->get_message_part($this->uid, $mime_id, $part); + + // re-format format=flowed content + if ($part->ctype_secondary == "plain" && $part->ctype_parameters['format'] == "flowed") + $out = self::unfold_flowed($out); break; } else if ($mimetype == 'text/html') { @@ -477,5 +481,37 @@ class rcube_message } + /** + * Interpret a format=flowed message body according to RFC 2646 + * + * @param string Raw body formatted as flowed text + * @return string Interpreted text with unwrapped lines and stuffed space removed + */ + public static function unfold_flowed($text) + { + return preg_replace( + array('/-- (\r?\n)/', '/^ /m', '/(.) \r?\n/', '/--%SIGEND%(\r?\n)/'), + array('--%SIGEND%\\1', '', '\\1 ', '-- \\1'), + $text); + } + + /** + * Wrap the given text to comply with RFC 2646 + */ + public static function format_flowed($text, $length = 72) + { + $out = ''; + + foreach (preg_split('/\r?\n/', trim($text)) as $line) { + // don't wrap quoted lines (to avoid wrapping problems) + if ($line[0] != '>') + $line = rc_wordwrap(rtrim($line), $length - 1, " \r\n"); + + $out .= $line . "\r\n"; + } + + return $out; + } + } |
