thomascube
2007-03-13 5a6ad209837a8bcca14d4f74541d8ac3ea760341
Fixed message headers encoding; improved recipient splitting; applied patch for attachment download (#1484198)

5 files modified
80 ■■■■■ changed files
CHANGELOG 13 ●●●●● patch | view | raw | blame | history
program/include/rcube_imap.inc 25 ●●●●● patch | view | raw | blame | history
program/lib/Mail/mime.php 4 ●●●● patch | view | raw | blame | history
program/steps/mail/get.inc 16 ●●●●● patch | view | raw | blame | history
program/steps/mail/sendmail.inc 22 ●●●●● patch | view | raw | blame | history
CHANGELOG
@@ -1,9 +1,22 @@
CHANGELOG RoundCube Webmail
---------------------------
2007/03/13 (thomasb)
----------
- Applied patch for attachment download by crichardson (closes #1484198)
- Fixed bug in Postgres DB handling (closes #1484068)
- Fixed bug of invalid calls to fetchRow() in rcube_db.inc (closes #1484280)
- Fixed array_merge bug (closes #1484281)
- Fixed flag for deletion in list view (closes #1484264)
- Finally support semicolons as recipient separator (closes ##1484251)
- Fixed message headers (subject) encoding
2007/03/04 (tomekp)
----------
- check if safe mode is on or not (closes #1484269)
2007/03/02 (thomasb)
----------
- Show "no subject" in message list if subject is missing (closes #1484243)
program/include/rcube_imap.inc
@@ -2454,7 +2454,7 @@
  function _parse_address_list($str)
    {
    // remove any newlines and carriage returns before
    $a = $this->_explode_quoted_string(',', preg_replace( "/[\r\n]/", " ", $str));
    $a = $this->_explode_quoted_string('[,;]', preg_replace( "/[\r\n]/", " ", $str));
    $result = array();
    
    foreach ($a as $key => $val)
@@ -2481,17 +2481,20 @@
  function _explode_quoted_string($delimiter, $string)
    {
    $quotes = explode("\"", $string);
    foreach ($quotes as $key => $val)
      if (($key % 2) == 1)
        $quotes[$key] = str_replace($delimiter, "_!@!_", $quotes[$key]);
    $string = implode("\"", $quotes);
    $result = explode($delimiter, $string);
    foreach ($result as $key => $val)
      $result[$key] = str_replace("_!@!_", $delimiter, $result[$key]);
    $result = array();
    $strlen = strlen($string);
    for ($q=$p=$i=0; $i < $strlen; $i++)
    {
      if ($string{$i} == "\"" && $string{$i-1} != "\\")
        $q = $q ? false : true;
      else if (!$q && preg_match("/$delimiter/", $string{$i}))
      {
        $result[] = substr($string, $p, $i - $p);
        $p = $i + 1;
      }
    }
    
    $result[] = substr($string, $p);
    return $result;
    }
  }
program/lib/Mail/mime.php
@@ -836,9 +836,9 @@
                    default:
                        // quoted-printable encoding has been selected
                        $mode = 'Q';
                        $encoded = preg_replace('/([\x20-\x25\x2C\x80-\xFF])/e', "'='.sprintf('%02X', ord('\\1'))", $value);
                        $encoded = preg_replace('/([\x2C\x3F\x80-\xFF])/e', "'='.sprintf('%02X', ord('\\1'))", $value);
                        // replace spaces with _
                        $encoded = str_replace('=20', '_', $encoded);
                        $encoded = str_replace(' ', '_', $encoded);
                    }
                $value = '=?' . $this->_build_params['head_charset'] . '?' . $mode . '?' . $encoded . '?=' . $suffix;
program/steps/mail/get.inc
@@ -63,19 +63,21 @@
    $mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
    $filename = $part->d_parameters['filename'] ? $part->d_parameters['filename'] : $part->ctype_parameters['name'];
    // send correct headers for content type and length
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private", false);
    header("Content-Transfer-Encoding: binary");
    header(sprintf('Content-Disposition: attachment; filename="%s";',
                   $filename ? rcube_imap::decode_mime_string($filename) : "roundcube.$ctype_secondary"));
    // send download headers
    if ($_GET['_download'])
      {
      // send download headers
      header("Cache-Control: private", false);
      header("Content-Type: application/octet-stream");
      header(sprintf('Content-Disposition: attachment; filename="%s"',
                     $filename ? rcube_imap::decode_mime_string($filename) : "roundcube.$ctype_secondary"));
      }
    else
      {
      header("Content-Type: $mimetype");
      header(sprintf('Content-Disposition: inline; filename="%s"', rcube_imap::decode_mime_string($filename)));
      }
    // We need to set the following headers to make downloads work using IE in HTTPS mode.
    if (isset($_SERVER['HTTPS']))
program/steps/mail/sendmail.inc
@@ -151,8 +151,8 @@
$input_charset = $OUTPUT->get_charset();
$message_charset = isset($_POST['_charset']) ? $_POST['_charset'] : $input_charset;
$mailto_regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m');
$mailto_replace = array(', ', ', ', '');
$mailto_regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m', '/;/');
$mailto_replace = array(', ', ', ', '', ',');
// replace new lines and strip ending ', '
$mailto = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_to', RCUBE_INPUT_POST, TRUE, $message_charset));
@@ -170,7 +170,7 @@
// compose headers array
$headers = array('Date' => date('D, j M Y H:i:s O'),
                 'From' => rcube_charset_convert($identity_arr['string'], $CHARSET, $message_charset),
                 'To'   => rcube_charset_convert($mailto, $input_charset, $message_charset));
                 'To'   => $mailto);
// additional recipients
if (!empty($_POST['_cc']))
@@ -301,10 +301,11 @@
// unset to save memory.
unset($MAIL_MIME->_parts);
// encoding subject header with mb_encode provides better results with asian characters
if ($MBSTRING && function_exists("mb_encode_mimeheader"))
{
  mb_internal_encoding($message_charset);
  $headers['Subject'] = mb_encode_mimeheader($headers['Subject'], $message_charset, 'Q');
  $mb_subject = mb_encode_mimeheader($headers['Subject'], $message_charset, 'Q');
  mb_internal_encoding($CHARSET);
}
@@ -326,12 +327,12 @@
    $send_headers = $headers;
    unset($send_headers['Bcc']);
  
    // generate message headers
    $header_str = $MAIL_MIME->txtHeaders($send_headers);
    if (!empty($mb_subject))
      $send_headers['Subject'] = $mb_subject;
  
    // send message
    $smtp_response = array();
    $sent = smtp_mail($from, $a_recipients, $header_str, $msg_body, $smtp_response);
    $sent = smtp_mail($from, $a_recipients, $MAIL_MIME->txtHeaders($send_headers), $msg_body, $smtp_response);
  
    // log error
    if (!$sent)
@@ -352,14 +353,17 @@
    $headers_php = $MAIL_MIME->_headers;
    unset($headers_php['To'], $headers_php['Subject']);
    
    if (!empty($mb_subject))
      $headers_enc['Subject'] = $mb_subject;
    // reset stored headers and overwrite
    $MAIL_MIME->_headers = array();
    $header_str = $MAIL_MIME->txtHeaders($headers_php);
  
    if (ini_get('safe_mode'))
      $sent = mail($headers_enc['To'], $headers['Subject'], $msg_body, $header_str);
      $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str);
    else
      $sent = mail($headers_enc['To'], $headers['Subject'], $msg_body, $header_str, "-f$from");
      $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str, "-f$from");
    }