Changeset 4980 in subversion


Ignore:
Timestamp:
Jul 27, 2011 2:21:49 PM (23 months ago)
Author:
alec
Message:
  • Use rcube_imap_generic::tokenizeResponse() for parsing BODYSTRUCTURE, fixes #1488007
Location:
trunk/roundcubemail/program/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcube_imap.php

    r4978 r4980  
    21642164                        $mime_part_headers[] = $tmp_part_id; 
    21652165                    } 
    2166                     else if (in_array('name', (array)$part[$i][2]) && (empty($part[$i][3]) || $part[$i][3]=='NIL')) { 
     2166                    else if (in_array('name', (array)$part[$i][2]) && empty($part[$i][3])) { 
    21672167                        $mime_part_headers[] = $tmp_part_id; 
    21682168                    } 
     
    22322232 
    22332233        // read content encoding 
    2234         if (!empty($part[5]) && $part[5]!='NIL') { 
     2234        if (!empty($part[5])) { 
    22352235            $struct->encoding = strtolower($part[5]); 
    22362236            $struct->headers['content-transfer-encoding'] = $struct->encoding; 
     
    22382238 
    22392239        // get part size 
    2240         if (!empty($part[6]) && $part[6]!='NIL') 
     2240        if (!empty($part[6])) 
    22412241            $struct->size = intval($part[6]); 
    22422242 
     
    22652265 
    22662266        // get part ID 
    2267         if (!empty($part[3]) && $part[3]!='NIL') { 
     2267        if (!empty($part[3])) { 
    22682268            $struct->content_id = $part[3]; 
    22692269            $struct->headers['content-id'] = $part[3]; 
  • trunk/roundcubemail/program/include/rcube_mime_struct.php

    • Property svn:keywords set to Id Author
    r4410 r4980  
    77 |                                                                       | 
    88 | This file is part of the Roundcube Webmail client                     | 
    9  | Copyright (C) 2005-2010, The Roundcube Dev Team                       | 
     9 | Copyright (C) 2005-2011, The Roundcube Dev Team                       | 
    1010 | Licensed under the GNU GPL                                            | 
    1111 |                                                                       | 
     
    4949        $line = str_replace(')(', ') (', $line); 
    5050 
    51             $struct = self::parseBSString($line); 
     51            $struct = rcube_imap_generic::tokenizeResponse($line); 
    5252        if (!is_array($struct[0]) && (strcasecmp($struct[0], 'message') == 0) 
    5353                    && (strcasecmp($struct[1], 'rfc822') == 0)) { 
     
    7979                return $part_a[0]; 
    8080            } 
    81          
     81 
    8282        return 'other'; 
    8383    } 
     
    9090                return $part_a[5]; 
    9191            } 
    92          
     92 
    9393        return ''; 
    9494    } 
     
    109109                    } 
    110110            } 
    111          
     111 
    112112        return ''; 
    113113    } 
     
    143143    } 
    144144 
    145     private function closingParenPos($str, $start) 
    146     { 
    147         $level = 0; 
    148         $len = strlen($str); 
    149         $in_quote = 0; 
    150  
    151         for ($i=$start; $i<$len; $i++) { 
    152             if ($str[$i] == '"' && $str[$i-1] != "\\") { 
    153                         $in_quote = ($in_quote + 1) % 2; 
    154             } 
    155             if (!$in_quote) { 
    156                     if ($str[$i] == '(') 
    157                     $level++; 
    158                     else if (($level > 0) && ($str[$i] == ')')) 
    159                     $level--; 
    160                     else if (($level == 0) && ($str[$i] == ')')) 
    161                     return $i; 
    162             } 
    163         } 
    164     } 
    165  
    166     /* 
    167      * Parses IMAP's BODYSTRUCTURE string into array 
    168     */ 
    169     private function parseBSString($str) 
    170     {    
    171         $id = 0; 
    172         $a = array(); 
    173         $len = strlen($str); 
    174         $in_quote = 0; 
    175  
    176         for ($i=0; $i<$len; $i++) { 
    177             if ($str[$i] == '"') { 
    178                     $in_quote = ($in_quote + 1) % 2; 
    179             } else if (!$in_quote) { 
    180                 // space means new element 
    181                 if ($str[$i] == ' ') { 
    182                     $id++; 
    183                     // skip additional spaces 
    184                     while ($str[$i+1] == ' ') 
    185                         $i++; 
    186                 // new part 
    187                 } else if ($str[$i] == '(') { 
    188                     $i++; 
    189                     $endPos = self::closingParenPos($str, $i); 
    190                     $partLen = $endPos - $i; 
    191                     if ($partLen < 0) 
    192                         break; 
    193                     $part = substr($str, $i, $partLen); 
    194                     $a[$id] = self::parseBSString($part); // send part string 
    195                     $i = $endPos; 
    196                 } else 
    197                             $a[$id] .= $str[$i]; //add to current element in array 
    198             } else if ($in_quote) { 
    199                 if ($str[$i] == "\\") { 
    200                             $i++; // escape backslashes 
    201                             if ($str[$i] == '"' || $str[$i] == "\\") 
    202                                 $a[$id] .= $str[$i]; 
    203                 } 
    204                 else 
    205                             $a[$id] .= $str[$i]; //add to current element in array 
    206             } 
    207         } 
    208          
    209         reset($a); 
    210         return $a; 
    211     } 
    212  
    213  
    214145} 
Note: See TracChangeset for help on using the changeset viewer.