Changeset 2430846 in github


Ignore:
Timestamp:
Mar 5, 2011 3:10:52 AM (2 years ago)
Author:
alecpl <alec@…>
Children:
5228a55
Parents:
01a3689
Message:
  • Applied some fixes from trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    r01a3689 r2430846  
    22=========================== 
    33 
     4- Fix some emails are not shown using Cyrus IMAP (#1487820) 
     5- Fix handling of mime-encoded words with non-integral number of octets in a word (#1487801) 
     6- Fix parsing links with non-printable characters inside (#1487805) 
    47- Fixed de_CH Localization bugs (#1487773) 
    58- Add variable for 'Today' label in date_today option (#1486120) 
  • program/include/rcube_imap.php

    r99897b7 r2430846  
    43454345    public static function decode_mime_string($input, $fallback=null) 
    43464346    { 
    4347         // Initialize variable 
    4348         $out = ''; 
    4349  
    4350         // Iterate instead of recursing, this way if there are too many values we don't have stack overflows 
     4347        if (!empty($fallback)) { 
     4348            $default_charset = $fallback; 
     4349        } 
     4350        else { 
     4351            $default_charset = rcmail::get_instance()->config->get('default_charset', 'ISO-8859-1'); 
     4352        } 
     4353 
    43514354        // rfc: all line breaks or other characters not found 
    43524355        // in the Base64 Alphabet must be ignored by decoding software 
     
    43554358        $input = preg_replace("/\?=\s+=\?/", '?==?', $input); 
    43564359 
    4357         // Check if there is stuff to decode 
    4358         if (strpos($input, '=?') !== false) { 
    4359             // Loop through the string to decode all occurences of =? ?= into the variable $out 
    4360             while(($pos = strpos($input, '=?')) !== false) { 
     4360        // encoded-word regexp 
     4361        $re = '/=\?([^?]+)\?([BbQq])\?([^?\n]*)\?=/'; 
     4362 
     4363        // Find all RFC2047's encoded words 
     4364        if (preg_match_all($re, $input, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { 
     4365            // Initialize variables 
     4366            $tmp   = array(); 
     4367            $out   = ''; 
     4368            $start = 0; 
     4369 
     4370            foreach ($matches as $idx => $m) { 
     4371                $pos      = $m[0][1]; 
     4372                $charset  = $m[1][0]; 
     4373                $encoding = $m[2][0]; 
     4374                $text     = $m[3][0]; 
     4375                $length   = strlen($m[0][0]); 
     4376 
    43614377                // Append everything that is before the text to be decoded 
    4362                 $out .= substr($input, 0, $pos); 
    4363  
    4364                 // Get the location of the text to decode 
    4365                 $end_cs_pos = strpos($input, "?", $pos+2); 
    4366                 $end_en_pos = strpos($input, "?", $end_cs_pos+1); 
    4367                 $end_pos = strpos($input, "?=", $end_en_pos+1); 
    4368  
    4369                 // Extract the encoded string 
    4370                 $encstr = substr($input, $pos+2, ($end_pos-$pos-2)); 
    4371                 // Extract the remaining string 
    4372                 $input = substr($input, $end_pos+2); 
    4373  
    4374                 // Decode the string fragement 
    4375                 $out .= rcube_imap::_decode_mime_string_part($encstr); 
    4376             } 
    4377  
    4378             // Deocde the rest (if any) 
    4379             if (strlen($input) != 0) 
    4380                 $out .= rcube_imap::decode_mime_string($input, $fallback); 
     4378                if ($start != $pos) { 
     4379                    $substr = substr($input, $start, $pos-$start); 
     4380                    $out   .= rcube_charset_convert($substr, $default_charset); 
     4381                    $start  = $pos; 
     4382                } 
     4383                $start += $length; 
     4384 
     4385                // Per RFC2047, each string part "MUST represent an integral number 
     4386                // of characters . A multi-octet character may not be split across 
     4387                // adjacent encoded-words." However, some mailers break this, so we 
     4388                // try to handle characters spanned across parts anyway by iterating 
     4389                // through and aggregating sequential encoded parts with the same 
     4390                // character set and encoding, then perform the decoding on the 
     4391                // aggregation as a whole. 
     4392 
     4393                $tmp[] = $text; 
     4394                if ($next_match = $matches[$idx+1]) { 
     4395                    if ($next_match[0][1] == $start 
     4396                        && $next_match[1][0] == $charset 
     4397                        && $next_match[2][0] == $encoding 
     4398                    ) { 
     4399                        continue; 
     4400                    } 
     4401                } 
     4402 
     4403                $count = count($tmp); 
     4404                $text  = ''; 
     4405 
     4406                // Decode and join encoded-word's chunks 
     4407                if ($encoding == 'B' || $encoding == 'b') { 
     4408                    // base64 must be decoded a segment at a time 
     4409                    for ($i=0; $i<$count; $i++) 
     4410                        $text .= base64_decode($tmp[$i]); 
     4411                } 
     4412                else { //if ($encoding == 'Q' || $encoding == 'q') { 
     4413                    // quoted printable can be combined and processed at once 
     4414                    for ($i=0; $i<$count; $i++) 
     4415                        $text .= $tmp[$i]; 
     4416 
     4417                    $text = str_replace('_', ' ', $text); 
     4418                    $text = quoted_printable_decode($text); 
     4419                } 
     4420 
     4421                $out .= rcube_charset_convert($text, $charset); 
     4422                $tmp = array(); 
     4423            } 
     4424 
     4425            // add the last part of the input string 
     4426            if ($start != strlen($input)) { 
     4427                $out .= rcube_charset_convert(substr($input, $start), $default_charset); 
     4428            } 
    43814429 
    43824430            // return the results 
     
    43854433 
    43864434        // no encoding information, use fallback 
    4387         return rcube_charset_convert($input, 
    4388             !empty($fallback) ? $fallback : rcmail::get_instance()->config->get('default_charset', 'ISO-8859-1')); 
    4389     } 
    4390  
    4391  
    4392     /** 
    4393      * Decode a part of a mime-encoded string 
    4394      * 
    4395      * @param string $str String to decode 
    4396      * @return string Decoded string 
    4397      * @access private 
    4398      */ 
    4399     private function _decode_mime_string_part($str) 
    4400     { 
    4401         $a = explode('?', $str); 
    4402         $count = count($a); 
    4403  
    4404         // should be in format "charset?encoding?base64_string" 
    4405         if ($count >= 3) { 
    4406             for ($i=2; $i<$count; $i++) 
    4407                 $rest .= $a[$i]; 
    4408  
    4409             if (($a[1]=='B') || ($a[1]=='b')) 
    4410                 $rest = base64_decode($rest); 
    4411             else if (($a[1]=='Q') || ($a[1]=='q')) { 
    4412                 $rest = str_replace('_', ' ', $rest); 
    4413                 $rest = quoted_printable_decode($rest); 
    4414             } 
    4415  
    4416             return rcube_charset_convert($rest, $a[0]); 
    4417         } 
    4418  
    4419         // we dont' know what to do with this 
    4420         return $str; 
     4435        return rcube_charset_convert($input, $default_charset); 
    44214436    } 
    44224437 
  • program/include/rcube_imap_generic.php

    r1a2754d r2430846  
    13521352                    } 
    13531353                } else if ($mode == 2) { 
    1354                     if (preg_match('/\((UID|RFC822\.SIZE) ([0-9]+)/', $line, $matches)) { 
     1354                    if (preg_match('/(UID|RFC822\.SIZE) ([0-9]+)/', $line, $matches)) { 
    13551355                        $result[$id] = trim($matches[2]); 
    13561356                    } else { 
  • program/lib/html2text.php

    r6084d78 r2430846  
    653653            return $this->_strtoupper("\n\n". $matches[2] ."\n\n"); 
    654654        case 'a': 
    655             return $this->_build_link_list($matches[3], $matches[4]); 
    656         } 
    657     } 
    658      
     655            // Remove spaces in URL (#1487805) 
     656            $url = str_replace(' ', '', $matches[3]); 
     657            return $this->_build_link_list($url, $matches[4]); 
     658        } 
     659    } 
     660 
    659661    /** 
    660662     *  Strtoupper multibyte wrapper function 
  • program/localization/fr_FR/labels.inc

    r98cb0f1 r2430846  
    104104$labels['replylist'] = 'Répondre à la liste'; 
    105105$labels['forwardmessage'] = 'Transmettre le message'; 
    106 $labels['deletemessage'] = 'Déplacer le message dans la corbeille'; 
     106$labels['deletemessage'] = 'Supprimer le message'; 
    107107$labels['movemessagetotrash'] = 'Déplacer le message dans la corbeille'; 
    108108$labels['printmessage'] = 'Imprimer ce message'; 
  • program/steps/mail/func.inc

    rb46e5b74 r2430846  
    12011201  $end = '>'; 
    12021202 
     1203  // Remove non-printable characters in URL (#1487805) 
     1204  $attrib['href'] = preg_replace('/[\x00-\x1F]/', '', $attrib['href']); 
     1205 
    12031206  if ($tag == 'link' && preg_match('/^https?:\/\//i', $attrib['href'])) { 
    12041207    $tempurl = 'tmp-' . md5($attrib['href']) . '.css'; 
Note: See TracChangeset for help on using the changeset viewer.