imap.php

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· PHP 代码 · 共 1,840 行 · 第 1/4 页

PHP
1,840
字号
        }
        if( count( $ret ) > 0 ){
            return true;
        }
        return false;
    }







    /**
    * Creates the mailbox $mailbox
    *
    * @param string $mailbox     mailbox name to create
    *
    * @return mixed true on Success/PearError on Failure
    * @since 1.0
    */
    function createMailbox($mailbox)
    {
        $ret=$this->cmdCreate($mailbox);
        if(strtoupper($ret["RESPONSE"]["CODE"]) != "OK"){
            return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]);
        }
        return true;
    }




    /**
    * Deletes the mailbox $mailbox
    *
    * @param string $mailbox     mailbox name to delete
    *
    * @return mixed true on Success/PearError on Failure
    * @since 1.0
    */
    function deleteMailbox($mailbox)
    {
    // TODO verificar que el mailbox se encuentra vacio y, sino borrar los mensajes antes~!!!!!!
        $ret=$this->cmdDelete($mailbox);
        if(strtoupper($ret["RESPONSE"]["CODE"]) != "OK"){
            return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]);
        }
        return true;
    }









    /**
    * Renames the mailbox $mailbox
    *
    * @param string $mailbox     mailbox name to rename
    *
    * @return mixed true on Success/PearError on Failure
    * @since 1.0
    */
    function renameMailbox($oldmailbox, $newmailbox)
    {
        $ret=$this->cmdRename($oldmailbox,$newmailbox);
        if(strtoupper($ret["RESPONSE"]["CODE"]) != "OK"){
            return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]);
        }
        return true;
    }









    /******************************************************************
    **                                                               **
    **           SUBSCRIPTION METHODS                                **
    **                                                               **
    ******************************************************************/





    /**
    * Subscribes to the selected mailbox
    *
    * @param string $mailbox     mailbox name to subscribe
    *
    * @return mixed true on Success/PearError on Failure
    * @since 1.0
    */
    function subscribeMailbox($mailbox = null )
    {
        if($mailbox == null){
            $mailbox = $this->getCurrentMailbox();
        }
        $ret=$this->cmdSubscribe($mailbox);
        if(strtoupper($ret["RESPONSE"]["CODE"]) != "OK"){
            return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]);
        }
        return true;
    }





    /**
    * Removes the subscription to a mailbox
    *
    * @param string $mailbox     mailbox name to unsubscribe
    *
    * @return mixed true on Success/PearError on Failure
    * @since 1.0
    */
    function unsubscribeMailbox($mailbox = null)
    {
        if($mailbox == null){
            $mailbox = $this->getCurrentMailbox();
        }
        $ret=$this->cmdUnsubscribe($mailbox);
        if(strtoupper($ret["RESPONSE"]["CODE"]) != "OK"){
            return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]);
        }
        return true;
    }



    /**
    * Lists the subscription to mailboxes
    *
    * @param string $mailbox_base     mailbox name start the search (see to getMailboxes() )
    * @param string $mailbox_name     mailbox name filter the search (see to getMailboxes() )
    *
    * @return mixed true on Success/PearError on Failure
    * @since 1.0
    */

    function listsubscribedMailboxes($reference = ''  , $restriction_search = 0, $returnAttributes = false)
    {
        if ( is_bool($restriction_search) ){
            $restriction_search = (int) $restriction_search;
        }

        if ( is_int( $restriction_search ) ){
            switch ( $restriction_search ) {
                case 0:
                    $mailbox = "*";
                    break;
                case 1:
                    $mailbox = $reference;
                    $reference = '%';
                    break;
                case 2:
                    $mailbox = "%";
                    break;
            }
         }else{
            if ( is_string( $restriction_search ) ){
                $mailbox = $restriction_search;
            }else {
                return new PEAR_Error("UPS... you ");
            }
        }

        if( PEAR::isError( $ret=$this->cmdLsub($reference, $mailbox) ) ){
            return $ret;
        }
        //$ret=$this->cmdLsub($mailbox_base, $mailbox_name);


        if(strtoupper($ret["RESPONSE"]["CODE"]) != "OK"){
            return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]);
        }

        $ret_aux=array();
        if( isset($ret["PARSED"]) ){
            foreach( $ret["PARSED"] as $mbox ){
                if( isset($mbox["EXT"]["LSUB"]["MAILBOX_NAME"]) ){
                    if( $returnAttributes){
                            $ret_aux[]=array(
                                        'MAILBOX' => $mbox["EXT"]["LSUB"]["MAILBOX_NAME"],
                                        'ATTRIBUTES' => $mbox["EXT"]["LSUB"]["NAME_ATTRIBUTES"],
                                        'HIERACHY_DELIMITER' =>  $mbox["EXT"]["LSUB"]["HIERACHY_DELIMITER"]
                                        ) ;
                        }else{
                            $ret_aux[]=$mbox["EXT"]["LSUB"]["MAILBOX_NAME"];

                        }
                }
            }
        }
        return $ret_aux;
    }












    /******************************************************************
    **                                                               **
    **           FLAGS METHODS                                       **
    **                                                               **
    ******************************************************************/




    /**
    * Lists the flags of the selected messages
    *
    * @param mixes $msg_id  the message list
    *
    * @return mixed array on Success/PearError on Failure
    * @since 1.0
    */
    function getFlags( $msg_id = null )
    {
      // You can also provide an array of numbers to those emails
        if( $msg_id != null){
            if(is_array($msg_id)){
                $message_set=$this->_getSearchListFromArray($msg_id);
            }else{
                $message_set=$msg_id;
            }
        }else{
            $message_set="1:*";
        }


        $ret=$this->cmdFetch($message_set,"FLAGS");
        if(strtoupper($ret["RESPONSE"]["CODE"]) != "OK"){
            return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]);
        }
        $flags=array();
        if(isset($ret["PARSED"])){
            foreach($ret["PARSED"] as $msg_flags){
                if(isset($msg_flags["EXT"]["FLAGS"])){
                    $flags[]=$msg_flags["EXT"]["FLAGS"];
                }
            }
        }
        return $flags;
    }




   /**
    * check the Seen flag
    *
    * @param mixes $message_nro the message to check
    *
    * @return mixed true or false if the flag is sert PearError on Failure
    * @since 1.0
    */
    function isSeen($message_nro)
    {
        return $this->hasFlag( $message_nro, "\\Seen" );
    }




   /**
    * check the Answered flag
    *
    * @param mixes $message_nro the message to check
    *
    * @return mixed true or false if the flag is sert PearError on Failure
    * @since 1.0
    */
    function isAnswered($message_nro)
    {
        return $this->hasFlag( $message_nro, "\\Answered" );
    }





   /**
    * check the flagged flag
    *
    * @param mixes $message_nro the message to check
    *
    * @return mixed true or false if the flag is sert PearError on Failure
    * @since 1.0
    */
    function isFlagged($message_nro)
    {
        return $this->hasFlag( $message_nro, "\\Flagged" );
    }






   /**
    * check the Draft flag
    *
    * @param mixes $message_nro the message to check
    *
    * @return mixed true or false if the flag is sert PearError on Failure
    * @since 1.0
    */
    function isDraft($message_nro)
    {
        return $this->hasFlag( $message_nro, "\\Draft" );
    }







   /**
    * check the Deleted flag
    *
    * @param mixes $message_nro the message to check
    *
    * @return mixed true or false if the flag is sert PearError on Failure
    * @since 1.0
    */
    function isDeleted($message_nro)
    {
        return $this->hasFlag( $message_nro, "\\Deleted" );
    }






    function hasFlag($message_nro,$flag)
    {
        if ( PEAR::isError( $resp = $this->getFlags( $message_nro ) ) ) {
            return $resp;
        }
        if(isset($resp[0]) ){
            if( is_array( $resp[0] ) ){
                if( in_array( $flag , $resp[0] ) )
                    return true;
            }
        }
        return false;
    }





    /******************************************************************
    **                                                               **
    **           MISC METHODS                                        **
    **                                                               **
    ******************************************************************/






    /*
    * expunge function. Sends the EXPUNGE command
    *
    *
    * @return bool Success/Failure
    */
    function expunge()
    {
        $ret = $this->cmdExpunge();
        if( strtoupper( $ret["RESPONSE"]["CODE"]) != "OK" ){
            return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]);
        }
        return true;
    }







    /*
    * search function. Sends the SEARCH command
    *
    *
    * @return bool Success/Failure
    */
    function search($search_list,$uidSearch=false)
    {
        if($uidSearch){
            $ret = $this->cmdUidSearch($search_list);
        }else{
            $ret = $this->cmdSearch($search_list);
        }

        if( strtoupper( $ret["RESPONSE"]["CODE"]) != "OK" ){
            return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]);
        }
        return $ret["PARSED"]["SEARCH"]["SEARCH_LIST"];
    }








    /******************************************************************
    **                                                               **
    **           QUOTA METHODS                                       **
    **                                                               **
    ******************************************************************/






     /**
     * Returns STORAGE quota details
     * @param string $mailbox_name Mailbox to get quota info.
     * @return assoc array contaning the quota info  on success or PEAR_Error
     *
     * @access public
     * @since  1.0
     */
    function getStorageQuota($mailbox_name = null )
    {
       if($mailbox_name == null){
            $mailbox_name = $this->getCurrentMailbox();
        }


        if ( PEAR::isError( $ret = $this->cmdGetQuota($mailbox_name) ) ) {
            return new PEAR_Error($ret->getMessage());

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?