summaryrefslogtreecommitdiff
path: root/program/steps/mail
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2010-05-20 21:28:30 +0000
committerthomascube <thomas@roundcube.net>2010-05-20 21:28:30 +0000
commit6b6f2e83de0e5b48ba48583206bd456508554540 (patch)
tree4d687f9dbd86fb24a1c86703340c19aa7927fc28 /program/steps/mail
parente93c72d9a378903502fa51452d6db3fffc3a9b28 (diff)
Display and send messages with format=flowed (#1484370), fixes word wrapping issues (#1486543)
Diffstat (limited to 'program/steps/mail')
-rw-r--r--program/steps/mail/compose.inc27
-rw-r--r--program/steps/mail/func.inc43
-rw-r--r--program/steps/mail/sendmail.inc15
3 files changed, 37 insertions, 48 deletions
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 50f11a361..0b18d122a 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -134,7 +134,7 @@ else
$OUTPUT->set_env('show_sig', false);
// set line length for body wrapping
-$LINE_LENGTH = $RCMAIL->config->get('line_length', 75);
+$LINE_LENGTH = $RCMAIL->config->get('line_length', 72);
if (!empty($msg_uid))
{
@@ -597,30 +597,13 @@ function rcmail_create_reply_body($body, $bodyIsHtml)
$body = substr($body, 0, max(0, $sp-1));
}
- // soft-wrap message first
- $body = rcmail_wrap_quoted($body, $LINE_LENGTH);
-
- $body = rtrim($body, "\r\n");
-
- if ($body) {
- // split body into single lines
- $a_lines = preg_split('/\r?\n/', $body);
-
- // add > to each line
- for ($n=0; $n<sizeof($a_lines); $n++) {
- if (strpos($a_lines[$n], '>')===0)
- $a_lines[$n] = '>'.$a_lines[$n];
- else
- $a_lines[$n] = '> '.$a_lines[$n];
- }
-
- $body = join("\n", $a_lines);
- }
+ // soft-wrap and quote message text
+ $body = rcmail_wrap_and_quote(rtrim($body, "\r\n"), $LINE_LENGTH);
// add title line(s)
- $prefix = rc_wordwrap(sprintf("On %s, %s wrote:\n",
+ $prefix = sprintf("On %s, %s wrote:\n",
$MESSAGE->headers->date,
- $MESSAGE->get_header('from')), $LINE_LENGTH);
+ $MESSAGE->get_header('from'));
$suffix = '';
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 951e777b1..fcb0229df 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -933,6 +933,10 @@ function rcmail_message_body($attrib)
if (!isset($part->body))
$part->body = $MESSAGE->get_part_content($part->mime_id);
+ // re-format format=flowed content
+ if ($part->ctype_secondary == "plain" && $part->ctype_parameters['format'] == "flowed")
+ $part->body = rcube_message::unfold_flowed($part->body);
+
$body = rcmail_print_body($part, array('safe' => $safe_mode, 'plain' => !$CONFIG['prefer_html']));
if ($part->ctype_secondary == 'html')
@@ -1161,40 +1165,37 @@ function rcmail_address_string($input, $max=null, $linked=false, $addicon=null)
/**
* Wrap text to a given number of characters per line
- * but respect the mail quotation of replies messages (>)
+ * but respect the mail quotation of replies messages (>).
+ * Finally add another quotation level by prpending the lines
+ * with >
*
* @param string Text to wrap
* @param int The line width
* @return string The wrapped text
*/
-function rcmail_wrap_quoted($text, $max = 76)
+function rcmail_wrap_and_quote($text, $length = 72)
{
// Rebuild the message body with a maximum of $max chars, while keeping quoted message.
+ $max = min(78, $length + 8);
$lines = preg_split('/\r?\n/', trim($text));
$out = '';
foreach ($lines as $line) {
- if (strlen($line) > $max) {
- if (preg_match('/^([>\s]+)/', $line, $regs)) {
- $length = strlen($regs[0]);
- $prefix = substr($line, 0, $length);
-
- // Remove '> ' from the line, then wordwrap() the line
- $line = rc_wordwrap(substr($line, $length), $max - $length);
-
- // Rebuild the line with '> ' at the beginning of each 'subline'
- $newline = '';
- foreach (explode("\n", $line) as $l) {
- $newline .= $prefix . $l . "\n";
- }
-
- // Remove the righest newline char
- $line = rtrim($newline);
- }
- else {
- $line = rc_wordwrap($line, $max);
+ // don't wrap already quoted lines
+ if ($line[0] == '>')
+ $line = '>' . rtrim($line);
+ else if (mb_strlen($line) > $max) {
+ $newline = '';
+ foreach(explode("\n", rc_wordwrap($line, $length - 2)) as $l) {
+ if (strlen($l))
+ $newline .= '> ' . $l . "\n";
+ else
+ $newline .= ">\n";
}
+ $line = rtrim($newline);
}
+ else
+ $line = '> ' . $line;
// Append the line
$out .= $line . "\n";
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index e7f5b9557..8e43b37a0 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -5,7 +5,7 @@
| program/steps/mail/sendmail.inc |
| |
| This file is part of the RoundCube Webmail client |
- | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland |
+ | Copyright (C) 2005-2010, RoundCube Dev. - Switzerland |
| Licensed under the GNU GPL |
| |
| PURPOSE: |
@@ -440,11 +440,16 @@ if ($isHtml) {
// look for "emoticon" images from TinyMCE and copy into message as attachments
$message_body = rcmail_attach_emoticons($MAIL_MIME);
}
-else
- {
- $message_body = rc_wordwrap($message_body, $LINE_LENGTH, "\r\n");
+else {
if ($footer)
$message_body .= "\r\n" . $footer;
+
+ // compose format=flowed content if enabled and not a reply message
+ if (empty($_SESSION['compose']['reply_msgid']) && ($flowed = $RCMAIL->config->get('send_format_flowed', true)))
+ $message_body = rcube_message::format_flowed($message_body, $LINE_LENGTH);
+ else
+ $message_body = rc_wordwrap($message_body, min(79, $LINE_LENGTH + 8), "\r\n"); // +8: be generous with quoted lines
+
$message_body = wordwrap($message_body, 998, "\r\n", true);
if (!strlen($message_body)) {
// empty message body breaks attachment handling in drafts
@@ -503,7 +508,7 @@ $MAIL_MIME->setParam('html_encoding', 'quoted-printable');
$MAIL_MIME->setParam('head_encoding', 'quoted-printable');
$MAIL_MIME->setParam('head_charset', $message_charset);
$MAIL_MIME->setParam('html_charset', $message_charset);
-$MAIL_MIME->setParam('text_charset', $message_charset);
+$MAIL_MIME->setParam('text_charset', $message_charset . ($flowed ? ";\r\n format=flowed" : ''));
// encoding subject header with mb_encode provides better results with asian characters
if (function_exists('mb_encode_mimeheader'))