Changeset 4306 in subversion


Ignore:
Timestamp:
Dec 3, 2010 7:25:49 AM (2 years ago)
Author:
alec
Message:
  • Improve performance of moving or copying of all messages in a folder (use CLOSE intead of EXPUNGE)
  • Code cleanup + added more phpdoc comments
Location:
trunk/roundcubemail
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r4304 r4306  
    1313- Add folder size and quota indicator in folder manager (#1485780) 
    1414- Add possibility to move a subfolder into root folder (#1486791) 
     15- Fix copying all messages in a folder copies only messages from current page 
     16- Improve performance of moving or copying of all messages in a folder 
    1517 
    1618RELEASE 0.5-BETA 
  • trunk/roundcubemail/program/include/rcube_imap.php

    r4304 r4306  
    186186    function close() 
    187187    { 
    188         $this->conn->close(); 
     188        $this->conn->closeConnection(); 
    189189        $this->write_cache(); 
    190190    } 
     
    199199    function reconnect() 
    200200    { 
    201         $this->close(); 
     201        $this->closeConnection(); 
    202202        $this->connect($this->host, $this->user, $this->pass, $this->port, $this->ssl); 
    203203 
     
    618618        // RECENT count is fetched a bit different 
    619619        else if ($mode == 'RECENT') { 
    620             $count = $this->conn->checkForRecent($mailbox); 
     620            $count = $this->conn->countRecent($mailbox); 
    621621        } 
    622622        // use SEARCH for message counting 
     
    25832583        // send expunge command in order to have the moved message 
    25842584        // really deleted from the source mailbox 
     2585$aa = rcube_timer(); 
    25852586        if ($moved) { 
    25862587            $this->_expunge($from_mbox, false, $uids); 
     
    25922593            $moved = $this->delete_message($uids, $fbox); 
    25932594        } 
    2594  
     2595rcube_print_time($aa); 
    25952596        if ($moved) { 
    25962597            // unset threads internal cache 
     
    27752776            $a_uids = NULL; 
    27762777 
    2777         $result = $this->conn->expunge($mailbox, $a_uids); 
     2778        // CLOSE(+SELECT) should be faster than EXPUNGE 
     2779        if (empty($a_uids) || $a_uids == '1:*') 
     2780            $result = $this->conn->close(); 
     2781        else 
     2782            $result = $this->conn->expunge($mailbox, $a_uids); 
    27782783 
    27792784        if ($result && $clear_cache) { 
  • trunk/roundcubemail/program/include/rcube_imap_generic.php

    r4263 r4306  
    684684 
    685685                $this->setError(self::ERROR_BAD, $error); 
    686             $this->close(); 
     686            $this->closeConnection(); 
    687687                return false; 
    688688            } 
     
    701701 
    702702                if ($res[0] != self::ERROR_OK) { 
    703                     $this->close(); 
     703                    $this->closeConnection(); 
    704704                    return false; 
    705705                } 
     
    707707                            if (!stream_socket_enable_crypto($this->fp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { 
    708708                                    $this->setError(self::ERROR_BAD, "Unable to negotiate TLS"); 
    709                     $this->close(); 
     709                    $this->closeConnection(); 
    710710                                    return false; 
    711711                            } 
     
    739739                    if ($auth_method == 'LOGIN' && $this->getCapability('LOGINDISABLED')) { 
    740740                            $this->setError(self::ERROR_BAD, "Login disabled by IMAP server"); 
    741                 $this->close(); 
     741                $this->closeConnection(); 
    742742                            return false; 
    743743            } 
     
    779779        } 
    780780 
    781         // Close connection 
    782         $this->close(); 
     781        $this->closeConnection(); 
    783782 
    784783        return false; 
     
    790789    } 
    791790 
    792     function close() 
     791    function closeConnection() 
    793792    { 
    794793            if ($this->putLine($this->nextTag() . ' LOGOUT')) { 
     
    800799    } 
    801800 
     801    /** 
     802     * Executes SELECT command (if mailbox is already not in selected state) 
     803     * 
     804     * @param string $mailbox Mailbox name 
     805     * 
     806     * @return boolean True on success, false on error 
     807     * @access public 
     808     */ 
    802809    function select($mailbox) 
    803810    { 
     
    843850 
    844851    /** 
    845      * Executes STATUS comand 
     852     * Executes STATUS command 
    846853     * 
    847854     * @param string $mailbox Mailbox name 
     
    888895    } 
    889896 
    890     function checkForRecent($mailbox) 
    891     { 
    892             if (!strlen($mailbox)) { 
    893                     $mailbox = 'INBOX'; 
    894             } 
    895  
    896             $this->select($mailbox); 
    897  
    898             if ($this->selected == $mailbox) { 
    899                     return $this->data['RECENT']; 
    900             } 
     897    /** 
     898     * Executes EXPUNGE command 
     899     * 
     900     * @param string $mailbox  Mailbox name 
     901     * @param string $messages Message UIDs to expunge 
     902     * 
     903     * @return boolean True on success, False on error 
     904     * @access public 
     905     */ 
     906    function expunge($mailbox, $messages=NULL) 
     907    { 
     908            if (!$this->select($mailbox)) { 
     909            return false; 
     910        } 
     911 
     912        // Clear internal status cache 
     913        unset($this->data['STATUS:'.$mailbox]); 
     914 
     915                if ($messages) 
     916                        $result = $this->execute('UID EXPUNGE', array($messages), self::COMMAND_NORESPONSE); 
     917                else 
     918                        $result = $this->execute('EXPUNGE', null, self::COMMAND_NORESPONSE); 
     919 
     920                if ($result == self::ERROR_OK) { 
     921                        $this->selected = ''; // state has changed, need to reselect 
     922                        return true; 
     923                } 
    901924 
    902925            return false; 
    903926    } 
    904927 
     928    /** 
     929     * Executes CLOSE command 
     930     * 
     931     * @return boolean True on success, False on error 
     932     * @access public 
     933     * @since 0.5 
     934     */ 
     935    function close() 
     936    { 
     937        $result = $this->execute('CLOSE', NULL, self::COMMAND_NORESPONSE); 
     938 
     939        if ($result == self::ERROR_OK) { 
     940            $this->selected = ''; 
     941            return true; 
     942        } 
     943 
     944            return false; 
     945    } 
     946 
     947    /** 
     948     * Executes SUBSCRIBE command 
     949     * 
     950     * @param string $mailbox Mailbox name 
     951     * 
     952     * @return boolean True on success, False on error 
     953     * @access public 
     954     */ 
     955    function subscribe($mailbox) 
     956    { 
     957            $result = $this->execute('SUBSCRIBE', array($this->escape($mailbox)), 
     958                self::COMMAND_NORESPONSE); 
     959 
     960            return ($result == self::ERROR_OK); 
     961    } 
     962 
     963    /** 
     964     * Executes UNSUBSCRIBE command 
     965     * 
     966     * @param string $mailbox Mailbox name 
     967     * 
     968     * @return boolean True on success, False on error 
     969     * @access public 
     970     */ 
     971    function unsubscribe($mailbox) 
     972    { 
     973            $result = $this->execute('UNSUBSCRIBE', array($this->escape($mailbox)), 
     974                self::COMMAND_NORESPONSE); 
     975 
     976            return ($result == self::ERROR_OK); 
     977    } 
     978 
     979    /** 
     980     * Executes DELETE command 
     981     * 
     982     * @param string $mailbox Mailbox name 
     983     * 
     984     * @return boolean True on success, False on error 
     985     * @access public 
     986     */ 
     987    function deleteFolder($mailbox) 
     988    { 
     989        $result = $this->execute('DELETE', array($this->escape($mailbox)), 
     990                self::COMMAND_NORESPONSE); 
     991 
     992            return ($result == self::ERROR_OK); 
     993    } 
     994 
     995    /** 
     996     * Removes all messages in a folder 
     997     * 
     998     * @param string $mailbox Mailbox name 
     999     * 
     1000     * @return boolean True on success, False on error 
     1001     * @access public 
     1002     */ 
     1003    function clearFolder($mailbox) 
     1004    { 
     1005            $num_in_trash = $this->countMessages($mailbox); 
     1006            if ($num_in_trash > 0) { 
     1007                    $this->delete($mailbox, '1:*'); 
     1008            } 
     1009 
     1010        $res = $this->close(); 
     1011//          $res = $this->expunge($mailbox); 
     1012 
     1013            return $res; 
     1014    } 
     1015 
     1016    /** 
     1017     * Returns count of all messages in a folder 
     1018     * 
     1019     * @param string $mailbox Mailbox name 
     1020     * 
     1021     * @return int Number of messages, False on error 
     1022     * @access public 
     1023     */ 
    9051024    function countMessages($mailbox, $refresh = false) 
    9061025    { 
     
    9261045 
    9271046        return false; 
     1047    } 
     1048 
     1049    /** 
     1050     * Returns count of messages with \Recent flag in a folder 
     1051     * 
     1052     * @param string $mailbox Mailbox name 
     1053     * 
     1054     * @return int Number of messages, False on error 
     1055     * @access public 
     1056     */ 
     1057    function countRecent($mailbox) 
     1058    { 
     1059            if (!strlen($mailbox)) { 
     1060                    $mailbox = 'INBOX'; 
     1061            } 
     1062 
     1063            $this->select($mailbox); 
     1064 
     1065            if ($this->selected == $mailbox) { 
     1066                    return $this->data['RECENT']; 
     1067            } 
     1068 
     1069            return false; 
    9281070    } 
    9291071 
     
    15661708    } 
    15671709 
    1568     function expunge($mailbox, $messages=NULL) 
    1569     { 
    1570             if (!$this->select($mailbox)) { 
    1571             return false; 
    1572         } 
    1573  
    1574         // Clear internal status cache 
    1575         unset($this->data['STATUS:'.$mailbox]); 
    1576  
    1577                 if ($messages) 
    1578                         $result = $this->execute('UID EXPUNGE', array($messages), self::COMMAND_NORESPONSE); 
    1579                 else 
    1580                         $result = $this->execute('EXPUNGE', null, self::COMMAND_NORESPONSE); 
    1581  
    1582                 if ($result == self::ERROR_OK) { 
    1583                         $this->selected = ''; // state has changed, need to reselect 
    1584                         return true; 
    1585                 } 
    1586  
    1587             return false; 
    1588     } 
    15891710 
    15901711    function modFlag($mailbox, $messages, $flag, $mod) 
     
    21542275    } 
    21552276 
    2156     function deleteFolder($mailbox) 
    2157     { 
    2158         $result = $this->execute('DELETE', array($this->escape($mailbox)), 
    2159                 self::COMMAND_NORESPONSE); 
    2160  
    2161             return ($result == self::ERROR_OK); 
    2162     } 
    2163  
    2164     function clearFolder($mailbox) 
    2165     { 
    2166             $num_in_trash = $this->countMessages($mailbox); 
    2167             if ($num_in_trash > 0) { 
    2168                     $this->delete($mailbox, '1:*'); 
    2169             } 
    2170             return ($this->expunge($mailbox) >= 0); 
    2171     } 
    2172  
    2173     function subscribe($mailbox) 
    2174     { 
    2175             $result = $this->execute('SUBSCRIBE', array($this->escape($mailbox)), 
    2176                 self::COMMAND_NORESPONSE); 
    2177  
    2178             return ($result == self::ERROR_OK); 
    2179     } 
    2180  
    2181     function unsubscribe($mailbox) 
    2182     { 
    2183             $result = $this->execute('UNSUBSCRIBE', array($this->escape($mailbox)), 
    2184                 self::COMMAND_NORESPONSE); 
    2185  
    2186             return ($result == self::ERROR_OK); 
    2187     } 
    2188  
    21892277    function append($mailbox, &$message) 
    21902278    { 
Note: See TracChangeset for help on using the changeset viewer.