Changeset 1018 in subversion
- Timestamp:
- Feb 5, 2008 2:48:07 PM (5 years ago)
- Location:
- branches/devel-vnext/program
- Files:
-
- 8 edited
-
include/globals.php (modified) (18 diffs)
-
include/rcube/rcmail_compose.php (modified) (2 diffs)
-
include/rcube_header_sorter.php (modified) (4 diffs)
-
include/rcube_html_page.php (modified) (1 diff)
-
include/rcube_imap.php (modified) (21 diffs)
-
include/rcube_mail_mime.php (modified) (2 diffs)
-
lib/imap.inc (modified) (6 diffs)
-
lib/mime.inc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/devel-vnext/program/include/globals.php
r1015 r1018 33 33 * @see rcube::rep_specialchars_output() 34 34 */ 35 function Q($str = '', $mode = 'strict', $newlines = TRUE) {35 function Q($str = '', $mode = 'strict', $newlines = true) { 36 36 return rcube::rep_specialchars_output($str, 'html', $mode, $newlines); 37 37 } … … 78 78 /** 79 79 * Send HTTP headers to prevent caching this page 80 * 80 * 81 81 * @return void 82 82 */ … … 85 85 return; 86 86 } 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 } 93 92 94 93 /** … … 122 121 } 123 122 $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) { 126 124 $iscached = true; 127 125 } … … 131 129 $iscached = true; 132 130 } 131 133 132 if ($iscached) { 134 133 header('HTTP/1.x 304 Not Modified'); … … 141 140 142 141 if ($etag) { 143 header( "Etag: $etag");142 header('Etag: '.$etag); 144 143 } 145 144 … … 148 147 } 149 148 } 150 151 149 152 150 /** … … 185 183 foreach ($var as $key => $value) { 186 184 // 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) */) { 188 186 $key = "'$key'"; 189 187 } … … 202 200 203 201 /** 204 * Function to convert an array to a javascript array205 * Actually an alias function for json_serialize()206 * @deprecated207 */208 // TODO is it really not used? rcmail_compose line 368209 function array2js($arr, $type='') {210 return json_serialize($arr);211 }212 213 214 /**215 202 * Similar function as in_array() but case-insensitive 216 203 * … … 222 209 foreach ($haystack as $value) { 223 210 if (strtolower($needle) === strtolower($value)) { 224 return TRUE;225 } 226 } 227 return FALSE;211 return true; 212 } 213 } 214 return false; 228 215 } 229 216 … … 235 222 * @return boolean Imagine what! 236 223 */ 224 //TODO wtf? purge this 237 225 function 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 } 245 231 246 232 /** … … 258 244 $bytes = floatval($regs[1]); 259 245 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; 269 255 } 270 256 } … … 307 293 $abs_path = $path; 308 294 295 // check if path is an absolute URL 296 if (preg_match('/^[fhtps]+:\/\//', $path)) { 297 return $path; 298 } 309 299 // cut base_url to the last directory 310 300 if (strpos($base_url, '/') > 7) { … … 371 361 return mb_strpos($haystack, $needle, $offset); 372 362 } 373 return strpos($haystack, $needle, $offset);363 return strpos($haystack, $needle, $offset); 374 364 } 375 365 … … 381 371 return mb_strrpos($haystack, $needle, $offset); 382 372 } 383 return strrpos($haystack, $needle, $offset);373 return strrpos($haystack, $needle, $offset); 384 374 } 385 375 … … 432 422 while ($file = readdir($dir)) { 433 423 if (strlen($file) > 2) { 434 unlink( "$dir_path/$file");424 unlink($dir_path.'/'.$file); 435 425 } 436 426 } … … 459 449 $ts = mktime(); 460 450 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; 471 461 } 472 462 … … 474 464 } 475 465 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; 466 function 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; 495 480 } 496 481 -
branches/devel-vnext/program/include/rcube/rcmail_compose.php
r962 r1018 352 352 $lang_set = ''; 353 353 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"; 355 355 } 356 356 $OUTPUT->include_script('googiespell.js'); … … 428 428 429 429 // try to remove the signature 430 if ($sp = strr str($body, '-- ')) {430 if ($sp = strrpos($body, '-- ')) { 431 431 if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r") { 432 432 $body = substr($body, 0, $sp-1); -
branches/devel-vnext/program/include/rcube_header_sorter.php
r806 r1018 8 8 * @license GPL 9 9 */ 10 class rcube_header_sorter 11 { 12 var $sequence_numbers = array(); 10 class rcube_header_sorter { 11 private $sequence_numbers = array(); 13 12 14 13 /** 15 * set the predetermined sort order.14 * Set the predetermined sort order. 16 15 * 17 * @param array $seqnums numerically indexed array of IMAP message sequence numbers16 * @param array Numerically indexed array of IMAP message sequence numbers 18 17 */ 19 public function set_sequence_numbers($seqnums) 20 { 18 public function set_sequence_numbers($seqnums = array()) { 21 19 $this->sequence_numbers = $seqnums; 22 20 } 23 21 24 22 /** 25 * sort the array of header objects23 * Sort the array of header objects 26 24 * 27 * @param array $headers array of iilBasicHeader objects indexed by UID25 * @param array Array of iilBasicHeader objects indexed by UID 28 26 */ 29 public function sort_headers(&$headers) 30 { 27 public function sort_headers($headers) { 31 28 /** 32 29 * uksort would work if the keys were the sequence number, but unfortunately … … 36 33 * uksort($headers, array($this, "compare_seqnums")); 37 34 */ 38 uasort($headers, array($this, "compare_seqnums"));35 uasort($headers, array($this, 'compare_seqnums')); 39 36 } 40 37 41 38 /** 42 * get the position of a message sequence number in my sequence_numbers array39 * Get the position of a message sequence number in my sequence_numbers array 43 40 * 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 45 43 */ 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++) { 50 46 if ($this->sequence_numbers[$pos] == $seqnum) { 51 47 return $pos; … … 58 54 * Sort method called by uasort() 59 55 */ 60 public function compare_seqnums($a, $b) 61 { 56 public function compare_seqnums($a, $b) { 62 57 // First get the sequence number from the header object (the 'id' field). 63 58 $seqa = $a->id; … … 73 68 } 74 69 } 70 71 ?> -
branches/devel-vnext/program/include/rcube_html_page.php
r1017 r1018 195 195 // find and add page footer 196 196 $output_lc = strtolower($output); 197 if (($fpos = strr str($output_lc, '</body>')) || ($fpos = strrstr($output_lc, '</html>'))) {197 if (($fpos = strrpos($output_lc, '</body>')) || ($fpos = strrpos($output_lc, '</html>'))) { 198 198 $output = substr($output, 0, $fpos) . "$__page_footer\n" . substr($output, $fpos); 199 199 } else { -
branches/devel-vnext/program/include/rcube_imap.php
r1017 r1018 39 39 * @link http://ilohamail.org 40 40 */ 41 class rcube_imap 42 { 41 class rcube_imap { 43 42 var $db; 44 43 var $conn; … … 1937 1936 $_query.= ' ?, ?, ?)'; 1938 1937 $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)); 1946 1945 } 1947 1946 … … 1992 1991 1993 1992 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); 1995 1994 } else if ($address) { 1996 1995 $string = $address; … … 2008 2007 } 2009 2008 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) { 2013 2017 $str = $this->decode_mime_string((string)$input); 2014 if ($str{0} =='"' && $remove_quotes) {2018 if ($str{0} == '"' && $remove_quotes) { 2015 2019 $str = str_replace('"', '', $str); 2016 2020 } … … 2022 2026 * Decode a mime-encoded string to internal charset 2023 2027 * 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) { 2028 2033 $out = ''; 2029 2034 … … 2032 2037 $out = substr($input, 0, $pos); 2033 2038 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); 2037 2042 2038 2043 $encstr = substr($input, $pos+2, ($end_pos-$pos-2)); 2039 2044 $rest = substr($input, $end_pos+2); 2040 2045 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); 2043 2048 2044 2049 return $out; 2045 2050 } 2046 2047 2051 // no encoding information, use fallback 2048 2052 return rcube::charset_convert($input, !empty($fallback) ? $fallback : 'ISO-8859-1'); … … 2052 2056 /** 2053 2057 * 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) { 2059 2060 $a = explode('?', $str); 2060 2061 $count = count($a); … … 2062 2063 // should be in format "charset?encoding?base64_string" 2063 2064 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')) { 2069 2070 $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); 2073 2073 $rest = quoted_printable_decode($rest); 2074 2074 } … … 2079 2079 } 2080 2080 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') { 2083 2089 switch (strtolower($encoding)) { 2084 2090 case '7bit': 2085 2091 return $input; 2086 break;2087 2088 2092 case 'quoted-printable': 2089 2093 return quoted_printable_decode($input); 2090 break;2091 2092 2094 case 'base64': 2093 2095 return base64_decode($input); 2094 break;2095 2096 2096 default: 2097 2097 return $input; … … 2099 2099 } 2100 2100 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) { 2121 2109 if (is_array($ctype_param) && !empty($ctype_param['charset'])) { 2122 2110 return rcube::charset_convert($body, $ctype_param['charset']); … … 2126 2114 return rcube::charset_convert($body, 'ISO-8859-1'); 2127 2115 } 2128 2129 2116 2130 2117 /* -------------------------------- … … 2132 2119 * --------------------------------*/ 2133 2120 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 } 2134 2154 2135 2155 /** 2136 2156 * _mod_mailbox 2137 2157 * 2138 * @access private2139 2158 * @param string $mbox_name 2140 2159 * @param string $mode 2141 2160 * @return string $mbox_name 2142 2161 */ 2143 private function _mod_mailbox($mbox_name, $mode='in') 2144 { 2162 private function _mod_mailbox($mbox_name, $mode = 'in') { 2145 2163 if ((!empty($this->root_ns) && $this->root_ns == $mbox_name) || $mbox_name == 'INBOX') { 2146 2164 return $mbox_name; … … 2149 2167 if (!empty($this->root_dir) && $mode=='in') { 2150 2168 $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') { 2153 2170 $mbox_name = substr($mbox_name, strlen($this->root_dir)+1); 2154 2171 } … … 2157 2174 2158 2175 /** 2159 * sort mailboxes first by default folders and then in alphabethical order2160 * /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) { 2163 2180 $a_out = $a_defaults = array(); 2164 2181 … … 2169 2186 } 2170 2187 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]) { 2172 2189 $a_defaults[$p] = $folder; 2173 } 2174 else { 2190 } else { 2175 2191 $a_out[] = $folder; 2176 2192 } 2177 2193 } 2178 2194 2179 sort($a_out);2195 natcasesort($a_out); 2180 2196 ksort($a_defaults); 2181 2197 … … 2183 2199 } 2184 2200 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) { 2199 2202 if (!$mbox_name) { 2200 2203 $mbox_name = $this->mailbox; … … 2207 2210 } 2208 2211 2209 function _id2uid($id, $mbox_name=NULL) 2210 { 2212 private function _id2uid($id, $mbox_name = null) { 2211 2213 if (!$mbox_name) { 2212 2214 $mbox_name = $this->mailbox; 2213 2215 } 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) { 2233 2243 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 } 2237 2247 $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 } 2263 2275 } 2264 2276 2265 2277 // get cached mailbox list 2266 if ($updated) 2267 { 2278 if ($updated) { 2268 2279 $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 } 2271 2283 2272 2284 // 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 } 2277 2290 2278 2291 // write mailboxlist to cache 2279 2292 $this->update_cache('mailboxes', $this->_sort_mailbox_list($a_mailbox_cache)); 2280 2293 } 2281 2282 2294 return $updated; 2283 2295 } 2284 2296 2285 2297 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; 2290 2303 $mailbox = $mbox_name ? $mbox_name : $this->mailbox; 2291 2304 $mode = strtoupper($mode); … … 2293 2306 $a_mailbox_cache = $this->get_cache('messagecount'); 2294 2307 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 } 2297 2311 2298 2312 // add incremental value to messagecount 2299 2313 $a_mailbox_cache[$mailbox][$mode] += $increment; 2300 2301 2314 // 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 } 2305 2318 // write back to cache 2306 2319 $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; 2316 2328 $mailbox = $mbox_name ? $mbox_name : $this->mailbox; 2317 2329 2318 2330 $a_mailbox_cache = $this->get_cache('messagecount'); 2319 2331 2320 if (is_array($a_mailbox_cache[$mailbox])) 2321 { 2332 if (is_array($a_mailbox_cache[$mailbox])) { 2322 2333 unset($a_mailbox_cache[$mailbox]); 2323 2334 $this->update_cache('messagecount', $a_mailbox_cache); … … 2325 2336 } 2326 2337 2327 2328 // split RFC822 header string into an associative array2329 function _parse_headers($headers)2330 {2338 /** 2339 * Split RFC822 header string into an associative array 2340 */ 2341 private function _parse_headers($headers) { 2331 2342 $a_headers = array(); 2332 2343 $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], ': ')) { 2338 2347 $field = strtolower(substr($lines[$i], 0, $p)); 2339 2348 $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 } 2345 2354 return $a_headers; 2346 2355 } 2347 2356 2348 2357 2349 function _parse_address_list($str, $decode=true) 2350 { 2358 private function _parse_address_list($str, $decode = true) { 2351 2359 // 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)); 2353 2361 $result = array(); 2354 2362 2355 foreach ($a as $key => $val) 2356 { 2363 foreach ($a as $key => $val) { 2357 2364 $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); 2359 2366 $result[$key]['name'] = ''; 2360 2367 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 } 2393 2380 return $result; 2394 2381 } … … 2399 2386 * Add quoted-printable encoding to a given string 2400 2387 * 2401 * @param string $input string to encode2402 * @param int $line_max add new line after this number of characters2403 * @param boole na $space_conf true if spaces should be converted into =202404 * @return encoded string2388 * @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 2405 2392 */ 2406 function quoted_printable_encode($input, $line_max=76, $space_conv=false) 2407 { 2393 function quoted_printable_encode($input, $line_max = 76, $space_conv = false) { 2408 2394 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); 2409 2395 $lines = preg_split("/(?:\r\n|\r|\n)/", $input); 2410 2396 $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)) { 2415 2401 //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary 2416 2402 $linlen = strlen($line); 2417 $newline = "";2418 for ($i = 0; $i < $linlen; $i++) {2403 $newline = ''; 2404 for ($i = 0; $i < $linlen; $i++) { 2419 2405 $c = substr( $line, $i, 1 ); 2420 2406 $dec = ord( $c ); 2421 2407 if ( ( $i == 0 ) && ( $dec == 46 ) ) { 2422 2408 // 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 2438 2418 $h2 = floor($dec/16); 2439 2419 $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 = ''; 2447 2428 // check if newline first character will be point or not 2448 2429 if ( $dec == 46 ) { 2449 $c = "=2E";2430 $c = '=2E'; 2450 2431 } 2451 2432 } … … 2457 2438 return trim($output); 2458 2439 } 2440 2441 ?> -
branches/devel-vnext/program/include/rcube_mail_mime.php
r806 r1018 18 18 $Id: sendmail.inc 506 2007-03-14 00:39:51Z thomasb $ 19 19 20 */20 */ 21 21 22 22 … … 26 26 * @package Mail 27 27 */ 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; 28 class rcube_mail_mime extends Mail_mime { 52 29 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 } 55 38 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; 139 58 } 140 59 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; 147 62 } 148 else 149 { 150 $hdr_value .= ($i>0?', ':'') . "\n " . $value; 151 $line_len = $len; 63 64 if ($contentid == '') { 65 $contentid = md5(uniqid(time())); 152 66 } 153 }154 67 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; 156 71 } 157 72 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 } 160 85 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 } 161 93 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; 175 162 } 176 177 $result[] = substr($string, $p);178 return $result;179 }180 181 163 } 182 164 -
branches/devel-vnext/program/lib/imap.inc
r995 r1018 127 127 var $internaldate; 128 128 var $references; 129 var $priority; 129 130 var $mdn_to; 130 131 var $mdn_sent = false; … … 162 163 if ($fp) { 163 164 do { 165 // FIXME: hardcode size? 164 166 $buffer = fgets($fp, 2048); 165 167 if ($buffer === false) { 166 168 break; 167 169 } 168 $line .=$buffer;170 $line .= $buffer; 169 171 } while ($buffer[strlen($buffer)-1]!="\n"); 170 172 } … … 176 178 if (ereg('\{[0-9]+\}$', $line)) { 177 179 $out = ''; 180 178 181 preg_match_all('/(.*)\{([0-9]+)\}$/', $line, $a); 179 182 $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\""; 184 188 } 185 189 return $line; … … 1516 1520 $request .= "(DATE FROM TO SUBJECT REPLY-TO IN-REPLY-TO CC BCC "; 1517 1521 $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"; 1519 1523 1520 1524 if (!fputs($fp, $request)) { … … 1625 1629 case 'message-id': 1626 1630 $result[$id]->messageID = $string; 1631 break; 1632 case 'x-priority': 1633 if (preg_match('/^(\d+)/', $string, $matches)) 1634 $result[$id]->priority = intval($matches[1]); 1627 1635 break; 1628 1636 } // end switch () … … 2580 2588 return (iil_C_Expunge($conn, $folder) >= 0); 2581 2589 } 2590 2591 ?> -
branches/devel-vnext/program/lib/mime.inc
r589 r1018 1 1 <?php 2 2 ///////////////////////////////////////////////////////// 3 // 3 // 4 4 // Iloha MIME Library (IML) 5 5 // 6 6 // (C)Copyright 2002 Ryo Chijiiwa <Ryo@IlohaMail.org> 7 7 // 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 10 10 // see http://www.fsf.org/copyleft/gpl.html 11 11 // … … 14 14 /******************************************************** 15 15 16 FILE: include/mime.inc17 PURPOSE:18 Provide functions for handling mime messages.19 USAGE:20 Use iil_C_FetchStructureString to get IMAP structure stirng, then pass that through21 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.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. 23 23 24 24 ********************************************************/ … … 33 33 $MIME_OTHER = 7; 34 34 35 function iml_ClosingParenPos($str, $start) {36 $level =0;35 function iml_ClosingParenPos($str, $start) { 36 $level = 0; 37 37 $len = strlen($str); 38 38 $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 56 function iml_ParseBSString($str) { 51 57 $id = 0; 52 58 $a = array(); 53 59 $len = strlen($str); 54 55 60 $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 61 75 $i++; 62 76 $endPos = iml_ClosingParenPos($str, $i); 63 77 $partLen = $endPos - $i; 64 78 $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 } 70 85 $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 } 78 100 reset($a); 79 101 return $a; 80 102 } 81 103 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 }104 function 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 } 90 112 return $struct; 91 113 } 92 114 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=""; 115 function 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 144 function 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 165 function 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 186 function iml_GetFirstTextPart($structure, $part = 0) { 187 if ($part == 0) { 188 $part = ''; 189 } 156 190 $typeCode = -1; 157 while ($typeCode !=0){191 while ($typeCode != 0) { 158 192 $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); 163 197 $lastPart = count($parts_a) - 1; 164 198 $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 } 171 204 return $part; 172 205 } 173 206 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{ 207 function 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 230 function 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 253 function 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 266 function 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 279 function 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 292 function 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 { 233 298 $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 310 function 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])) { 247 318 //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)) { 255 327 //check in content disposition 256 328 $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]))) { 258 330 $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)) { 261 333 $name=$array[$key+1]; 334 } 262 335 } 263 336 } 264 337 } 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 346 function 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 369 function 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 395 function 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 322 406 ?>
Note: See TracChangeset
for help on using the changeset viewer.
