Changeset 3413 in subversion
- Timestamp:
- Mar 24, 2010 7:27:44 AM (3 years ago)
- Location:
- trunk/roundcubemail/program
- Files:
-
- 2 edited
-
include/rcube_imap.php (modified) (20 diffs)
-
lib/imap.inc (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/program/include/rcube_imap.php
r3401 r3413 2105 2105 * Set message flag to one or several messages 2106 2106 * 2107 * @param mixed Message UIDs as array or as comma-separated string2108 * @param string Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT2109 * @param string Folder name2107 * @param mixed Message UIDs as array or comma-separated string, or '*' 2108 * @param string Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT 2109 * @param string Folder name 2110 2110 * @param boolean True to skip message cache clean up 2111 * @return boolean True on success, Falseon failure2111 * @return int Number of flagged messages, -1 on failure 2112 2112 */ 2113 2113 function set_flag($uids, $flag, $mbox_name=NULL, $skip_cache=false) … … 2116 2116 2117 2117 $flag = strtoupper($flag); 2118 if (!is_array($uids)) 2119 $uids = explode(',',$uids); 2120 2118 list($uids, $all_mode) = $this->_parse_uids($uids); 2119 2121 2120 if (strpos($flag, 'UN') === 0) 2122 $result = iil_C_UnFlag($this->conn, $mailbox, join(',', $uids), substr($flag, 2));2121 $result = iil_C_UnFlag($this->conn, $mailbox, $uids, substr($flag, 2)); 2123 2122 else 2124 $result = iil_C_Flag($this->conn, $mailbox, join(',', $uids), $flag); 2125 2126 // reload message headers if cached 2127 if ($this->caching_enabled && !$skip_cache) { 2128 $cache_key = $mailbox.'.msg'; 2129 $this->remove_message_cache($cache_key, $uids); 2130 } 2131 2132 // set nr of messages that were flaged 2133 $count = count($uids); 2134 2135 // clear message count cache 2136 if ($result && $flag=='SEEN') 2137 $this->_set_messagecount($mailbox, 'UNSEEN', $count*(-1)); 2138 else if ($result && $flag=='UNSEEN') 2139 $this->_set_messagecount($mailbox, 'UNSEEN', $count); 2140 else if ($result && $flag=='DELETED') 2141 $this->_set_messagecount($mailbox, 'ALL', $count*(-1)); 2123 $result = iil_C_Flag($this->conn, $mailbox, $uids, $flag); 2124 2125 if ($result >= 0) { 2126 // reload message headers if cached 2127 if ($this->caching_enabled && !$skip_cache) { 2128 $cache_key = $mailbox.'.msg'; 2129 if ($all_mode) 2130 $this->clear_message_cache($cache_key); 2131 else 2132 $this->remove_message_cache($cache_key, explode(',', $uids)); 2133 } 2134 // update counters 2135 if ($flag=='SEEN') 2136 $this->_set_messagecount($mailbox, 'UNSEEN', $result*(-1)); 2137 else if ($flag=='UNSEEN') 2138 $this->_set_messagecount($mailbox, 'UNSEEN', $result); 2139 else if ($flag=='DELETED') 2140 $this->_set_messagecount($mailbox, 'ALL', $result*(-1)); 2141 } 2142 2142 2143 2143 return $result; … … 2148 2148 * Remove message flag for one or several messages 2149 2149 * 2150 * @param mixed Message UIDs as array or as comma-separated string2150 * @param mixed Message UIDs as array or comma-separated string, or '*' 2151 2151 * @param string Flag to unset: SEEN, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT 2152 2152 * @param string Folder name 2153 * @return boolean True on success, Falseon failure2153 * @return int Number of flagged messages, -1 on failure 2154 2154 * @see set_flag 2155 2155 */ … … 2198 2198 * Move a message from one mailbox to another 2199 2199 * 2200 * @param string List of UIDs to move, separated by comma2200 * @param mixed Message UIDs as array or comma-separated string, or '*' 2201 2201 * @param string Target mailbox 2202 2202 * @param string Source mailbox … … 2210 2210 $from_mbox = $from_mbox ? $this->mod_mailbox($from_mbox) : $this->mailbox; 2211 2211 2212 // convert the list of uids to array 2213 $a_uids = is_string($uids) ? explode(',', $uids) : (is_array($uids) ? $uids : NULL); 2212 list($uids, $all_mode) = $this->_parse_uids($uids); 2214 2213 2215 2214 // exit if no message uids are specified 2216 if ( !is_array($a_uids) || empty($a_uids))2215 if (empty($uids)) 2217 2216 return false; 2218 2217 … … 2234 2233 2235 2234 // move messages 2236 $iil_move = iil_C_Move($this->conn, join(',', $a_uids), $from_mbox, $to_mbox);2235 $iil_move = iil_C_Move($this->conn, $uids, $from_mbox, $to_mbox); 2237 2236 $moved = !($iil_move === false || $iil_move < 0); 2238 2237 … … 2240 2239 // really deleted from the source mailbox 2241 2240 if ($moved) { 2242 $this->_expunge($from_mbox, false, $ a_uids);2241 $this->_expunge($from_mbox, false, $uids); 2243 2242 $this->_clear_messagecount($from_mbox); 2244 2243 $this->_clear_messagecount($to_mbox); … … 2246 2245 // moving failed 2247 2246 else if ($config->get('delete_always', false) && $tbox == $config->get('trash_mbox')) { 2248 $moved = $this->delete_message($ a_uids, $fbox);2247 $moved = $this->delete_message($uids, $fbox); 2249 2248 } 2250 2249 … … 2256 2255 if ($this->search_set && $from_mbox == $this->mailbox) { 2257 2256 // threads are too complicated to just remove messages from set 2258 if ($this->search_threads )2257 if ($this->search_threads || $all_mode) 2259 2258 $this->refresh_search(); 2260 2259 else { 2261 foreach ($a_uids as $uid) 2260 $uids = explode(',', $uids); 2261 foreach ($uids as $uid) 2262 2262 $a_mids[] = $this->_uid2id($uid, $from_mbox); 2263 2263 $this->search_set = array_diff($this->search_set, $a_mids); … … 2267 2267 // update cached message headers 2268 2268 $cache_key = $from_mbox.'.msg'; 2269 if ($ start_index = $this->get_message_cache_index_min($cache_key, $a_uids)) {2269 if ($all_mode || ($start_index = $this->get_message_cache_index_min($cache_key, $uids))) { 2270 2270 // clear cache from the lowest index on 2271 $this->clear_message_cache($cache_key, $ start_index);2271 $this->clear_message_cache($cache_key, $all_mode ? 1 : $start_index); 2272 2272 } 2273 2273 } … … 2280 2280 * Copy a message from one mailbox to another 2281 2281 * 2282 * @param string List of UIDs to copy, separated by comma2282 * @param mixed Message UIDs as array or comma-separated string, or '*' 2283 2283 * @param string Target mailbox 2284 2284 * @param string Source mailbox … … 2292 2292 $from_mbox = $from_mbox ? $this->mod_mailbox($from_mbox) : $this->mailbox; 2293 2293 2294 // convert the list of uids to array 2295 $a_uids = is_string($uids) ? explode(',', $uids) : (is_array($uids) ? $uids : NULL); 2294 list($uids, $all_mode) = $this->_parse_uids($uids); 2296 2295 2297 2296 // exit if no message uids are specified 2298 if ( !is_array($a_uids) || empty($a_uids))2297 if (empty($uids)) 2299 2298 return false; 2300 2299 … … 2309 2308 2310 2309 // copy messages 2311 $iil_copy = iil_C_Copy($this->conn, join(',', $a_uids), $from_mbox, $to_mbox);2310 $iil_copy = iil_C_Copy($this->conn, $uids, $from_mbox, $to_mbox); 2312 2311 $copied = !($iil_copy === false || $iil_copy < 0); 2313 2312 … … 2323 2322 * Mark messages as deleted and expunge mailbox 2324 2323 * 2325 * @param string List of UIDs to move, separated by comma2324 * @param mixed Message UIDs as array or comma-separated string, or '*' 2326 2325 * @param string Source mailbox 2327 2326 * @return boolean True on success, False on error … … 2331 2330 $mailbox = $mbox_name ? $this->mod_mailbox($mbox_name) : $this->mailbox; 2332 2331 2333 // convert the list of uids to array 2334 $a_uids = is_string($uids) ? explode(',', $uids) : (is_array($uids) ? $uids : NULL); 2335 2332 list($uids, $all_mode) = $this->_parse_uids($uids); 2333 2336 2334 // exit if no message uids are specified 2337 if ( !is_array($a_uids) || empty($a_uids))2335 if (empty($uids)) 2338 2336 return false; 2339 2337 2340 $deleted = iil_C_Delete($this->conn, $mailbox, join(',', $a_uids));2338 $deleted = iil_C_Delete($this->conn, $mailbox, $uids); 2341 2339 2342 2340 if ($deleted) { 2343 2341 // send expunge command in order to have the deleted message 2344 2342 // really deleted from the mailbox 2345 $this->_expunge($mailbox, false, $ a_uids);2343 $this->_expunge($mailbox, false, $uids); 2346 2344 $this->_clear_messagecount($mailbox); 2347 2345 unset($this->uid_id_map[$mailbox]); … … 2353 2351 if ($this->search_set && $mailbox == $this->mailbox) { 2354 2352 // threads are too complicated to just remove messages from set 2355 if ($this->search_threads )2353 if ($this->search_threads || $all_mode) 2356 2354 $this->refresh_search(); 2357 2355 else { 2358 foreach ($a_uids as $uid) 2356 $uids = explode(',', $uids); 2357 foreach ($uids as $uid) 2359 2358 $a_mids[] = $this->_uid2id($uid, $mailbox); 2360 2359 $this->search_set = array_diff($this->search_set, $a_mids); … … 2364 2363 // remove deleted messages from cache 2365 2364 $cache_key = $mailbox.'.msg'; 2366 if ($ start_index = $this->get_message_cache_index_min($cache_key, $a_uids)) {2365 if ($all_mode || ($start_index = $this->get_message_cache_index_min($cache_key, $uids))) { 2367 2366 // clear cache from the lowest index on 2368 $this->clear_message_cache($cache_key, $ start_index);2367 $this->clear_message_cache($cache_key, $all_mode ? 1 : $start_index); 2369 2368 } 2370 2369 } … … 2422 2421 * Send IMAP expunge command and clear cache 2423 2422 * 2424 * @see rcube_imap::expunge() 2425 * @param string Mailbox name 2426 * @param boolean False if cache should not be cleared 2427 * @param string List of UIDs to remove, separated by comma 2423 * @param string Mailbox name 2424 * @param boolean False if cache should not be cleared 2425 * @param mixed Message UIDs as array or comma-separated string, or '*' 2428 2426 * @return boolean True on success 2429 2427 * @access private 2428 * @see rcube_imap::expunge() 2430 2429 */ 2431 2430 private function _expunge($mailbox, $clear_cache=true, $uids=NULL) … … 2448 2447 2449 2448 2449 /** 2450 * Parse message UIDs input 2451 * 2452 * @param mixed UIDs array or comma-separated list or '*' or '1:*' 2453 * @return array Two elements array with UIDs converted to list and ALL flag 2454 * @access private 2455 */ 2456 private function _parse_uids($uids) 2457 { 2458 if ($uids === '*' || $uids === '1:*') { 2459 $uids = '1:*'; 2460 $all = true; 2461 } 2462 else { 2463 if (is_array($uids)) 2464 $uids = join(',', $uids); 2465 2466 if (preg_match('/[^0-9,]/', $uids)) 2467 $uids = ''; 2468 } 2469 2470 return array($uids, (bool) $all); 2471 } 2472 2473 2450 2474 /* -------------------------------- 2451 2475 * folder managment 2452 2476 * --------------------------------*/ 2453 2454 2477 2455 2478 /** … … 3149 3172 return; 3150 3173 3174 if (!empty($uids) && !is_array($uids)) { 3175 if ($uids == '*' || $uids == '1:*') 3176 $uids = NULL; 3177 else 3178 $uids = explode(',', $uids); 3179 } 3180 3151 3181 $sql_result = $this->db->query( 3152 3182 "SELECT MIN(idx) AS minidx -
trunk/roundcubemail/program/lib/imap.inc
r3379 r3413 390 390 } 391 391 392 function iil_C _ClearCapability(&$conn)392 function iil_ClearCapability() 393 393 { 394 394 $conn->capability = array(); … … 661 661 662 662 // Now we're authenticated, capabilities need to be reread 663 iil_C _ClearCapability($conn);663 iil_ClearCapability(); 664 664 } 665 665 } … … 1426 1426 iil_PutLine($conn->fp, "exp1 $command"); 1427 1427 do { 1428 $line =chop(iil_ReadLine($conn->fp, 100));1428 $line = iil_ReadLine($conn->fp, 100); 1429 1429 if ($line[0] == '*') { 1430 $c++;1431 }1430 $c++; 1431 } 1432 1432 } while (!iil_StartsWith($line, 'exp1', true)); 1433 1433 … … 1448 1448 } 1449 1449 1450 $fp = $conn->fp;1451 1450 $flags = $GLOBALS['IMAP_FLAGS']; 1452 1453 $flag = strtoupper($flag); 1454 $flag = $flags[$flag]; 1455 1456 if (iil_C_Select($conn, $mailbox)) { 1457 $c = 0; 1458 iil_PutLine($fp, "flg UID STORE $messages " . $mod . "FLAGS (" . $flag . ")"); 1459 do { 1460 $line=chop(iil_ReadLine($fp, 100)); 1461 if ($line[0] == '*') { 1462 $c++; 1463 } 1464 } while (!iil_StartsWith($line, 'flg', true)); 1465 1466 if (iil_ParseResult($line) == 0) { 1467 return $c; 1468 } 1469 $conn->error = $line; 1470 return -1; 1471 } 1472 $conn->error = 'Select failed'; 1451 $flag = $flags[strtoupper($flag)]; 1452 1453 if (!iil_C_Select($conn, $mailbox)) { 1454 return -1; 1455 } 1456 1457 $c = 0; 1458 iil_PutLine($conn->fp, "flg UID STORE $messages " . $mod . "FLAGS (" . $flag . ")"); 1459 do { 1460 $line = iil_ReadLine($conn->fp, 1000); 1461 if ($line[0] == '*') { 1462 $c++; 1463 } 1464 } while (!iil_StartsWith($line, 'flg', true)); 1465 1466 if (iil_ParseResult($line) == 0) { 1467 return $c; 1468 } 1469 1470 $conn->error = $line; 1473 1471 return -1; 1474 1472 } … … 1487 1485 1488 1486 function iil_C_Copy(&$conn, $messages, $from, $to) { 1489 $fp = $conn->fp;1490 1487 1491 1488 if (empty($from) || empty($to)) { … … 1493 1490 } 1494 1491 1495 if (iil_C_Select($conn, $from)) { 1496 $c=0; 1497 1498 iil_PutLine($fp, "cpy1 UID COPY $messages \"".iil_Escape($to)."\""); 1499 $line = iil_ReadReply($fp); 1500 return iil_ParseResult($line); 1501 } else { 1502 return -1; 1503 } 1492 if (!iil_C_Select($conn, $from)) { 1493 return -1; 1494 } 1495 1496 iil_PutLine($conn->fp, "cpy1 UID COPY $messages \"".iil_Escape($to)."\""); 1497 $line = iil_ReadReply($conn->fp); 1498 return iil_ParseResult($line); 1504 1499 } 1505 1500 1506 1501 function iil_C_CountUnseen(&$conn, $folder) { 1507 $index = iil_C_Search($conn, $folder, 'ALL UNSEEN');1508 if (is_array($index))1509 return count($index);1510 return false;1502 $index = iil_C_Search($conn, $folder, 'ALL UNSEEN'); 1503 if (is_array($index)) 1504 return count($index); 1505 return false; 1511 1506 } 1512 1507
Note: See TracChangeset
for help on using the changeset viewer.
