Changeset 3644 in subversion


Ignore:
Timestamp:
May 20, 2010 5:28:30 PM (3 years ago)
Author:
thomasb
Message:

Display and send messages with format=flowed (#1484370), fixes word wrapping issues (#1486543)

Location:
trunk/roundcubemail
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r3640 r3644  
    22=========================== 
    33 
     4- Read and send messages with format=flowed (#1484370), fixes word wrapping issues (#1486543) 
    45- Fix duplicated attachments when forwarding a message (#1486487) 
    56- Fix message/rfc822 attachments containing only attachments are not parsed properly (#1486743) 
  • trunk/roundcubemail/config/main.inc.php.dist

    r3520 r3644  
    66 |                                                                       | 
    77 | This file is part of the RoundCube Webmail client                     | 
    8  | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland                 | 
     8 | Copyright (C) 2005-2010, RoundCube Dev. - Switzerland                 | 
    99 | Licensed under the GNU GPL                                            | 
    1010 |                                                                       | 
     
    189189 
    190190// add this user-agent to message headers when sending 
    191 $rcmail_config['useragent'] = 'RoundCube Webmail/'.RCMAIL_VERSION; 
     191$rcmail_config['useragent'] = 'Roundcube Webmail/'.RCMAIL_VERSION; 
    192192 
    193193// use this name to compose page titles 
    194 $rcmail_config['product_name'] = 'RoundCube Webmail'; 
     194$rcmail_config['product_name'] = 'Roundcube Webmail'; 
    195195 
    196196// try to load host-specific configuration 
     
    214214// leave empty for auto-detection 
    215215$rcmail_config['mail_header_delimiter'] = NULL; 
     216 
     217// number of chars allowed for line when wrapping text. 
     218// text wrapping is done when composing/sending messages 
     219$rcmail_config['line_length'] = 66; 
     220 
     221// send plaintext messages as format=flowed 
     222$rcmail_config['send_format_flowed'] = true; 
    216223 
    217224// session domain: .example.org 
  • trunk/roundcubemail/program/include/rcube_message.php

    r3639 r3644  
    199199      if ($mimetype == 'text/plain') { 
    200200        $out = $this->imap->get_message_part($this->uid, $mime_id, $part); 
     201         
     202        // re-format format=flowed content 
     203        if ($part->ctype_secondary == "plain" && $part->ctype_parameters['format'] == "flowed") 
     204          $out = self::unfold_flowed($out); 
    201205        break; 
    202206      } 
     
    478482 
    479483 
     484  /** 
     485   * Interpret a format=flowed message body according to RFC 2646 
     486   * 
     487   * @param string  Raw body formatted as flowed text 
     488   * @return string Interpreted text with unwrapped lines and stuffed space removed 
     489   */ 
     490  public static function unfold_flowed($text) 
     491  { 
     492    return preg_replace( 
     493      array('/-- (\r?\n)/',   '/^ /m',  '/(.) \r?\n/',  '/--%SIGEND%(\r?\n)/'), 
     494      array('--%SIGEND%\\1',  '',       '\\1 ',         '-- \\1'), 
     495      $text); 
     496  } 
     497   
     498  /** 
     499   * Wrap the given text to comply with RFC 2646 
     500   */ 
     501  public static function format_flowed($text, $length = 72) 
     502  { 
     503    $out = ''; 
     504     
     505    foreach (preg_split('/\r?\n/', trim($text)) as $line) { 
     506      // don't wrap quoted lines (to avoid wrapping problems) 
     507      if ($line[0] != '>') 
     508        $line = rc_wordwrap(rtrim($line), $length - 1, " \r\n"); 
     509 
     510      $out .= $line . "\r\n"; 
     511    } 
     512     
     513    return $out; 
     514  } 
     515 
    480516} 
    481517 
  • trunk/roundcubemail/program/steps/mail/compose.inc

    r3640 r3644  
    135135 
    136136// set line length for body wrapping 
    137 $LINE_LENGTH = $RCMAIL->config->get('line_length', 75); 
     137$LINE_LENGTH = $RCMAIL->config->get('line_length', 72); 
    138138 
    139139if (!empty($msg_uid)) 
     
    598598    } 
    599599 
    600     // soft-wrap message first 
    601     $body = rcmail_wrap_quoted($body, $LINE_LENGTH); 
    602  
    603     $body = rtrim($body, "\r\n"); 
    604  
    605     if ($body) { 
    606       // split body into single lines 
    607       $a_lines = preg_split('/\r?\n/', $body); 
    608  
    609       // add > to each line 
    610       for ($n=0; $n<sizeof($a_lines); $n++) { 
    611         if (strpos($a_lines[$n], '>')===0) 
    612           $a_lines[$n] = '>'.$a_lines[$n]; 
    613         else 
    614           $a_lines[$n] = '> '.$a_lines[$n]; 
    615       } 
    616   
    617       $body = join("\n", $a_lines); 
    618     } 
     600    // soft-wrap and quote message text 
     601    $body = rcmail_wrap_and_quote(rtrim($body, "\r\n"), $LINE_LENGTH); 
    619602 
    620603    // add title line(s) 
    621     $prefix = rc_wordwrap(sprintf("On %s, %s wrote:\n", 
     604    $prefix = sprintf("On %s, %s wrote:\n", 
    622605      $MESSAGE->headers->date, 
    623       $MESSAGE->get_header('from')), $LINE_LENGTH); 
     606      $MESSAGE->get_header('from')); 
    624607 
    625608    $suffix = ''; 
  • trunk/roundcubemail/program/steps/mail/func.inc

    r3627 r3644  
    933933        if (!isset($part->body)) 
    934934          $part->body = $MESSAGE->get_part_content($part->mime_id); 
     935 
     936        // re-format format=flowed content 
     937        if ($part->ctype_secondary == "plain" && $part->ctype_parameters['format'] == "flowed") 
     938          $part->body = rcube_message::unfold_flowed($part->body); 
    935939 
    936940        $body = rcmail_print_body($part, array('safe' => $safe_mode, 'plain' => !$CONFIG['prefer_html'])); 
     
    11621166/** 
    11631167 * Wrap text to a given number of characters per line 
    1164  * but respect the mail quotation of replies messages (>) 
     1168 * but respect the mail quotation of replies messages (>). 
     1169 * Finally add another quotation level by prpending the lines 
     1170 * with > 
    11651171 * 
    11661172 * @param string Text to wrap 
     
    11681174 * @return string The wrapped text 
    11691175 */ 
    1170 function rcmail_wrap_quoted($text, $max = 76) 
     1176function rcmail_wrap_and_quote($text, $length = 72) 
    11711177{ 
    11721178  // Rebuild the message body with a maximum of $max chars, while keeping quoted message. 
     1179  $max = min(78, $length + 8); 
    11731180  $lines = preg_split('/\r?\n/', trim($text)); 
    11741181  $out = ''; 
    11751182 
    11761183  foreach ($lines as $line) { 
    1177     if (strlen($line) > $max) { 
    1178       if (preg_match('/^([>\s]+)/', $line, $regs)) { 
    1179         $length = strlen($regs[0]); 
    1180         $prefix = substr($line, 0, $length); 
    1181  
    1182         // Remove '> ' from the line, then wordwrap() the line 
    1183         $line = rc_wordwrap(substr($line, $length), $max - $length); 
    1184  
    1185         // Rebuild the line with '> ' at the beginning of each 'subline' 
    1186         $newline = ''; 
    1187         foreach (explode("\n", $line) as $l) { 
    1188           $newline .= $prefix . $l . "\n"; 
    1189         } 
    1190  
    1191         // Remove the righest newline char 
    1192         $line = rtrim($newline); 
     1184    // don't wrap already quoted lines 
     1185    if ($line[0] == '>') 
     1186      $line = '>' . rtrim($line); 
     1187    else if (mb_strlen($line) > $max) { 
     1188      $newline = ''; 
     1189      foreach(explode("\n", rc_wordwrap($line, $length - 2)) as $l) { 
     1190        if (strlen($l)) 
     1191          $newline .= '> ' . $l . "\n"; 
     1192        else 
     1193          $newline .= ">\n"; 
    11931194      } 
    1194       else { 
    1195         $line = rc_wordwrap($line, $max); 
    1196       } 
    1197     } 
     1195      $line = rtrim($newline); 
     1196    } 
     1197    else 
     1198      $line = '> ' . $line; 
    11981199 
    11991200    // Append the line 
  • trunk/roundcubemail/program/steps/mail/sendmail.inc

    r3642 r3644  
    66 |                                                                       | 
    77 | This file is part of the RoundCube Webmail client                     | 
    8  | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland                 | 
     8 | Copyright (C) 2005-2010, RoundCube Dev. - Switzerland                 | 
    99 | Licensed under the GNU GPL                                            | 
    1010 |                                                                       | 
     
    441441  $message_body = rcmail_attach_emoticons($MAIL_MIME); 
    442442} 
    443 else 
    444   { 
    445   $message_body = rc_wordwrap($message_body, $LINE_LENGTH, "\r\n"); 
     443else { 
    446444  if ($footer) 
    447445    $message_body .= "\r\n" . $footer; 
     446   
     447  // compose format=flowed content if enabled and not a reply message 
     448  if (empty($_SESSION['compose']['reply_msgid']) && ($flowed = $RCMAIL->config->get('send_format_flowed', true))) 
     449    $message_body = rcube_message::format_flowed($message_body, $LINE_LENGTH); 
     450  else 
     451    $message_body = rc_wordwrap($message_body, min(79, $LINE_LENGTH + 8), "\r\n");  // +8: be generous with quoted lines 
     452   
    448453  $message_body = wordwrap($message_body, 998, "\r\n", true); 
    449454  if (!strlen($message_body)) {  
     
    504509$MAIL_MIME->setParam('head_charset', $message_charset); 
    505510$MAIL_MIME->setParam('html_charset', $message_charset); 
    506 $MAIL_MIME->setParam('text_charset', $message_charset); 
     511$MAIL_MIME->setParam('text_charset', $message_charset . ($flowed ? ";\r\n format=flowed" : '')); 
    507512 
    508513// encoding subject header with mb_encode provides better results with asian characters 
Note: See TracChangeset for help on using the changeset viewer.