Changeset 1018 in subversion


Ignore:
Timestamp:
Feb 5, 2008 2:48:07 PM (5 years ago)
Author:
tomekp
Message:

more merging

Location:
branches/devel-vnext/program
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-vnext/program/include/globals.php

    r1015 r1018  
    3333 * @see rcube::rep_specialchars_output() 
    3434 */ 
    35 function Q($str = '', $mode = 'strict', $newlines = TRUE) { 
     35function Q($str = '', $mode = 'strict', $newlines = true) { 
    3636    return rcube::rep_specialchars_output($str, 'html', $mode, $newlines); 
    3737} 
     
    7878/** 
    7979 * Send HTTP headers to prevent caching this page 
    80  *  
     80 * 
    8181 * @return void 
    8282 */ 
     
    8585        return; 
    8686    } 
    87     header("Expires: ".gmdate("D, d M Y H:i:s")." GMT"); 
    88     header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 
    89     header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); 
    90     header("Pragma: no-cache"); 
    91 } 
    92  
     87    header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); 
     88    header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 
     89    header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); 
     90    header('Pragma: no-cache'); 
     91} 
    9392 
    9493/** 
     
    122121    } 
    123122    $iscached = false; 
    124     if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] 
    125         && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $mdate) { 
     123    if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $mdate) { 
    126124        $iscached = true; 
    127125    } 
     
    131129        $iscached = true; 
    132130    } 
     131 
    133132    if ($iscached) { 
    134133        header('HTTP/1.x 304 Not Modified'); 
     
    141140 
    142141    if ($etag) { 
    143         header("Etag: $etag"); 
     142        header('Etag: '.$etag); 
    144143    } 
    145144 
     
    148147    } 
    149148} 
    150  
    151149 
    152150/** 
     
    185183            foreach ($var as $key => $value) { 
    186184                // enclose key with quotes if it is not variable-name conform 
    187                 if (!ereg('^[_a-zA-Z]{1}[_a-zA-Z0-9]*$', $key) /* || is_js_reserved_word($key) */) { 
     185                if (!preg_match('/^[_a-zA-Z]{1}[_a-zA-Z0-9]*$/', $key) /* || is_js_reserved_word($key) */) { 
    188186                    $key = "'$key'"; 
    189187                } 
     
    202200 
    203201/** 
    204  * Function to convert an array to a javascript array 
    205  * Actually an alias function for json_serialize() 
    206  * @deprecated 
    207  */ 
    208 // TODO is it really not used? rcmail_compose line 368 
    209 function array2js($arr, $type='') { 
    210     return json_serialize($arr); 
    211 } 
    212  
    213  
    214 /** 
    215202 * Similar function as in_array() but case-insensitive 
    216203 * 
     
    222209    foreach ($haystack as $value) { 
    223210        if (strtolower($needle) === strtolower($value)) { 
    224             return TRUE; 
    225         } 
    226     } 
    227     return FALSE; 
     211            return true; 
     212        } 
     213    } 
     214    return false; 
    228215} 
    229216 
     
    235222 * @return boolean Imagine what! 
    236223 */ 
     224//TODO wtf? purge this 
    237225function get_boolean($str) { 
    238     $str = strtolower($str); 
    239     if(in_array($str, array('false', '0', 'no', 'nein', ''), TRUE)) { 
    240         return FALSE; 
    241     } 
    242     return TRUE; 
    243 } 
    244  
     226    if (in_array(strtolower($str), array('false', '0', 'no', 'nein', ''), true)) { 
     227        return false; 
     228    } 
     229    return true; 
     230} 
    245231 
    246232/** 
     
    258244        $bytes = floatval($regs[1]); 
    259245        switch (strtolower($regs[2])) { 
    260         case 'g': 
    261             $bytes *= 1073741824; 
    262             break; 
    263         case 'm': 
    264             $bytes *= 1048576; 
    265             break; 
    266         case 'k': 
    267             $bytes *= 1024; 
    268             break; 
     246            case 'g': 
     247                $bytes *= 1073741824; 
     248                break; 
     249            case 'm': 
     250                $bytes *= 1048576; 
     251                break; 
     252            case 'k': 
     253                $bytes *= 1024; 
     254                break; 
    269255        } 
    270256    } 
     
    307293    $abs_path = $path; 
    308294 
     295    // check if path is an absolute URL 
     296    if (preg_match('/^[fhtps]+:\/\//', $path)) { 
     297        return $path; 
     298    } 
    309299    // cut base_url to the last directory 
    310300    if (strpos($base_url, '/') > 7) { 
     
    371361        return mb_strpos($haystack, $needle, $offset); 
    372362    } 
    373         return strpos($haystack, $needle, $offset); 
     363    return strpos($haystack, $needle, $offset); 
    374364} 
    375365 
     
    381371        return mb_strrpos($haystack, $needle, $offset); 
    382372    } 
    383         return strrpos($haystack, $needle, $offset); 
     373    return strrpos($haystack, $needle, $offset); 
    384374} 
    385375 
     
    432422    while ($file = readdir($dir)) { 
    433423        if (strlen($file) > 2) { 
    434             unlink("$dir_path/$file"); 
     424            unlink($dir_path.'/'.$file); 
    435425        } 
    436426    } 
     
    459449    $ts = mktime(); 
    460450    switch ($unit) { 
    461     case 'w': 
    462         $amount *= 7; 
    463     case 'd': 
    464         $amount *= 24; 
    465     case 'h': 
    466         $amount *= 60; 
    467     case 'm': 
    468         $amount *= 60; 
    469     case 's': 
    470         $ts += $amount * $factor; 
     451        case 'w': 
     452            $amount *= 7; 
     453        case 'd': 
     454            $amount *= 24; 
     455        case 'h': 
     456            $amount *= 60; 
     457        case 'm': 
     458            $amount *= 60; 
     459        case 's': 
     460            $ts += $amount * $factor; 
    471461    } 
    472462 
     
    474464} 
    475465 
    476  
    477 /** 
    478  * Return the last occurence of a string in another string 
    479  * 
    480  * @param haystack string string in which to search 
    481  * @param needle string string for which to search 
    482  * @return index of needle within haystack, or false if not found 
    483  */ 
    484 function strrstr($haystack, $needle) { 
    485     $pver = phpversion(); 
    486     if ($pver[0] >= 5) { 
    487         return strrpos($haystack, $needle); 
    488     } 
    489     $index = strpos(strrev($haystack), strrev($needle)); 
    490     if ($index === false) { 
    491         return false; 
    492     } 
    493     $index = strlen($haystack) - strlen($needle) - $index; 
    494     return $index; 
     466function explode_quoted_string($delimiter, $string) { 
     467    $result = array(); 
     468    $strlen = strlen($string); 
     469    for ($q=$p=$i=0; $i < $strlen; $i++) { 
     470        if ($string{$i} == "\"" && $string{$i-1} != "\\") { 
     471        $q = $q ? false : true; 
     472        } else if (!$q && preg_match("/$delimiter/", $string{$i})) { 
     473            $result[] = substr($string, $p, $i - $p); 
     474            $p = $i + 1; 
     475        } 
     476    } 
     477 
     478    $result[] = substr($string, $p); 
     479    return $result; 
    495480} 
    496481 
  • branches/devel-vnext/program/include/rcube/rcmail_compose.php

    r962 r1018  
    352352        $lang_set = ''; 
    353353        if (!empty($CONFIG['spellcheck_languages']) && is_array($CONFIG['spellcheck_languages'])) { 
    354             $lang_set = "googie.setLanguages(".array2js($CONFIG['spellcheck_languages']).");\n"; 
     354            $lang_set = "googie.setLanguages(".json_serialize($CONFIG['spellcheck_languages']).");\n"; 
    355355        } 
    356356        $OUTPUT->include_script('googiespell.js'); 
     
    428428 
    429429        // try to remove the signature 
    430         if ($sp = strrstr($body, '-- ')) { 
     430        if ($sp = strrpos($body, '-- ')) { 
    431431            if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r") { 
    432432                $body = substr($body, 0, $sp-1); 
  • branches/devel-vnext/program/include/rcube_header_sorter.php

    r806 r1018  
    88 * @license GPL 
    99 */ 
    10 class rcube_header_sorter 
    11 { 
    12     var $sequence_numbers = array(); 
     10class rcube_header_sorter { 
     11    private $sequence_numbers = array(); 
    1312 
    1413    /** 
    15      * set the predetermined sort order. 
     14     * Set the predetermined sort order. 
    1615     * 
    17      * @param array $seqnums numerically indexed array of IMAP message sequence numbers 
     16     * @param array Numerically indexed array of IMAP message sequence numbers 
    1817     */ 
    19     public function set_sequence_numbers($seqnums) 
    20     { 
     18    public function set_sequence_numbers($seqnums = array()) { 
    2119        $this->sequence_numbers = $seqnums; 
    2220    } 
    2321 
    2422    /** 
    25      * sort the array of header objects 
     23     * Sort the array of header objects 
    2624     * 
    27      * @param array $headers array of iilBasicHeader objects indexed by UID 
     25     * @param array Array of iilBasicHeader objects indexed by UID 
    2826     */ 
    29     public function sort_headers(&$headers) 
    30     { 
     27    public function sort_headers($headers) { 
    3128        /** 
    3229         * uksort would work if the keys were the sequence number, but unfortunately 
     
    3633         * uksort($headers, array($this, "compare_seqnums")); 
    3734         */ 
    38         uasort($headers, array($this, "compare_seqnums")); 
     35        uasort($headers, array($this, 'compare_seqnums')); 
    3936    } 
    4037 
    4138    /** 
    42      * get the position of a message sequence number in my sequence_numbers array 
     39     * Get the position of a message sequence number in my sequence_numbers array 
    4340     * 
    44      * @param integer $seqnum message sequence number contained in sequence_numbers 
     41     * @param int Message sequence number contained in sequence_numbers 
     42     * @return int Position, -1 if not found 
    4543     */ 
    46     public function position_of($seqnum) 
    47     { 
    48         $c = count($this->sequence_numbers); 
    49         for ($pos = 0; $pos <= $c; $pos++) { 
     44    public function position_of($seqnum) { 
     45        for ($pos = 0, $c = count($this->sequence_numbers); $pos <= $c; $pos++) { 
    5046            if ($this->sequence_numbers[$pos] == $seqnum) { 
    5147                return $pos; 
     
    5854     * Sort method called by uasort() 
    5955     */ 
    60     public function compare_seqnums($a, $b) 
    61     { 
     56    public function compare_seqnums($a, $b) { 
    6257        // First get the sequence number from the header object (the 'id' field). 
    6358        $seqa = $a->id; 
     
    7368    } 
    7469} 
     70 
     71?> 
  • branches/devel-vnext/program/include/rcube_html_page.php

    r1017 r1018  
    195195        // find and add page footer 
    196196        $output_lc = strtolower($output); 
    197         if (($fpos = strrstr($output_lc, '</body>')) || ($fpos = strrstr($output_lc, '</html>'))) { 
     197        if (($fpos = strrpos($output_lc, '</body>')) || ($fpos = strrpos($output_lc, '</html>'))) { 
    198198            $output = substr($output, 0, $fpos) . "$__page_footer\n" . substr($output, $fpos); 
    199199        } else { 
  • branches/devel-vnext/program/include/rcube_imap.php

    r1017 r1018  
    3939 * @link       http://ilohamail.org 
    4040 */ 
    41 class rcube_imap 
    42 { 
     41class rcube_imap { 
    4342    var $db; 
    4443    var $conn; 
     
    19371936        $_query.= ' ?, ?, ?)'; 
    19381937        $this->db->query($_query, $_SESSION['user_id'], $key, $index, $headers->uid, 
    1939             (string)substr($this->decode_header($headers->subject, true), 0, 128), 
    1940             (string)substr($this->decode_header($headers->from, true), 0, 128), 
    1941             (string)substr($this->decode_header($headers->to, true), 0, 128), 
    1942             (string)substr($this->decode_header($headers->cc, true), 0, 128), 
    1943             (int)$headers->size, 
    1944             serialize($headers), 
    1945             (is_object($struct) ? serialize($struct) : null)); 
     1938        (string)substr($this->decode_header($headers->subject, true), 0, 128), 
     1939        (string)substr($this->decode_header($headers->from, true), 0, 128), 
     1940        (string)substr($this->decode_header($headers->to, true), 0, 128), 
     1941        (string)substr($this->decode_header($headers->cc, true), 0, 128), 
     1942        (int)$headers->size, 
     1943        serialize($headers), 
     1944        (is_object($struct) ? serialize($struct) : null)); 
    19461945    } 
    19471946 
     
    19921991 
    19931992            if ($name && $address && $name != $address) { 
    1994                 $string = sprintf('%s <%s>', strpos($name, ',')!==FALSE ? '"'.$name.'"' : $name, $address); 
     1993                $string = sprintf('%s <%s>', strpos($name, ',') !== false ? '"'.$name.'"' : $name, $address); 
    19951994            } else if ($address) { 
    19961995                $string = $address; 
     
    20082007    } 
    20092008 
    2010  
    2011     function decode_header($input, $remove_quotes=FALSE) 
    2012     { 
     2009    /** 
     2010     * Decode a message header value 
     2011     * 
     2012     * @param string  Header value 
     2013     * @param boolean Remove quotes if necessary 
     2014     * @return string Decoded string 
     2015     */ 
     2016    public function decode_header($input, $remove_quotes = false) { 
    20132017        $str = $this->decode_mime_string((string)$input); 
    2014         if ($str{0}=='"' && $remove_quotes) { 
     2018        if ($str{0} == '"' && $remove_quotes) { 
    20152019            $str = str_replace('"', '', $str); 
    20162020        } 
     
    20222026     * Decode a mime-encoded string to internal charset 
    20232027     * 
    2024      * @access static 
    2025      */ 
    2026     static function decode_mime_string($input, $fallback=null) 
    2027     { 
     2028     * @param string  Header value 
     2029     * @param string  Fallback charset if none specified 
     2030     * @return string Decoded string 
     2031     */ 
     2032    public static function decode_mime_string($input, $fallback = null) { 
    20282033        $out = ''; 
    20292034 
     
    20322037            $out = substr($input, 0, $pos); 
    20332038 
    2034             $end_cs_pos = strpos($input, "?", $pos+2); 
    2035             $end_en_pos = strpos($input, "?", $end_cs_pos+1); 
    2036             $end_pos = strpos($input, "?=", $end_en_pos+1); 
     2039            $end_cs_pos = strpos($input, '?', $pos+2); 
     2040            $end_en_pos = strpos($input, '?', $end_cs_pos+1); 
     2041            $end_pos = strpos($input, '?=', $end_en_pos+1); 
    20372042 
    20382043            $encstr = substr($input, $pos+2, ($end_pos-$pos-2)); 
    20392044            $rest = substr($input, $end_pos+2); 
    20402045 
    2041             $out .= rcube_imap::_decode_mime_string_part($encstr); 
    2042             $out .= rcube_imap::decode_mime_string($rest, $fallback); 
     2046            $out .= self::_decode_mime_string_part($encstr); 
     2047            $out .= self::decode_mime_string($rest, $fallback); 
    20432048 
    20442049            return $out; 
    20452050        } 
    2046  
    20472051        // no encoding information, use fallback 
    20482052        return rcube::charset_convert($input, !empty($fallback) ? $fallback : 'ISO-8859-1'); 
     
    20522056    /** 
    20532057     * Decode a part of a mime-encoded string 
    2054      * 
    2055      * @access static 
    2056      */ 
    2057     static function _decode_mime_string_part($str) 
    2058     { 
     2058     */ 
     2059    private static function _decode_mime_string_part($str) { 
    20592060        $a = explode('?', $str); 
    20602061        $count = count($a); 
     
    20622063        // should be in format "charset?encoding?base64_string" 
    20632064        if ($count >= 3) { 
    2064             for ($i=2; $i<$count; $i++) { 
    2065                 $rest.=$a[$i]; 
    2066             } 
    2067  
    2068             if (($a[1]=="B")||($a[1]=="b")) { 
     2065            for ($i = 2; $i < $count; $i++) { 
     2066                $rest .= $a[$i]; 
     2067            } 
     2068 
     2069            if (($a[1] == 'B') || ($a[1] == 'b')) { 
    20692070                $rest = base64_decode($rest); 
    2070             } 
    2071             else if (($a[1]=="Q")||($a[1]=="q")) { 
    2072                 $rest = str_replace("_", " ", $rest); 
     2071            } else if (($a[1] == 'Q') || ($a[1] == 'q')) { 
     2072                $rest = str_replace('_', ' ', $rest); 
    20732073                $rest = quoted_printable_decode($rest); 
    20742074            } 
     
    20792079    } 
    20802080 
    2081     function mime_decode($input, $encoding='7bit') 
    2082     { 
     2081    /** 
     2082     * Decode a mime part 
     2083     * 
     2084     * @param string Input string 
     2085     * @param string Part encoding 
     2086     * @return string Decoded string 
     2087     */ 
     2088    private function mime_decode($input, $encoding = '7bit') { 
    20832089        switch (strtolower($encoding)) { 
    20842090            case '7bit': 
    20852091                return $input; 
    2086                 break; 
    2087  
    20882092            case 'quoted-printable': 
    20892093                return quoted_printable_decode($input); 
    2090                 break; 
    2091  
    20922094            case 'base64': 
    20932095                return base64_decode($input); 
    2094                 break; 
    2095  
    20962096            default: 
    20972097                return $input; 
     
    20992099    } 
    21002100 
    2101     function mime_encode($input, $encoding='7bit') 
    2102     { 
    2103         switch ($encoding) { 
    2104             case 'quoted-printable': 
    2105                 return quoted_printable_encode($input); 
    2106                 break; 
    2107  
    2108             case 'base64': 
    2109                 return base64_encode($input); 
    2110                 break; 
    2111  
    2112             default: 
    2113                 return $input; 
    2114         } 
    2115     } 
    2116  
    2117  
    2118     // convert body chars according to the ctype_parameters 
    2119     function charset_decode($body, $ctype_param) 
    2120     { 
     2101    /** 
     2102     * Convert body charset to UTF-8 according to the ctype_parameters 
     2103     * 
     2104     * @param string Part body to decode 
     2105     * @param string Charset to convert from 
     2106     * @return string Content converted to internal charset 
     2107     */ 
     2108    function charset_decode($body, $ctype_param) { 
    21212109        if (is_array($ctype_param) && !empty($ctype_param['charset'])) { 
    21222110            return rcube::charset_convert($body, $ctype_param['charset']); 
     
    21262114        return rcube::charset_convert($body,  'ISO-8859-1'); 
    21272115    } 
    2128  
    21292116 
    21302117    /* -------------------------------- 
     
    21322119     * --------------------------------*/ 
    21332120 
     2121    /** 
     2122     * Translate UID to message ID 
     2123     * 
     2124     * @param int    Message UID 
     2125     * @param string Mailbox name 
     2126     * @return int   Message ID 
     2127     */ 
     2128    public function get_id($uid, $mbox_name = null) { 
     2129        return $this->_uid2id($uid, ($mbox_name ? $this->_mod_mailbox($mbox_name) : $this->mailbox)); 
     2130    } 
     2131 
     2132    /** 
     2133     * Validate the given input and save to local properties 
     2134     */ 
     2135    private function _set_sort_order($sort_field = null, $sort_order = null) { 
     2136        if ($sort_field != null) { 
     2137            $this->sort_field = asciiwords($sort_field); 
     2138        } 
     2139        if ($sort_order != null) { 
     2140            $this->sort_order = strtoupper($sort_order) == 'DESC' ? 'DESC' : 'ASC'; 
     2141        } 
     2142    } 
     2143 
     2144    /** 
     2145     * Translate message number to UID 
     2146     * 
     2147     * @param int    Message ID 
     2148     * @param string Mailbox name 
     2149     * @return int   Message UID 
     2150     */ 
     2151    public function get_uid($id, $mbox_name = null) { 
     2152        return $this->_id2uid($id, ($mbox_name ? $this->_mod_mailbox($mbox_name) : $this->mailbox)); 
     2153    } 
    21342154 
    21352155    /** 
    21362156     * _mod_mailbox 
    21372157     * 
    2138      * @access private 
    21392158     * @param  string  $mbox_name 
    21402159     * @param  string  $mode 
    21412160     * @return string  $mbox_name 
    21422161     */ 
    2143     private function _mod_mailbox($mbox_name, $mode='in') 
    2144     { 
     2162    private function _mod_mailbox($mbox_name, $mode = 'in') { 
    21452163        if ((!empty($this->root_ns) && $this->root_ns == $mbox_name) || $mbox_name == 'INBOX') { 
    21462164            return $mbox_name; 
     
    21492167        if (!empty($this->root_dir) && $mode=='in') { 
    21502168            $mbox_name = $this->root_dir.$this->delimiter.$mbox_name; 
    2151         } 
    2152         else if (strlen($this->root_dir) && $mode=='out') { 
     2169        } else if (strlen($this->root_dir) && $mode=='out') { 
    21532170            $mbox_name = substr($mbox_name, strlen($this->root_dir)+1); 
    21542171        } 
     
    21572174 
    21582175    /** 
    2159      * sort mailboxes first by default folders and then in alphabethical order 
    2160      */ 
    2161     function _sort_mailbox_list($a_folders) 
    2162     { 
     2176     * Sort mailboxes first by default folders and then in alphabethical order 
     2177     * @access private 
     2178     */ 
     2179    private function _sort_mailbox_list($a_folders) { 
    21632180        $a_out = $a_defaults = array(); 
    21642181 
     
    21692186            } 
    21702187 
    2171             if (($p = array_search(strtolower($folder), $this->default_folders_lc))!==FALSE) { 
     2188            if (($p = array_search(strtolower($folder), $this->default_folders_lc)) !== false && !$a_defaults[$p]) { 
    21722189                $a_defaults[$p] = $folder; 
    2173             } 
    2174             else { 
     2190            } else { 
    21752191                $a_out[] = $folder; 
    21762192            } 
    21772193        } 
    21782194 
    2179         sort($a_out); 
     2195        natcasesort($a_out); 
    21802196        ksort($a_defaults); 
    21812197 
     
    21832199    } 
    21842200 
    2185     function get_id($uid, $mbox_name=NULL) 
    2186     { 
    2187         $mailbox = $mbox_name ? $this->_mod_mailbox($mbox_name) : $this->mailbox; 
    2188         return $this->_uid2id($uid, $mailbox); 
    2189     } 
    2190  
    2191     function get_uid($id,$mbox_name=NULL) 
    2192     { 
    2193         $mailbox = $mbox_name ? $this->_mod_mailbox($mbox_name) : $this->mailbox; 
    2194         return $this->_id2uid($id, $mailbox); 
    2195     } 
    2196  
    2197     function _uid2id($uid, $mbox_name=NULL) 
    2198     { 
     2201    private function _uid2id($uid, $mbox_name = null) { 
    21992202        if (!$mbox_name) { 
    22002203            $mbox_name = $this->mailbox; 
     
    22072210    } 
    22082211 
    2209     function _id2uid($id, $mbox_name=NULL) 
    2210     { 
     2212    private function _id2uid($id, $mbox_name = null) { 
    22112213        if (!$mbox_name) { 
    22122214            $mbox_name = $this->mailbox; 
    22132215        } 
    2214         return iil_C_ID2UID($this->conn, $mbox_name, $id); 
    2215     } 
    2216  
    2217  
    2218     // parse string or array of server capabilities and put them in internal array 
    2219     function _parse_capability($caps) 
    2220     { 
    2221         if (!is_array($caps)) 
    2222         $cap_arr = explode(' ', $caps); 
    2223         else 
    2224         $cap_arr = $caps; 
    2225  
    2226         foreach ($cap_arr as $cap) 
    2227         { 
    2228             if ($cap=='CAPABILITY') 
    2229             continue; 
    2230  
    2231             if (strpos($cap, '=')>0) 
    2232             { 
     2216        $index = array_flip((array)$this->uid_id_map[$mbox_name]); 
     2217        if (isset($index[$id])) { 
     2218            $uid = $index[$id]; 
     2219        } else { 
     2220            $uid = iil_C_ID2UID($this->conn, $mbox_name, $id); 
     2221            $this->uid_id_map[$mbox_name][$uid] = $id; 
     2222        } 
     2223 
     2224        return $uid; 
     2225    } 
     2226 
     2227    /** 
     2228     * Parse string or array of server capabilities and put them in internal array 
     2229     */ 
     2230    private function _parse_capability($caps) { 
     2231        if (!is_array($caps)) { 
     2232            $cap_arr = explode(' ', $caps); 
     2233        } else { 
     2234            $cap_arr = $caps; 
     2235        } 
     2236 
     2237        foreach ($cap_arr as $cap) { 
     2238            if ($cap == 'CAPABILITY') { 
     2239                continue; 
     2240            } 
     2241 
     2242            if (strpos($cap, '=') > 0) { 
    22332243                list($key, $value) = explode('=', $cap); 
    2234                 if (!is_array($this->capabilities[$key])) 
    2235                 $this->capabilities[$key] = array(); 
    2236  
     2244                if (!is_array($this->capabilities[$key])) { 
     2245                    $this->capabilities[$key] = array(); 
     2246                } 
    22372247                $this->capabilities[$key][] = $value; 
    2238             } 
    2239             else 
    2240             $this->capabilities[$cap] = TRUE; 
    2241         } 
    2242     } 
    2243  
    2244  
    2245     // subscribe/unsubscribe a list of mailboxes and update local cache 
    2246     function _change_subscription($a_mboxes, $mode) 
    2247     { 
    2248         $updated = FALSE; 
    2249  
    2250         if (is_array($a_mboxes)) 
    2251         foreach ($a_mboxes as $i => $mbox_name) 
    2252         { 
    2253             $mailbox = $this->_mod_mailbox($mbox_name); 
    2254             $a_mboxes[$i] = $mailbox; 
    2255  
    2256             if ($mode=='subscribe') 
    2257             $result = iil_C_Subscribe($this->conn, $mailbox); 
    2258             else if ($mode=='unsubscribe') 
    2259             $result = iil_C_UnSubscribe($this->conn, $mailbox); 
    2260  
    2261             if ($result>=0) 
    2262             $updated = TRUE; 
     2248            } else { 
     2249                $this->capabilities[$cap] = true; 
     2250            } 
     2251        } 
     2252    } 
     2253 
     2254    /** 
     2255     * Subscribe/unsubscribe a list of mailboxes and update local cache 
     2256     */ 
     2257    private function _change_subscription($a_mboxes, $mode) { 
     2258        $updated = false; 
     2259 
     2260        if (is_array($a_mboxes)) { 
     2261            foreach ($a_mboxes as $i => $mbox_name) { 
     2262                $mailbox = $this->_mod_mailbox($mbox_name); 
     2263                $a_mboxes[$i] = $mailbox; 
     2264     
     2265                if ($mode == 'subscribe') { 
     2266                    $result = iil_C_Subscribe($this->conn, $mailbox); 
     2267                } else if ($mode == 'unsubscribe') { 
     2268                    $result = iil_C_UnSubscribe($this->conn, $mailbox); 
     2269                } 
     2270     
     2271                if ($result >= 0) { 
     2272                    $updated = true; 
     2273                } 
     2274            } 
    22632275        } 
    22642276 
    22652277        // get cached mailbox list 
    2266         if ($updated) 
    2267         { 
     2278        if ($updated) { 
    22682279            $a_mailbox_cache = $this->get_cache('mailboxes'); 
    2269             if (!is_array($a_mailbox_cache)) 
    2270             return $updated; 
     2280            if (!is_array($a_mailbox_cache)) { 
     2281                return $updated; 
     2282            } 
    22712283 
    22722284            // modify cached list 
    2273             if ($mode=='subscribe') 
    2274             $a_mailbox_cache = array_merge($a_mailbox_cache, $a_mboxes); 
    2275             else if ($mode=='unsubscribe') 
    2276             $a_mailbox_cache = array_diff($a_mailbox_cache, $a_mboxes); 
     2285            if ($mode == 'subscribe') { 
     2286                $a_mailbox_cache = array_merge($a_mailbox_cache, $a_mboxes); 
     2287            } else if ($mode == 'unsubscribe') { 
     2288                $a_mailbox_cache = array_diff($a_mailbox_cache, $a_mboxes); 
     2289            } 
    22772290 
    22782291            // write mailboxlist to cache 
    22792292            $this->update_cache('mailboxes', $this->_sort_mailbox_list($a_mailbox_cache)); 
    22802293        } 
    2281  
    22822294        return $updated; 
    22832295    } 
    22842296 
    22852297 
    2286     // increde/decrese messagecount for a specific mailbox 
    2287     function _set_messagecount($mbox_name, $mode, $increment) 
    2288     { 
    2289         $a_mailbox_cache = FALSE; 
     2298    /** 
     2299     * Increde/decrese messagecount for a specific mailbox 
     2300     */ 
     2301    private function _set_messagecount($mbox_name, $mode, $increment) { 
     2302        $a_mailbox_cache = false; 
    22902303        $mailbox = $mbox_name ? $mbox_name : $this->mailbox; 
    22912304        $mode = strtoupper($mode); 
     
    22932306        $a_mailbox_cache = $this->get_cache('messagecount'); 
    22942307 
    2295         if (!is_array($a_mailbox_cache[$mailbox]) || !isset($a_mailbox_cache[$mailbox][$mode]) || !is_numeric($increment)) 
    2296         return FALSE; 
     2308        if (!is_array($a_mailbox_cache[$mailbox]) || !isset($a_mailbox_cache[$mailbox][$mode]) || !is_numeric($increment)) { 
     2309            return false; 
     2310        } 
    22972311 
    22982312        // add incremental value to messagecount 
    22992313        $a_mailbox_cache[$mailbox][$mode] += $increment; 
    2300  
    23012314        // there's something wrong, delete from cache 
    2302         if ($a_mailbox_cache[$mailbox][$mode] < 0) 
    2303         unset($a_mailbox_cache[$mailbox][$mode]); 
    2304  
     2315        if ($a_mailbox_cache[$mailbox][$mode] < 0) { 
     2316            unset($a_mailbox_cache[$mailbox][$mode]); 
     2317        } 
    23052318        // write back to cache 
    23062319        $this->update_cache('messagecount', $a_mailbox_cache); 
    2307  
    2308         return TRUE; 
    2309     } 
    2310  
    2311  
    2312     // remove messagecount of a specific mailbox from cache 
    2313     function _clear_messagecount($mbox_name='') 
    2314     { 
    2315         $a_mailbox_cache = FALSE; 
     2320        return true; 
     2321    } 
     2322 
     2323    /** 
     2324     * Remove messagecount of a specific mailbox from cache 
     2325     */ 
     2326    function _clear_messagecount($mbox_name = '') { 
     2327        $a_mailbox_cache = false; 
    23162328        $mailbox = $mbox_name ? $mbox_name : $this->mailbox; 
    23172329 
    23182330        $a_mailbox_cache = $this->get_cache('messagecount'); 
    23192331 
    2320         if (is_array($a_mailbox_cache[$mailbox])) 
    2321         { 
     2332        if (is_array($a_mailbox_cache[$mailbox])) { 
    23222333            unset($a_mailbox_cache[$mailbox]); 
    23232334            $this->update_cache('messagecount', $a_mailbox_cache); 
     
    23252336    } 
    23262337 
    2327  
    2328     // split RFC822 header string into an associative array 
    2329     function _parse_headers($headers) 
    2330     { 
     2338    /** 
     2339     * Split RFC822 header string into an associative array 
     2340     */ 
     2341    private function _parse_headers($headers) { 
    23312342        $a_headers = array(); 
    23322343        $lines = explode("\n", $headers); 
    2333         $c = count($lines); 
    2334         for ($i=0; $i<$c; $i++) 
    2335         { 
    2336             if ($p = strpos($lines[$i], ': ')) 
    2337             { 
     2344 
     2345        for ($i = 0, $c = count($lines); $i < $c; $i++) { 
     2346            if ($p = strpos($lines[$i], ': ')) { 
    23382347                $field = strtolower(substr($lines[$i], 0, $p)); 
    23392348                $value = trim(substr($lines[$i], $p+1)); 
    2340                 if (!empty($value)) 
    2341                 $a_headers[$field] = $value; 
    2342             } 
    2343         } 
    2344  
     2349                if (!empty($value)) { 
     2350                    $a_headers[$field] = $value; 
     2351                } 
     2352            } 
     2353        } 
    23452354        return $a_headers; 
    23462355    } 
    23472356 
    23482357 
    2349     function _parse_address_list($str, $decode=true) 
    2350     { 
     2358    private function _parse_address_list($str, $decode = true) { 
    23512359        // remove any newlines and carriage returns before 
    2352         $a = $this->_explode_quoted_string('[,;]', preg_replace( "/[\r\n]/", " ", $str)); 
     2360        $a = explode_quoted_string('[,;]', preg_replace( "/[\r\n]/", " ", $str)); 
    23532361        $result = array(); 
    23542362 
    2355         foreach ($a as $key => $val) 
    2356         { 
     2363        foreach ($a as $key => $val) { 
    23572364            $val = preg_replace("/([\"\w])</", "$1 <", $val); 
    2358             $sub_a = $this->_explode_quoted_string(' ', $decode ? $this->decode_header($val) : $val); 
     2365            $sub_a = explode_quoted_string(' ', $decode ? $this->decode_header($val) : $val); 
    23592366            $result[$key]['name'] = ''; 
    23602367 
    2361             foreach ($sub_a as $k => $v) 
    2362             { 
    2363                 if (strpos($v, '@') > 0) 
    2364                 $result[$key]['address'] = str_replace('<', '', str_replace('>', '', $v)); 
    2365                 else 
    2366                 $result[$key]['name'] .= (empty($result[$key]['name'])?'':' ').str_replace("\"",'',stripslashes($v)); 
    2367             } 
    2368  
    2369             if (empty($result[$key]['name'])) 
    2370             $result[$key]['name'] = $result[$key]['address']; 
    2371         } 
    2372  
    2373         return $result; 
    2374     } 
    2375  
    2376  
    2377     function _explode_quoted_string($delimiter, $string) 
    2378     { 
    2379         $result = array(); 
    2380         $strlen = strlen($string); 
    2381         for ($q=$p=$i=0; $i < $strlen; $i++) 
    2382         { 
    2383             if ($string{$i} == "\"" && $string{$i-1} != "\\") 
    2384             $q = $q ? false : true; 
    2385             else if (!$q && preg_match("/$delimiter/", $string{$i})) 
    2386             { 
    2387                 $result[] = substr($string, $p, $i - $p); 
    2388                 $p = $i + 1; 
    2389             } 
    2390         } 
    2391  
    2392         $result[] = substr($string, $p); 
     2368            foreach ($sub_a as $k => $v) { 
     2369                if (strpos($v, '@') > 0) { 
     2370                    $result[$key]['address'] = str_replace('<', '', str_replace('>', '', $v)); 
     2371                } else { 
     2372                    $result[$key]['name'] .= (empty($result[$key]['name'])?'':' ').str_replace("\"",'',stripslashes($v)); 
     2373                } 
     2374            } 
     2375 
     2376            if (empty($result[$key]['name'])) { 
     2377                $result[$key]['name'] = $result[$key]['address']; 
     2378            } 
     2379        } 
    23932380        return $result; 
    23942381    } 
     
    23992386 * Add quoted-printable encoding to a given string 
    24002387 * 
    2401  * @param string  $input      string to encode 
    2402  * @param int     $line_max   add new line after this number of characters 
    2403  * @param boolena $space_conf true if spaces should be converted into =20 
    2404  * @return encoded string 
     2388 * @param string   String to encode 
     2389 * @param int      Add new line after this number of characters 
     2390 * @param boolean  True if spaces should be converted into =20 
     2391 * @return string Encoded string 
    24052392 */ 
    2406 function quoted_printable_encode($input, $line_max=76, $space_conv=false) 
    2407 { 
     2393function quoted_printable_encode($input, $line_max = 76, $space_conv = false) { 
    24082394    $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); 
    24092395    $lines = preg_split("/(?:\r\n|\r|\n)/", $input); 
    24102396    $eol = "\r\n"; 
    2411     $escape = "="; 
    2412     $output = ""; 
    2413  
    2414     while( list(, $line) = each($lines)) { 
     2397    $escape = '='; 
     2398    $output = ''; 
     2399 
     2400    while (list(, $line) = each($lines)) { 
    24152401        //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary 
    24162402        $linlen = strlen($line); 
    2417         $newline = ""; 
    2418         for($i = 0; $i < $linlen; $i++) { 
     2403        $newline = ''; 
     2404        for ($i = 0; $i < $linlen; $i++) { 
    24192405            $c = substr( $line, $i, 1 ); 
    24202406            $dec = ord( $c ); 
    24212407            if ( ( $i == 0 ) && ( $dec == 46 ) ) { 
    24222408                // convert first point in the line into =2E 
    2423                 $c = "=2E"; 
    2424             } 
    2425             if ( $dec == 32 ) 
    2426             { 
    2427                 if ( $i == ( $linlen - 1 ) ) // convert space at eol only 
    2428                 { 
    2429                     $c = "=20"; 
    2430                 } 
    2431                 else if ( $space_conv ) 
    2432                 { 
    2433                     $c = "=20"; 
    2434                 } 
    2435             } 
    2436             else if ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) )  // always encode "\t", which is *not* required 
    2437             { 
     2409                $c = '=2E'; 
     2410            } 
     2411            if ( $dec == 32 ) { 
     2412                // convert space at eol only 
     2413                if ( $i == ( $linlen - 1 ) || $space_conv) { 
     2414                    $c = '=20'; 
     2415                } 
     2416            } else if ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { 
     2417                // always encode "\t", which is *not* required 
    24382418                $h2 = floor($dec/16); 
    24392419                $h1 = floor($dec%16); 
    2440                 $c = $escape.$hex["$h2"].$hex["$h1"]; 
    2441             } 
    2442  
    2443             if ( (strlen($newline) + strlen($c)) >= $line_max )  // CRLF is not counted 
    2444             { 
    2445                 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay 
    2446                 $newline = ""; 
     2420                $c = $escape.$hex[$h2].$hex[$h1]; 
     2421            } 
     2422 
     2423            // CRLF is not counted 
     2424            if ( (strlen($newline) + strlen($c)) >= $line_max ) { 
     2425                // soft line break; " =\r\n" is okay 
     2426                $output .= $newline.$escape.$eol; 
     2427                $newline = ''; 
    24472428                // check if newline first character will be point or not 
    24482429                if ( $dec == 46 ) { 
    2449                     $c = "=2E"; 
     2430                    $c = '=2E'; 
    24502431                } 
    24512432            } 
     
    24572438    return trim($output); 
    24582439} 
     2440 
     2441?> 
  • branches/devel-vnext/program/include/rcube_mail_mime.php

    r806 r1018  
    1818 $Id: sendmail.inc 506 2007-03-14 00:39:51Z thomasb $ 
    1919 
    20 */ 
     20 */ 
    2121 
    2222 
     
    2626 * @package Mail 
    2727 */ 
    28 class rcube_mail_mime extends Mail_mime 
    29 { 
    30    
    31   /** 
    32    * Adds an image to the list of embedded images. 
    33    * 
    34    * @param  string  $file       The image file name OR image data itself 
    35    * @param  string  $c_type     The content type 
    36    * @param  string  $name       The filename of the image. 
    37    *                             Only use if $file is the image data 
    38    * @param  bool    $isfilename Whether $file is a filename or not 
    39    *                             Defaults to true 
    40    * @param  string  $contentid  Desired Content-ID of MIME part 
    41    *                             Defaults to generated unique ID 
    42    * @return mixed   true on success or PEAR_Error object 
    43    * @access public 
    44    */ 
    45   function addHTMLImage($file, $c_type='application/octet-stream', $name = '', $isfilename = true, $contentid = '') 
    46   { 
    47     $filedata = ($isfilename === true) ? $this->_file2str($file) : $file; 
    48     if ($isfilename === true) 
    49       $filename = ($name == '' ? $file : $name); 
    50     else 
    51       $filename = $name; 
     28class rcube_mail_mime extends Mail_mime { 
    5229 
    53     if (PEAR::isError($filedata)) 
    54         return $filedata; 
     30    /** 
     31     * Set build parameters 
     32     */ 
     33    public function setParam($param = array()) { 
     34        if (is_array($param)) { 
     35            $this->_build_params = array_merge($this->_build_params, $param); 
     36        } 
     37    } 
    5538 
    56     if ($contentid == '') 
    57        $contentid = md5(uniqid(time())); 
    58  
    59     $this->_html_images[] = array( 
    60       'body'   => $filedata, 
    61       'name'   => $filename, 
    62       'c_type' => $c_type, 
    63       'cid'    => $contentid 
    64     ); 
    65  
    66     return true; 
    67   } 
    68  
    69    
    70   /** 
    71   * returns the HTML body portion of the message 
    72   * @return string HTML body of the message 
    73   * @access public 
    74   */ 
    75   function getHTMLBody() 
    76   { 
    77      return $this->_htmlbody; 
    78   } 
    79    
    80    
    81   /** 
    82    * Encodes a header as per RFC2047 
    83    * 
    84    * @param  array $input The header data to encode 
    85    * @param  array $params Extra build parameters 
    86    * @return array Encoded data 
    87    * @access private 
    88    * @override 
    89    */ 
    90   function _encodeHeaders($input, $params = array()) 
    91   { 
    92     $maxlen = 73; 
    93     $params += $this->_build_params; 
    94      
    95     foreach ($input as $hdr_name => $hdr_value) 
    96     { 
    97       // if header contains e-mail addresses 
    98       if (preg_match('/\s<.+@[a-z0-9\-\.]+\.[a-z]+>/U', $hdr_value)) 
    99         $chunks = $this->_explode_quoted_string(',', $hdr_value); 
    100       else 
    101         $chunks = array($hdr_value); 
    102  
    103       $hdr_value = ''; 
    104       $line_len = 0; 
    105  
    106       foreach ($chunks as $i => $value) 
    107       { 
    108         $value = trim($value); 
    109  
    110         //This header contains non ASCII chars and should be encoded. 
    111         if (preg_match('#[\x80-\xFF]{1}#', $value)) 
    112         { 
    113           $suffix = ''; 
    114           // Don't encode e-mail address 
    115           if (preg_match('/(.+)\s(<.+@[a-z0-9\-\.]+>)$/Ui', $value, $matches)) 
    116           { 
    117             $value = $matches[1]; 
    118             $suffix = ' '.$matches[2]; 
    119           } 
    120  
    121           switch ($params['head_encoding']) 
    122           { 
    123             case 'base64': 
    124             // Base64 encoding has been selected. 
    125             $mode = 'B'; 
    126             $encoded = base64_encode($value); 
    127             break; 
    128  
    129             case 'quoted-printable': 
    130             default: 
    131             // quoted-printable encoding has been selected 
    132             $mode = 'Q'; 
    133             $encoded = preg_replace('/([\x2C\x3F\x80-\xFF])/e', "'='.sprintf('%02X', ord('\\1'))", $value); 
    134             // replace spaces with _ 
    135             $encoded = str_replace(' ', '_', $encoded); 
    136           } 
    137  
    138           $value = '=?' . $params['head_charset'] . '?' . $mode . '?' . $encoded . '?=' . $suffix; 
     39    /** 
     40     * Adds an image to the list of embedded images. 
     41     * 
     42     * @param  string  $file       The image file name OR image data itself 
     43     * @param  string  $c_type     The content type 
     44     * @param  string  $name       The filename of the image. 
     45     *                             Only use if $file is the image data 
     46     * @param  bool    $isfilename Whether $file is a filename or not 
     47     *                             Defaults to true 
     48     * @param  string  $contentid  Desired Content-ID of MIME part 
     49     *                             Defaults to generated unique ID 
     50     * @return mixed   true on success or PEAR_Error object 
     51     */ 
     52    public function addHTMLImage($file, $c_type = 'application/octet-stream', $name = '', $isfilename = true, $contentid = '') { 
     53        $filedata = ($isfilename === true) ? $this->_file2str($file) : $file; 
     54        if ($isfilename === true) { 
     55            $filename = ($name == '' ? $file : $name); 
     56        } else { 
     57            $filename = $name; 
    13958        } 
    14059 
    141         // add chunk to output string by regarding the header maxlen 
    142         $len = strlen($value); 
    143         if ($line_len + $len < $maxlen) 
    144         { 
    145           $hdr_value .= ($i>0?', ':'') . $value; 
    146           $line_len += $len + ($i>0?2:0); 
     60        if (PEAR::isError($filedata)) { 
     61            return $filedata; 
    14762        } 
    148         else 
    149         { 
    150           $hdr_value .= ($i>0?', ':'') . "\n " . $value; 
    151           $line_len = $len; 
     63 
     64        if ($contentid == '') { 
     65            $contentid = md5(uniqid(time())); 
    15266        } 
    153       } 
    15467 
    155       $input[$hdr_name] = $hdr_value; 
     68        $this->_html_images[] = array('body' => $filedata, 'name' => $filename, 'c_type' => $c_type, 'cid' => $contentid); 
     69 
     70        return true; 
    15671    } 
    15772 
    158     return $input; 
    159   } 
     73    /** 
     74     * Creates a new mimePart object, using multipart/mixed as 
     75     * the initial content-type and returns it during the 
     76     * build process. 
     77     * 
     78     * @return object  The multipart/mixed mimePart object 
     79     */ 
     80    private function _addMixedPart() { 
     81        $params['content_type'] = $this->_headers['Content-Type'] ? $this->_headers['Content-Type'] : 'multipart/mixed'; 
     82        $ret = new Mail_mimePart('', $params); 
     83        return $ret; 
     84    } 
    16085 
     86    /** 
     87     * returns the HTML body portion of the message 
     88     * @return string HTML body of the message 
     89     */ 
     90    public function getHTMLBody() { 
     91        return $this->_htmlbody; 
     92    } 
    16193 
    162   function _explode_quoted_string($delimiter, $string) 
    163   { 
    164     $result = array(); 
    165     $strlen = strlen($string); 
    166     for ($q=$p=$i=0; $i < $strlen; $i++) 
    167     { 
    168       if ($string{$i} == "\"" && $string{$i-1} != "\\") 
    169         $q = $q ? false : true; 
    170       else if (!$q && $string{$i} == $delimiter) 
    171       { 
    172         $result[] = substr($string, $p, $i - $p); 
    173         $p = $i + 1; 
    174       } 
     94    /** 
     95     * Encodes a header as per RFC2047 
     96     * 
     97     * @param  array $input The header data to encode 
     98     * @param  array $params Extra build parameters 
     99     * @return array Encoded data 
     100     * @access private 
     101     * @override 
     102     */ 
     103    private function _encodeHeaders($input, $params = array()) { 
     104        $maxlen = 73; 
     105        $params += $this->_build_params; 
     106 
     107        foreach ($input as $hdr_name => $hdr_value) { 
     108            // if header contains e-mail addresses 
     109            if (preg_match('/\s<.+@[a-z0-9\-\.]+\.[a-z]+>/U', $hdr_value)) { 
     110                $chunks = explode_quoted_string(',', $hdr_value); 
     111            } else { 
     112                $chunks = array($hdr_value); 
     113            } 
     114 
     115            $hdr_value = ''; 
     116            $line_len = 0; 
     117 
     118            foreach ($chunks as $i => $value) { 
     119                $value = trim($value); 
     120 
     121                //This header contains non ASCII chars and should be encoded. 
     122                if (preg_match('#[\x80-\xFF]{1}#', $value)) { 
     123                    $suffix = ''; 
     124                    // Don't encode e-mail address 
     125                    if (preg_match('/(.+)\s(<.+@[a-z0-9\-\.]+>)$/Ui', $value, $matches)) { 
     126                        $value = $matches[1]; 
     127                        $suffix = ' '.$matches[2]; 
     128                    } 
     129 
     130                    switch ($params['head_encoding']) { 
     131                        case 'base64': 
     132                            // Base64 encoding has been selected. 
     133                            $mode = 'B'; 
     134                            $encoded = base64_encode($value); 
     135                            break; 
     136                        case 'quoted-printable': 
     137                        default: 
     138                            // quoted-printable encoding has been selected 
     139                            $mode = 'Q'; 
     140                            $encoded = preg_replace('/([\x2C\x3F\x80-\xFF])/e', "'='.sprintf('%02X', ord('\\1'))", $value); 
     141                            // replace spaces with _ 
     142                            $encoded = str_replace(' ', '_', $encoded); 
     143                    } 
     144 
     145                    $value = '=?' . $params['head_charset'] . '?' . $mode . '?' . $encoded . '?=' . $suffix; 
     146                } 
     147 
     148                // add chunk to output string by regarding the header maxlen 
     149                $len = strlen($value); 
     150                if ($i == 0 || $line_len + $len < $maxlen) { 
     151                    $hdr_value .= ($i>0?', ':'') . $value; 
     152                    $line_len += $len + ($i>0?2:0); 
     153                } else { 
     154                    $hdr_value .= ($i>0?', ':'') . "\n " . $value; 
     155                    $line_len = $len; 
     156                } 
     157            } 
     158            $input[$hdr_name] = $hdr_value; 
     159        } 
     160 
     161        return $input; 
    175162    } 
    176      
    177     $result[] = substr($string, $p); 
    178     return $result; 
    179   } 
    180  
    181163} 
    182164 
  • branches/devel-vnext/program/lib/imap.inc

    r995 r1018  
    127127        var $internaldate; 
    128128        var $references; 
     129        var $priority; 
    129130        var $mdn_to; 
    130131        var $mdn_sent = false; 
     
    162163        if ($fp) { 
    163164                do { 
     165                    // FIXME: hardcode size? 
    164166                        $buffer = fgets($fp, 2048); 
    165167                        if ($buffer === false) { 
    166168                                break; 
    167169            } 
    168                         $line.=$buffer; 
     170                        $line .= $buffer; 
    169171                } while ($buffer[strlen($buffer)-1]!="\n"); 
    170172        } 
     
    176178        if (ereg('\{[0-9]+\}$', $line)) { 
    177179                $out = ''; 
     180         
    178181                preg_match_all('/(.*)\{([0-9]+)\}$/', $line, $a); 
    179182                $bytes = $a[2][0]; 
    180                 while (strlen($out)<$bytes) { 
    181                         $out.=chop(iil_ReadLine($fp, 1024)); 
    182                 } 
    183                 $line = $a[1][0]."\"$out\""; 
     183                while (strlen($out) < $bytes) { 
     184                    $line = iil_ReadLine($fp, 1024);  
     185                        $out .= chop($line); 
     186                } 
     187                $line = $a[1][0] . "\"$out\""; 
    184188        } 
    185189        return $line; 
     
    15161520    $request .= "(DATE FROM TO SUBJECT REPLY-TO IN-REPLY-TO CC BCC "; 
    15171521    $request .= "CONTENT-TRANSFER-ENCODING CONTENT-TYPE MESSAGE-ID "; 
    1518     $request .= "REFERENCES DISPOSITION-NOTIFICATION-TO)])\r\n"; 
     1522    $request .= "REFERENCES DISPOSITION-NOTIFICATION-TO X-PRIORITY)])\r\n"; 
    15191523 
    15201524        if (!fputs($fp, $request)) { 
     
    16251629                                        case 'message-id': 
    16261630                                                $result[$id]->messageID = $string; 
     1631                                                break; 
     1632                                        case 'x-priority': 
     1633                                                if (preg_match('/^(\d+)/', $string, $matches)) 
     1634                                                        $result[$id]->priority = intval($matches[1]); 
    16271635                                                break; 
    16281636                                } // end switch () 
     
    25802588        return (iil_C_Expunge($conn, $folder) >= 0); 
    25812589} 
     2590 
     2591?> 
  • branches/devel-vnext/program/lib/mime.inc

    r589 r1018  
    11<?php 
    22///////////////////////////////////////////////////////// 
    3 //       
     3// 
    44//      Iloha MIME Library (IML) 
    55// 
    66//      (C)Copyright 2002 Ryo Chijiiwa <Ryo@IlohaMail.org> 
    77// 
    8 //      This file is part of IlohaMail. IlohaMail is free software released  
    9 //      under the GPL license.  See enclosed file COPYING for details, or  
     8//      This file is part of IlohaMail. IlohaMail is free software released 
     9//      under the GPL license.  See enclosed file COPYING for details, or 
    1010//      see http://www.fsf.org/copyleft/gpl.html 
    1111// 
     
    1414/******************************************************** 
    1515 
    16         FILE: include/mime.inc 
    17         PURPOSE: 
    18                 Provide functions for handling mime messages. 
    19         USAGE: 
    20                 Use iil_C_FetchStructureString to get IMAP structure stirng, then pass that through 
    21                 iml_GetRawStructureArray() to get root node to a nested data structure. 
    22                 Pass root node to the iml_GetPart*() functions to retreive individual bits of info. 
     16FILE: include/mime.inc 
     17PURPOSE: 
     18Provide functions for handling mime messages. 
     19USAGE: 
     20Use iil_C_FetchStructureString to get IMAP structure stirng, then pass that through 
     21iml_GetRawStructureArray() to get root node to a nested data structure. 
     22Pass root node to the iml_GetPart*() functions to retreive individual bits of info. 
    2323 
    2424********************************************************/ 
     
    3333$MIME_OTHER = 7; 
    3434 
    35 function iml_ClosingParenPos($str, $start){ 
    36     $level=0; 
     35function iml_ClosingParenPos($str, $start) { 
     36    $level = 0; 
    3737    $len = strlen($str); 
    3838    $in_quote = 0; 
    39     for ($i=$start;$i<$len;$i++){ 
    40         if ($str[$i]=="\"") $in_quote = ($in_quote + 1) % 2; 
    41         if (!$in_quote){ 
    42                 if ($str[$i]=="(") $level++; 
    43                 else if (($level > 0) && ($str[$i]==")")) $level--; 
    44                 else if (($level == 0) && ($str[$i]==")")) return $i; 
    45         } 
    46     } 
    47 } 
    48  
    49 function iml_ParseBSString($str){        
    50      
     39 
     40    for ($i = $start; $i < $len; $i++) { 
     41        if ($str[$i] == '"') { 
     42            $in_quote = ($in_quote + 1) % 2; 
     43        } 
     44        if (!$in_quote) { 
     45            if ($str[$i] == '(') { 
     46                $level++; 
     47            } else if (($level > 0) && ($str[$i] == ')')) { 
     48                $level--; 
     49            } else if (($level == 0) && ($str[$i] == ')')) { 
     50                return $i; 
     51            } 
     52        } 
     53    } 
     54} 
     55 
     56function iml_ParseBSString($str) { 
    5157    $id = 0; 
    5258    $a = array(); 
    5359    $len = strlen($str); 
    54      
    5560    $in_quote = 0; 
    56     for ($i=0; $i<$len; $i++){ 
    57         if ($str[$i] == "\"") $in_quote = ($in_quote + 1) % 2; 
    58         else if (!$in_quote){ 
    59             if ($str[$i] == " ") $id++; //space means new element 
    60             else if ($str[$i]=="("){ //new part 
     61 
     62    for ($i = 0; $i < $len; $i++) { 
     63        if ($str[$i] == '"') { 
     64            $in_quote = ($in_quote + 1) % 2; 
     65        } else if (!$in_quote) { 
     66            //space means new element 
     67            if ($str[$i] == " ") { 
     68                $id++; 
     69                // skip additional spaces 
     70                while ($str[$i+1] == ' ') { 
     71                    $i++;   
     72                } 
     73            } else if ($str[$i] == '(') { 
     74                //new part 
    6175                $i++; 
    6276                $endPos = iml_ClosingParenPos($str, $i); 
    6377                $partLen = $endPos - $i; 
    6478                $part = substr($str, $i, $partLen); 
    65                 $a[$id] = iml_ParseBSString($part); //send part string 
    66                 if ($verbose){ 
    67                                         echo "{>".$endPos."}"; 
    68                                         flush(); 
    69                                 } 
     79                //send part string 
     80                $a[$id] = iml_ParseBSString($part); 
     81                if ($verbose) { 
     82                    echo '{>'.$endPos.'}'; 
     83                    flush(); 
     84                } 
    7085                $i = $endPos; 
    71             }else $a[$id].=$str[$i]; //add to current element in array 
    72         }else if ($in_quote){ 
    73             if ($str[$i]=="\\") $i++; //escape backslashes 
    74             else $a[$id].=$str[$i]; //add to current element in array 
    75         } 
    76     } 
    77          
     86            } else { 
     87                //add to current element in array 
     88                $a[$id].=$str[$i]; 
     89            } 
     90        } else if ($in_quote) { 
     91            //escape backslashes 
     92            if ($str[$i] == '\\') { 
     93                $i++;  
     94            } else { 
     95                //add to current element in array 
     96                $a[$id].=$str[$i]; 
     97            } 
     98        } 
     99    } 
    78100    reset($a); 
    79101    return $a; 
    80102} 
    81103 
    82 function iml_GetRawStructureArray($str){ 
    83     $line=substr($str, 1, strlen($str) - 2); 
    84     $line = str_replace(")(", ") (", $line); 
    85          
    86         $struct = iml_ParseBSString($line); 
    87         if ((strcasecmp($struct[0], "message")==0) && (strcasecmp($struct[1], "rfc822")==0)){ 
    88                 $struct = array($struct); 
    89         } 
     104function iml_GetRawStructureArray($str) { 
     105    $line = substr($str, 1, strlen($str) - 2); 
     106    $line = str_replace(')(', ') (', $line); 
     107 
     108    $struct = iml_ParseBSString($line); 
     109    if ((strcasecmp($struct[0], 'message') == 0) && (strcasecmp($struct[1], 'rfc822') == 0)) { 
     110        $struct = array($struct); 
     111    } 
    90112    return $struct; 
    91113} 
    92114 
    93 function iml_GetPartArray($a, $part){ 
    94         if (!is_array($a)) return false; 
    95         if (strpos($part, ".") > 0){ 
    96                 $original_part = $part; 
    97                 $pos = strpos($part, "."); 
    98                 $rest = substr($original_part, $pos+1); 
    99                 $part = substr($original_part, 0, $pos); 
    100                 if ((strcasecmp($a[0], "message")==0) && (strcasecmp($a[1], "rfc822")==0)){ 
    101                         $a = $a[8]; 
    102                 } 
    103                 //echo "m - part: $original_part current: $part rest: $rest array: ".implode(" ", $a)."<br>\n"; 
    104                 return iml_GetPartArray($a[$part-1], $rest); 
    105         }else if ($part>0){ 
    106                 if ((strcasecmp($a[0], "message")==0) && (strcasecmp($a[1], "rfc822")==0)){ 
    107                         $a = $a[8]; 
    108                 } 
    109                 //echo "s - part: $part rest: $rest array: ".implode(" ", $a)."<br>\n"; 
    110                 if (is_array($a[$part-1])) return $a[$part-1]; 
    111                 else return $a; 
    112         }else if (($part==0) || (empty($part))){ 
    113                 return $a; 
    114         } 
    115 } 
    116  
    117 function iml_GetNumParts($a, $part){ 
    118         if (is_array($a)){ 
    119                 $parent=iml_GetPartArray($a, $part); 
    120                  
    121                 if ((strcasecmp($parent[0], "message")==0) && (strcasecmp($parent[1], "rfc822")==0)){ 
    122                         $parent = $parent[8]; 
    123                 } 
    124  
    125                 $is_array=true; 
    126                 $c=0; 
    127                 while (( list ($key, $val) = each ($parent) )&&($is_array)){ 
    128                         $is_array=is_array($parent[$key]); 
    129                         if ($is_array) $c++; 
    130                 } 
    131                 return $c; 
    132         } 
    133          
    134         return false; 
    135 } 
    136  
    137 function iml_GetPartTypeString($a, $part){ 
    138         $part_a=iml_GetPartArray($a, $part); 
    139         if ($part_a){ 
    140                 if (is_array($part_a[0])){ 
    141                         $type_str = "MULTIPART/"; 
    142                         reset($part_a); 
    143                         while(list($n,$element)=each($part_a)){ 
    144                                 if (!is_array($part_a[$n])){ 
    145                                         $type_str.=$part_a[$n]; 
    146                                         break; 
    147                                 } 
    148                         } 
    149                         return $type_str; 
    150                 }else return $part_a[0]."/".$part_a[1]; 
    151         }else return false; 
    152 } 
    153  
    154 function iml_GetFirstTextPart($structure,$part){ 
    155     if ($part==0) $part=""; 
     115function iml_GetPartArray($a, $part) { 
     116    if (!is_array($a)) { 
     117        return false; 
     118    } 
     119    if (strpos($part, '.') > 0) { 
     120        $original_part = $part; 
     121        $pos = strpos($part, '.'); 
     122        $rest = substr($original_part, $pos+1); 
     123        $part = substr($original_part, 0, $pos); 
     124        if ((strcasecmp($a[0], 'message') == 0) && (strcasecmp($a[1], 'rfc822') == 0)) { 
     125            $a = $a[8]; 
     126        } 
     127        //echo "m - part: $original_part current: $part rest: $rest array: ".implode(" ", $a)."<br>\n"; 
     128        return iml_GetPartArray($a[$part-1], $rest); 
     129    } else if ($part > 0) { 
     130        if ((strcasecmp($a[0], 'message') == 0) && (strcasecmp($a[1], 'rfc822') == 0)) { 
     131            $a = $a[8]; 
     132        } 
     133        //echo "s - part: $part rest: $rest array: ".implode(" ", $a)."<br>\n"; 
     134        if (is_array($a[$part-1])) { 
     135            return $a[$part-1]; 
     136        } else { 
     137            return $a; 
     138        } 
     139    } else if (($part == 0) || (empty($part))) { 
     140        return $a; 
     141    } 
     142} 
     143 
     144function iml_GetNumParts($a, $part) { 
     145    if (is_array($a)) { 
     146        $parent = iml_GetPartArray($a, $part); 
     147 
     148        if ((strcasecmp($parent[0], 'message') == 0) && (strcasecmp($parent[1], 'rfc822') == 0)) { 
     149            $parent = $parent[8]; 
     150        } 
     151 
     152        $is_array = true; 
     153        $c = 0; 
     154        while ((list($key, $val) = each($parent)) && ($is_array)) { 
     155            $is_array = is_array($parent[$key]); 
     156            if ($is_array) { 
     157                $c++; 
     158            } 
     159        } 
     160        return $c; 
     161    } 
     162    return false; 
     163} 
     164 
     165function iml_GetPartTypeString($a, $part) { 
     166    $part_a = iml_GetPartArray($a, $part); 
     167    if ($part_a) { 
     168        if (is_array($part_a[0])) { 
     169            $type_str = 'MULTIPART/'; 
     170            reset($part_a); 
     171            while(list($n,$element) = each($part_a)) { 
     172                if (!is_array($part_a[$n])) { 
     173                    $type_str .= $part_a[$n]; 
     174                    break; 
     175                } 
     176            } 
     177            return $type_str; 
     178        } else { 
     179            return $part_a[0].'/'.$part_a[1]; 
     180        } 
     181    } else { 
     182        return false; 
     183    } 
     184} 
     185 
     186function iml_GetFirstTextPart($structure, $part = 0) { 
     187    if ($part == 0) { 
     188        $part = ''; 
     189    } 
    156190    $typeCode = -1; 
    157     while ($typeCode!=0){ 
     191    while ($typeCode != 0) { 
    158192        $typeCode = iml_GetPartTypeCode($structure, $part); 
    159         if ($typeCode == 1){ 
    160             $part .= (empty($part)?"":".")."1"; 
    161         }else if ($typeCode > 0){ 
    162             $parts_a = explode(".", $part); 
     193        if ($typeCode == 1) { 
     194            $part .= (empty($part) ? '' : '.').'1'; 
     195        } else if ($typeCode > 0) { 
     196            $parts_a = explode('.', $part); 
    163197            $lastPart = count($parts_a) - 1; 
    164198            $parts_a[$lastPart] = (int)$parts_a[$lastPart] + 1; 
    165             $part = implode(".", $parts_a); 
    166         }else if ($typeCode == -1){ 
    167             return ""; 
    168         } 
    169     } 
    170      
     199            $part = implode('.', $parts_a); 
     200        } else if ($typeCode == -1) { 
     201            return ''; 
     202        } 
     203    } 
    171204    return $part; 
    172205} 
    173206 
    174 function iml_GetPartTypeCode($a, $part){ 
    175         $types=array(0=>"text",1=>"multipart",2=>"message",3=>"application",4=>"audio",5=>"image",6=>"video",7=>"other"); 
    176  
    177         $part_a=iml_GetPartArray($a, $part); 
    178         if ($part_a){ 
    179                 if (is_array($part_a[0])) $str="multipart"; 
    180                 else $str=$part_a[0]; 
    181  
    182                 $code=7; 
    183                 while ( list($key, $val) = each($types)) if (strcasecmp($val, $str)==0) $code=$key; 
    184                 return $code; 
    185         }else return -1; 
    186 } 
    187  
    188 function iml_GetPartEncodingCode($a, $part){ 
    189         $encodings=array("7BIT", "8BIT", "BINARY", "BASE64", "QUOTED-PRINTABLE", "OTHER"); 
    190  
    191         $part_a=iml_GetPartArray($a, $part); 
    192         if ($part_a){ 
    193                 if (is_array($part_a[0])) return -1; 
    194                 else $str=$part_a[5]; 
    195  
    196                 $code=5; 
    197                 while ( list($key, $val) = each($encodings)) if (strcasecmp($val, $str)==0) $code=$key; 
    198  
    199                 return $code; 
    200  
    201         }else return -1; 
    202 } 
    203  
    204 function iml_GetPartEncodingString($a, $part){ 
    205         $part_a=iml_GetPartArray($a, $part); 
    206         if ($part_a){ 
    207                 if (is_array($part_a[0])) return -1; 
    208                 else return $part_a[5]; 
    209         }else return -1; 
    210 } 
    211  
    212 function iml_GetPartSize($a, $part){ 
    213         $part_a=iml_GetPartArray($a, $part); 
    214         if ($part_a){ 
    215                 if (is_array($part_a[0])) return -1; 
    216                 else return $part_a[6]; 
    217         }else return -1; 
    218 } 
    219  
    220 function iml_GetPartID($a, $part){ 
    221         $part_a=iml_GetPartArray($a, $part); 
    222         if ($part_a){ 
    223                 if (is_array($part_a[0])) return -1; 
    224                 else return $part_a[3]; 
    225         }else return -1; 
    226 } 
    227  
    228 function iml_GetPartDisposition($a, $part){ 
    229         $part_a=iml_GetPartArray($a, $part); 
    230         if ($part_a){ 
    231                 if (is_array($part_a[0])) return -1; 
    232                 else{ 
     207function iml_GetPartTypeCode($a, $part) { 
     208    $types = array(0 => 'text', 1 => 'multipart', 2 => 'message', 3 => 'application', 4 => 'audio', 5 => 'image', 6 => 'video', 7 => 'other'); 
     209 
     210    $part_a = iml_GetPartArray($a, $part); 
     211    if ($part_a) { 
     212        if (is_array($part_a[0])) { 
     213            $str = 'multipart'; 
     214        } else { 
     215            $str = $part_a[0]; 
     216        } 
     217 
     218        $code = 7; 
     219        while (list($key, $val) = each($types)) { 
     220            if (strcasecmp($val, $str) == 0) { 
     221                $code=$key; 
     222            } 
     223        } 
     224        return $code; 
     225    } else { 
     226        return -1; 
     227    } 
     228} 
     229 
     230function iml_GetPartEncodingCode($a, $part) { 
     231    $encodings = array('7BIT', '8BIT', 'BINARY', 'BASE64', 'QUOTED-PRINTABLE', 'OTHER'); 
     232 
     233    $part_a = iml_GetPartArray($a, $part); 
     234    if ($part_a) { 
     235        if (is_array($part_a[0])) { 
     236            return -1; 
     237        } else { 
     238            $str = $part_a[5]; 
     239        } 
     240 
     241        $code = 5; 
     242        while (list($key, $val) = each($encodings)) { 
     243            if (strcasecmp($val, $str)==0) { 
     244                $code = $key; 
     245            } 
     246        } 
     247        return $code; 
     248    } else { 
     249        return -1; 
     250    } 
     251} 
     252 
     253function iml_GetPartEncodingString($a, $part) { 
     254    $part_a = iml_GetPartArray($a, $part); 
     255    if ($part_a) { 
     256        if (is_array($part_a[0])) { 
     257            return -1; 
     258        } else { 
     259            return $part_a[5]; 
     260        } 
     261    } else { 
     262        return -1; 
     263    } 
     264} 
     265 
     266function iml_GetPartSize($a, $part) { 
     267    $part_a = iml_GetPartArray($a, $part); 
     268    if ($part_a) { 
     269        if (is_array($part_a[0])) { 
     270            return -1; 
     271        } else { 
     272            return $part_a[6]; 
     273        } 
     274    } else { 
     275        return -1; 
     276    } 
     277} 
     278 
     279function iml_GetPartID($a, $part) { 
     280    $part_a = iml_GetPartArray($a, $part); 
     281    if ($part_a) { 
     282        if (is_array($part_a[0])) { 
     283            return -1; 
     284        } else {  
     285            return $part_a[3]; 
     286        } 
     287    } else { 
     288        return -1; 
     289    } 
     290} 
     291 
     292function iml_GetPartDisposition($a, $part) { 
     293    $part_a = iml_GetPartArray($a, $part); 
     294    if ($part_a) { 
     295        if (is_array($part_a[0])) { 
     296            return -1; 
     297        } else { 
    233298            $id = count($part_a) - 2; 
    234                         if (is_array($part_a[$id])) return $part_a[$id][0]; 
    235                         else return ""; 
    236                 } 
    237         }else return ""; 
    238 } 
    239  
    240 function iml_GetPartName($a, $part){ 
    241         $part_a=iml_GetPartArray($a, $part); 
    242         if ($part_a){ 
    243                 if (is_array($part_a[0])) return -1; 
    244                 else{ 
    245             $name = ""; 
    246                         if (is_array($part_a[2])){ 
     299            if (is_array($part_a[$id])) { 
     300                return $part_a[$id][0]; 
     301            } else { 
     302                return ''; 
     303            } 
     304        } 
     305    } else { 
     306        return ''; 
     307    } 
     308} 
     309 
     310function iml_GetPartName($a, $part) { 
     311    $part_a = iml_GetPartArray($a, $part); 
     312    if ($part_a) { 
     313        if (is_array($part_a[0])) { 
     314            return -1; 
     315        } else { 
     316            $name = ''; 
     317            if (is_array($part_a[2])) { 
    247318                //first look in content type 
    248                                 $name=""; 
    249                                 while ( list($key, $val) = each ($part_a[2])){ 
    250                     if ((strcasecmp($val, "NAME")==0)||(strcasecmp($val, "FILENAME")==0))  
    251                         $name=$part_a[2][$key+1]; 
    252                 } 
    253                         } 
    254             if (empty($name)){ 
     319                $name = ''; 
     320                while (list($key, $val) = each($part_a[2])) { 
     321                    if ((strcasecmp($val, 'NAME') == 0) || (strcasecmp($val, 'FILENAME') == 0)) { 
     322                        $name = $part_a[2][$key+1]; 
     323                    } 
     324                } 
     325            } 
     326            if (empty($name)) { 
    255327                //check in content disposition 
    256328                $id = count($part_a) - 2; 
    257                 if ((is_array($part_a[$id])) && (is_array($part_a[$id][1]))){ 
     329                if ((is_array($part_a[$id])) && (is_array($part_a[$id][1]))) { 
    258330                    $array = $part_a[$id][1]; 
    259                     while ( list($key, $val) = each($array)){ 
    260                         if ((strcasecmp($val, "NAME")==0)||(strcasecmp($val, "FILENAME")==0))  
     331                    while ( list($key, $val) = each($array)) { 
     332                        if ((strcasecmp($val, 'NAME') == 0) || (strcasecmp($val, 'FILENAME') == 0)) { 
    261333                            $name=$array[$key+1]; 
     334                        } 
    262335                    } 
    263336                } 
    264337            } 
    265                         return $name; 
    266                 } 
    267         }else return ""; 
    268 } 
    269  
    270  
    271 function iml_GetPartCharset($a, $part){ 
    272         $part_a=iml_GetPartArray($a, $part); 
    273         if ($part_a){ 
    274                 if (is_array($part_a[0])) return -1; 
    275                 else{ 
    276                         if (is_array($part_a[2])){ 
    277                                 $name=""; 
    278                                 while ( list($key, $val) = each ($part_a[2])) if (strcasecmp($val, "charset")==0) $name=$part_a[2][$key+1]; 
    279                                 return $name; 
    280                         } 
    281                         else return ""; 
    282                 } 
    283         }else return ""; 
    284 } 
    285  
    286 function iml_GetPartList($a, $part){ 
    287         //echo "MOO?"; flush(); 
    288         $data = array(); 
    289         $num_parts = iml_GetNumParts($a, $part); 
    290         //echo "($num_parts)"; flush(); 
    291         if ($num_parts !== false){ 
    292                 //echo "<!-- ($num_parts parts)//-->\n"; 
    293                 for ($i = 0; $i<$num_parts; $i++){ 
    294                         $part_code = $part.(empty($part)?"":".").($i+1); 
    295                         $part_type = iml_GetPartTypeCode($a, $part_code); 
    296                         $part_disposition = iml_GetPartDisposition($a, $part_code); 
    297                         //echo "<!-- part: $part_code type: $part_type //-->\n"; 
    298                         if (strcasecmp($part_disposition, "attachment")!=0 &&  
    299                                 (($part_type == 1) || ($part_type==2))){ 
    300                                 $data = array_merge($data, iml_GetPartList($a, $part_code)); 
    301                         }else{ 
    302                                 $data[$part_code]["typestring"] = iml_GetPartTypeString($a, $part_code); 
    303                                 $data[$part_code]["disposition"] = $part_disposition; 
    304                                 $data[$part_code]["size"] = iml_GetPartSize($a, $part_code); 
    305                                 $data[$part_code]["name"] = iml_GetPartName($a, $part_code); 
    306                                 $data[$part_code]["id"] = iml_GetPartID($a, $part_code); 
    307                         } 
    308                 } 
    309         } 
    310         return $data; 
    311 } 
    312  
    313 function iml_GetNextPart($part){ 
    314         if (strpos($part, ".")===false) return $part++; 
    315         else{ 
    316                 $parts_a = explode(".", $part); 
    317                 $num_levels = count($parts_a); 
    318                 $parts_a[$num_levels-1]++; 
    319                 return implode(".", $parts_a); 
    320         } 
    321 } 
     338            return $name; 
     339        } 
     340    } else { 
     341        return ''; 
     342    } 
     343} 
     344 
     345 
     346function iml_GetPartCharset($a, $part) { 
     347    $part_a=iml_GetPartArray($a, $part); 
     348    if ($part_a) { 
     349        if (is_array($part_a[0])) { 
     350            return -1; 
     351        } else { 
     352            if (is_array($part_a[2])) { 
     353                $name = ''; 
     354                while (list($key, $val) = each($part_a[2])) { 
     355                    if (strcasecmp($val, 'charset') == 0) { 
     356                        $name = $part_a[2][$key+1]; 
     357                    } 
     358                } 
     359                return $name; 
     360            } else { 
     361                return ''; 
     362            } 
     363        } 
     364    } else { 
     365        return ''; 
     366    } 
     367} 
     368 
     369function iml_GetPartList($a, $part) { 
     370    //echo "MOO?"; flush(); 
     371    $data = array(); 
     372    $num_parts = iml_GetNumParts($a, $part); 
     373    //echo "($num_parts)"; flush(); 
     374    if ($num_parts !== false) { 
     375        //echo "<!-- ($num_parts parts)//-->\n"; 
     376        for ($i = 0; $i < $num_parts; $i++) { 
     377            $part_code = $part.(empty($part) ? '' : '.').($i+1); 
     378            $part_type = iml_GetPartTypeCode($a, $part_code); 
     379            $part_disposition = iml_GetPartDisposition($a, $part_code); 
     380            //echo "<!-- part: $part_code type: $part_type //-->\n"; 
     381            if (strcasecmp($part_disposition, 'attachment') != 0 && (($part_type == 1) || ($part_type == 2))) { 
     382                $data = array_merge($data, iml_GetPartList($a, $part_code)); 
     383            } else { 
     384                $data[$part_code]['typestring'] = iml_GetPartTypeString($a, $part_code); 
     385                $data[$part_code]['disposition'] = $part_disposition; 
     386                $data[$part_code]['size'] = iml_GetPartSize($a, $part_code); 
     387                $data[$part_code]['name'] = iml_GetPartName($a, $part_code); 
     388                $data[$part_code]['id'] = iml_GetPartID($a, $part_code); 
     389            } 
     390        } 
     391    } 
     392    return $data; 
     393} 
     394 
     395function iml_GetNextPart($part) { 
     396    if (strpos($part, '.') === false) { 
     397        return $part++; 
     398    } else { 
     399        $parts_a = explode('.', $part); 
     400        $num_levels = count($parts_a); 
     401        $parts_a[$num_levels-1]++; 
     402        return implode('.', $parts_a); 
     403    } 
     404} 
     405 
    322406?> 
Note: See TracChangeset for help on using the changeset viewer.