Net_IMAP
[ class tree: Net_IMAP ] [ index: Net_IMAP ] [ all elements ]

Source for file IMAP.php

Documentation is available at IMAP.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Damian Alejandro Fernandez Sosa <damlists@cnba.uba.ar>       |
  17. // +----------------------------------------------------------------------+
  18.  
  19.  
  20. require_once 'Net/IMAPProtocol.php';
  21.  
  22.  
  23. /**
  24.  * Provides an implementation of the IMAP protocol using PEAR's
  25.  * Net_Socket:: class.
  26.  *
  27.  * @package Net_IMAP
  28.  * @author  Damian Alejandro Fernandez Sosa <damlists@cnba.uba.ar>
  29.  */
  30. class Net_IMAP extends Net_IMAPProtocol {
  31.  
  32.     /**
  33.      * Constructor
  34.      *
  35.      * Instantiates a new Net_SMTP object, overriding any defaults
  36.      * with parameters that are passed in.
  37.      *
  38.      * @param string The server to connect to.
  39.      * @param int The port to connect to.
  40.      * @param string The value to give when sending EHLO or HELO.
  41.      */
  42.  
  43.     function Net_IMAP($host 'localhost'$port = 143)
  44.     {
  45.         $this->Net_IMAPProtocol();
  46.         $ret $this->connect$host $port );
  47.     }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.      /**
  55.      * Attempt to connect to the IMAP server located at $host $port
  56.      * @param string $host The IMAP server
  57.      * @param string $port The IMAP port
  58.      *
  59.      *           It is only useful in a very few circunstances
  60.      *           because the contructor already makes this job
  61.      * @return true on success or PEAR_Error
  62.      *
  63.      * @access public
  64.      * @since  1.0
  65.      */
  66.     function connect($host$port)
  67.     {
  68.         $ret=$this->cmdConnect($host,$port);
  69.         if($ret === true ){
  70.             // Determine server capabilities
  71.             $res $this->cmdCapability();
  72.  
  73.             // check if we can enable TLS via STARTTLS
  74.             if($this->hasCapability('STARTTLS'=== true && function_exists('stream_socket_enable_crypto'=== true{
  75.                 if (PEAR::isError($res $this->cmdStartTLS())) {
  76.                     return $res;
  77.                 }
  78.             }
  79.             return $ret;
  80.         }
  81.         if(empty($ret)){
  82.             return new PEAR_Error("Unexpected response on connection");
  83.         }
  84.         if(PEAR::isError($ret) ){
  85.             return $ret;
  86.         }
  87.         if(isset(    $ret["RESPONSE"]["CODE") ){
  88.             if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  89.                 return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  90.             }
  91.         }
  92.  
  93.         return $ret;
  94.     }
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.     /**
  106.      * Attempt to authenticate to the IMAP server.
  107.      * @param string $user The userid to authenticate as.
  108.      * @param string $pass The password to authenticate with.
  109.      * @param string $useauthenticate true: authenticate using
  110.      *         the IMAP AUTHENTICATE command. false: authenticate using
  111.      *         the IMAP AUTHENTICATE command. 'string': authenticate using
  112.      *         the IMAP AUTHENTICATE command but using the authMethod in 'string'
  113.      * @param boolean $selectMailbox automaticaly select inbox on login (false does not)
  114.      *
  115.      * @return true on success or PEAR_Error
  116.      *
  117.      * @access public
  118.      * @since  1.0
  119.      */
  120.  
  121.     function login($user$pass$useauthenticate = true$selectMailbox=true)
  122.     {
  123.         if $useauthenticate ){
  124.             //$useauthenticate is a string if the user hardcodes an AUTHMethod
  125.             // (the user calls $imap->login("user","password","CRAM-MD5"); for example!
  126.  
  127.             $method is_string$useauthenticate $useauthenticate : null;
  128.  
  129.             //Try the selected Auth method
  130.             if PEAR::isError$ret $this->cmdAuthenticate$user $pass $method  ) ) ) {
  131.                 // Verify the methods that we have in common with the server
  132.                 if(is_array($this->_serverAuthMethods)){
  133.                     $commonMethods=array_intersect ($this->supportedAuthMethods$this->_serverAuthMethods );
  134.                 }else{
  135.                     $this->_serverAuthMethods=null;
  136.                 }
  137.                 if($this->_serverAuthMethods == null  || count($commonMethods== 0 || $this->supportedAuthMethods == null ){
  138.                     // The server does not have any auth method, so I try LOGIN
  139.                     if PEAR::isError$ret $this->cmdLogin$user$pass ) ) ) {
  140.                         return $ret;
  141.                     }
  142.                 }else{
  143.                     return $ret;
  144.                 }
  145.             }
  146.             if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  147.                 return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  148.             }
  149.         }else{
  150.             //The user request "PLAIN"  auth, we use the login command
  151.             if PEAR::isError$ret $this->cmdLogin$user$pass ) ) ) {
  152.                 return $ret;
  153.             }
  154.             if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  155.                 return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  156.             }
  157.         }
  158.  
  159.         if($selectMailbox){
  160.             //Select INBOX
  161.             if PEAR::isError$ret=$this->cmdSelect$this->getCurrentMailbox() ) ) ) {
  162.                 return $ret;
  163.             }
  164.         }
  165.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  166.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  167.         }
  168.         return true;
  169.     }
  170.  
  171.  
  172.  
  173.  
  174.     /*
  175.     * Disconnect function. Sends the QUIT command
  176.     * and closes the socket.
  177.     *
  178.     * @return bool Success/Failure
  179.     */
  180.     function disconnect($expungeOnExit = false)
  181.     {
  182.         if($expungeOnExit){
  183.             $ret=$this->cmdExpunge();
  184.             if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  185.                 $ret=$this->cmdLogout();
  186.                 return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  187.             }
  188.         }
  189.         $ret=$this->cmdLogout();
  190.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  191.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  192.         }
  193.  
  194.         return true;
  195.     }
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.      /*
  204.     * Changes  the default/current mailbox th $mailbox
  205.     *
  206.     *
  207.     * @return bool Success/Pear_Error Failure
  208.     */
  209.     function selectMailbox($mailbox)
  210.     {
  211.         $ret=$this->cmdSelect($mailbox);
  212.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  213.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  214.         }
  215.         return true;
  216.     }
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.      /*
  225.     * Checks  the mailbox $mailbox
  226.     *
  227.     *
  228.     * @return bool Success/Pear_Error Failure
  229.     */
  230.     function examineMailbox($mailbox)
  231.     {
  232.         $ret=$this->cmdExamine($mailbox);
  233.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  234.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  235.         }
  236.  
  237.         //$ret_aux["EXISTS"]=$ret["PARSED"]["EXISTS"];
  238.         //$ret_aux["RECENT"]=$ret["PARSED"]["RECENT"];
  239.         $ret $ret["PARSED"];
  240.         return $ret;
  241.     }
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.     /*
  251.     * Returns the raw headers of the specified message.
  252.     *
  253.     * @param  $msg_id Message number
  254.     * @param  bool $uidFetch msg_id contains UID's instead of Message Sequence Number if set to true
  255.     * @return mixed   Either raw headers or false on error
  256.     */
  257.     function getRawHeaders($msg_id$part_id ''$uidFetch = false)
  258.     {
  259.         if($part_id != ''{
  260.           $command = "BODY[$part_id.HEADER]";
  261.         else {
  262.           $command "BODY[HEADER]";
  263.         }
  264.         if($uidFetch == true{
  265.           $ret=$this->cmdUidFetch($msg_id$command);
  266.         else {
  267.           $ret=$this->cmdFetch($msg_id$command);
  268.         }
  269.         if(strtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  270.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  271.         }
  272.         $ret=$ret["PARSED"][0]["EXT"][$command]["CONTENT"];
  273.         return $ret;
  274.     }
  275.  
  276.  
  277.  
  278.  
  279.     /*
  280.      * Returns the  headers of the specified message in an
  281.      * associative array. Array keys are the header names, array
  282.      * values are the header values. In the case of multiple headers
  283.      * having the same names, eg Received:, the array value will be
  284.      * an indexed array of all the header values.
  285.      *
  286.      * @param  int      $msg_id         Message number
  287.      * @param  boolean  $keysToUpper    false (default) original header names
  288.      *                                  true change keys (header names) toupper
  289.      * @param  bool    $uidFetch     msg_id contains UID's instead of Message Sequence Number if set to true
  290.      *
  291.      * @return mixed    Either array of headers or false on error
  292.      */
  293.     function getParsedHeaders($msg_id$keysToUpper = false$part_id ''$uidFetch = false)
  294.     {
  295.         $ret=$this->getRawHeaders($msg_id$part_id$uidFetch);
  296.  
  297.         $raw_headers rtrim($ret);
  298.         $raw_headers preg_replace("/\r\n[ \t]+/"' '$raw_headers)// Unfold headers
  299.         $raw_headers explode("\r\n"$raw_headers);
  300.         foreach ($raw_headers as $value{
  301.             $name  substr($value0$pos strpos($value':'));
  302.             if ($keysToUpper{
  303.                 $name strtoupper($name);
  304.             }
  305.             $value ltrim(substr($value$pos + 1));
  306.             if (isset($headers[$name]&& is_array($headers[$name])) {
  307.                 $headers[$name][$value;
  308.             elseif (isset($headers[$name])) {
  309.                 $headers[$name= array($headers[$name]$value);
  310.             else {
  311.                 $headers[$name$value;
  312.             }
  313.         }
  314.         return $headers;
  315.     }
  316.  
  317.  
  318.  
  319.  
  320.     /*
  321.     * Returns an array containing the message ID, the size and the UID
  322.     * of each message selected.
  323.     * message selection can be a valid IMAP command, a number or an array of
  324.     * messages
  325.     *
  326.     * @param  $msg_id Message number
  327.     * @return mixed   Either array of message data or PearError on error
  328.     */
  329.  
  330.     function getMessagesList($msg_id = null)
  331.     {
  332.         if$msg_id != null){
  333.             if(is_array($msg_id)){
  334.                 $message_set=$this->_getSearchListFromArray($msg_id);
  335.             }else{
  336.                 $message_set=$msg_id;
  337.             }
  338.         }else{
  339.             $message_set="1:*";
  340.         }
  341.         $ret=$this->cmdFetch($message_set,"(RFC822.SIZE UID)");
  342.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  343.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  344.         }
  345.         foreach($ret["PARSED"as $msg){
  346.             $ret_aux[]=array("msg_id"=>$msg["NRO"],"size" => $msg["EXT"]["RFC822.SIZE"],"uidl"=> $msg["EXT"]["UID"]);
  347.         }
  348.         return $ret_aux;
  349.     }
  350.  
  351.     /*
  352.      * @param  mixed      $msg_id         Message number
  353.      * @param  bool    $uidFetch     msg_id contains UID's instead of Message Sequence Number if set to true
  354.      *
  355.      * @return mixed    Either array of headers or PEAR::Error on error
  356.      */
  357.     function getSummary($msg_id = null$uidFetch = false)
  358.     {
  359.        if$msg_id != null){
  360.             if(is_array($msg_id)){
  361.                 $message_set=$this->_getSearchListFromArray($msg_id);
  362.             }else{
  363.                 $message_set=$msg_id;
  364.             }
  365.         }else{
  366.             $message_set="1:*";
  367.         }
  368.         if($uidFetch{
  369.           $ret=$this->cmdUidFetch($message_set,"(RFC822.SIZE UID FLAGS ENVELOPE INTERNALDATE BODY.PEEK[HEADER.FIELDS (CONTENT-TYPE)])");
  370.         else {
  371.           $ret=$this->cmdFetch($message_set,"(RFC822.SIZE UID FLAGS ENVELOPE INTERNALDATE BODY.PEEK[HEADER.FIELDS (CONTENT-TYPE)])");
  372.         }
  373.         #$ret=$this->cmdFetch($message_set,"(RFC822.SIZE UID FLAGS ENVELOPE INTERNALDATE BODY[1.MIME])");
  374.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  375.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  376.         }
  377.  
  378.         #print "<hr>"; var_dump($ret["PARSED"]); print "<hr>";
  379.  
  380.         if(isset$ret["PARSED") ){
  381.             for($i=0; $i<count($ret["PARSED"]$i++){
  382.                 $a=$ret["PARSED"][$i]['EXT']['ENVELOPE'];
  383.                 $a['MSG_NUM']=$ret["PARSED"][$i]['NRO'];
  384.                 $a['UID']=$ret["PARSED"][$i]['EXT']['UID'];
  385.                 $a['FLAGS']=$ret["PARSED"][$i]['EXT']['FLAGS'];
  386.                 $a['INTERNALDATE']=$ret["PARSED"][$i]['EXT']['INTERNALDATE'];
  387.                 $a['SIZE']=$ret["PARSED"][$i]['EXT']['RFC822.SIZE'];
  388.                 if(preg_match('/^content-type: (.*);/iU'$ret["PARSED"][$i]['EXT']['BODY[HEADER.FIELDS (CONTENT-TYPE)]']['CONTENT']$matches)) {
  389.                   $a['MIMETYPE']=strtolower($matches[1]);
  390.                 }
  391.                 $env[]=$a;
  392.                 $a=null;
  393.             }
  394.             return $env;
  395.         }
  396.  
  397.         //return $ret;
  398.     }
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.     /*
  407.     * Returns the body of the message with given message number.
  408.     *
  409.     * @param  $msg_id Message number
  410.     * @param  bool  $uidFetch  msg_id contains UID's instead of Message Sequence Number if set to true
  411.     * @return mixed   Either message body or false on error
  412.     */
  413.     function getBody($msg_id$uidFetch = false)
  414.     {
  415.         if($uidFetch{
  416.           $ret=$this->cmdUidFetch($msg_id,"BODY[TEXT]");
  417.         else {
  418.           $ret=$this->cmdFetch($msg_id,"BODY[TEXT]");
  419.         }
  420.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  421.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  422.         }
  423.         $ret=$ret["PARSED"][0]["EXT"]["BODY[TEXT]"]["CONTENT"];
  424.         //$ret=$resp["PARSED"][0]["EXT"]["RFC822"]["CONTENT"];
  425.         return $ret;
  426.     }
  427.  
  428.  
  429.     /*
  430.     * Returns the body of the message with given message number.
  431.     *
  432.     * @param  $msg_id Message number
  433.     * @param  string $partId Message number
  434.     * @param  bool  $uidFetch  msg_id contains UID's instead of Message Sequence Number if set to true
  435.     * @return mixed   Either message body or false on error
  436.     */
  437.     function getBodyPart($msg_id$partId$uidFetch = false)
  438.     {
  439.         if($uidFetch{
  440.           $ret=$this->cmdUidFetch($msg_id,"BODY[$partId]");
  441.         else {
  442.           $ret=$this->cmdFetch($msg_id,"BODY[$partId]");
  443.         }
  444.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  445.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  446.         }
  447.         $ret=$ret["PARSED"][0]["EXT"]["BODY[$partId]"]["CONTENT"];
  448.         //$ret=$resp["PARSED"][0]["EXT"]["RFC822"]["CONTENT"];
  449.         return $ret;
  450.     }
  451.  
  452.  
  453.     /*
  454.     * Returns the body of the message with given message number.
  455.     *
  456.     * @param  $msg_id Message number
  457.     * @param  bool  $uidFetch  msg_id contains UID's instead of Message Sequence Number if set to true
  458.     * @return mixed   Either message body or false on error
  459.     */
  460.     function getStructure($msg_id$uidFetch = false)
  461.     {
  462.         #print "IMAP.php::getStructure<pre>";
  463.         #$this->setDebug(true);
  464.         #print "<pre>";
  465.         if($uidFetch{
  466.           $ret=$this->cmdUidFetch($msg_id,"BODYSTRUCTURE");
  467.         else {
  468.           $ret=$this->cmdFetch($msg_id,"BODYSTRUCTURE");
  469.         }
  470.  
  471.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  472.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  473.         }
  474.         $ret=$ret["PARSED"][0]["EXT"]["BODYSTRUCTURE"][0];
  475.         $structure = array();
  476.  
  477.         $mimeParts = array();
  478.         $this->_parseStructureArray($ret$mimeParts);
  479.  
  480.         return array_shift($mimeParts);
  481.     }
  482.  
  483.     function _parseStructureArray($_structure&$_mimeParts$_partID ''
  484.     {
  485.         // something went wrong
  486.         if(!is_array($_structure)) {
  487.           return false;
  488.         }
  489.  
  490.         #print "<hr>Net_IMAP::_parseStructureArray _partID: $_partID<br>";
  491.         $mimeParts = array();
  492.         $subPartID = 1;
  493.         $partID ($_partID == '''' $_partID.'.';
  494.         if(is_array($_structure[0])) {
  495.           $this->_parseStructureMultipartArray($_structure$_mimeParts$_partID);
  496.         else {
  497.           switch(strtoupper($_structure[0])) {
  498.             case 'TEXT':
  499.               $this->_parseStructureTextArray($_structure$_mimeParts$partID.$subPartID);
  500.               
  501.               break;
  502.  
  503.              case 'MESSAGE':
  504.               $this->_parseStructureMessageArray($_structure$_mimeParts$partID.$subPartID);
  505.                 
  506.               break;
  507.           }
  508.         }
  509.         
  510.     }
  511.     
  512.     function _parseStructureMultipartArray($_structure&$_mimeParts$_partID$_parentIsMessage = false
  513.     {
  514.         #print "Net_IMAP::_parseStructureMultipartArray _partID: $_partID<br>";
  515.         // a multipart/mixed get's no own id, if the parent is message/rfc822
  516.         // and multipart/report also not
  517.         if($_parentIsMessage == true && is_array($_structure[0]&& ($_structure[count($_structure)-5== 'mixed' || $_structure[count($_structure)-5== 'report')) {
  518.           // cut off at last .
  519.           $_partID substr($_partID0strrpos($_partID'.'));
  520.         }
  521.         $subPartID = 1;
  522.         $partID ($_partID == '''' $_partID.'.';
  523.         $subMimeParts = array();
  524.         foreach($_structure as $structurePart{
  525.           if(is_array($structurePart)) {
  526.             if(is_array($structurePart[0])) {
  527.               // another multipart inside the multipart
  528.               $this->_parseStructureMultipartArray($structurePart$subMimeParts$partID.$subPartID);
  529.             else {
  530.               switch(strtoupper($structurePart[0])) {
  531.                 case 'APPLICATION':
  532.                   $this->_parseStructureApplicationArray($structurePart$subMimeParts$partID.$subPartID);
  533.               
  534.                   break;
  535.  
  536.                  case 'IMAGE':
  537.                   $this->_parseStructureImageArray($structurePart$subMimeParts$partID.$subPartID);
  538.                   
  539.                   break;
  540.  
  541.                  case 'MESSAGE':
  542.                   $this->_parseStructureMessageArray($structurePart$subMimeParts$partID.$subPartID);
  543.                   
  544.                   break;
  545.  
  546.                 case 'TEXT':
  547.                   $this->_parseStructureTextArray($structurePart$subMimeParts$partID.$subPartID);
  548.               
  549.                   break;
  550.               }
  551.             }
  552.             $subPartID++;
  553.           else {
  554.             $part = new stdClass;
  555.             $part->type = 'MULTIPART';
  556.             $part->subType = strtoupper($structurePart);
  557.           
  558.             $part->subParts = $subMimeParts;
  559.           
  560.             if($_partID == ''{
  561.               $part->partID = 0;
  562.               $_mimeParts = array(0 => $part);
  563.             else {
  564.               $part->partID = $_partID;
  565.               $_mimeParts = array($_partID => $part);
  566.             }
  567.             
  568.             return;
  569.           }
  570.         }
  571.     }
  572.     
  573.     function _parseStructureImageArray($_structure&$_mimeParts$_partID
  574.     {
  575.         #print "Net_IMAP::_parseStructureImageArray _partID: $_partID<br>";
  576.         $part $this->_parseStructureCommonFields($_structure);
  577.         $part->cid = $_structure[3];
  578.         $part->partID = $_partID;
  579.         
  580.         $_mimeParts[$_partID$part;
  581.     }
  582.  
  583.     function _parseStructureApplicationArray($_structure&$_mimeParts$_partID
  584.     {
  585.         #print "Net_IMAP::_parseStructureApplicationArray _partID: $_partID<br>";
  586.         $part $this->_parseStructureCommonFields($_structure);
  587.         if(is_array($_structure[8])) {
  588.           if(isset($_structure[8][0]&& $_structure[8][0!= 'NIL'{
  589.             $part->disposition = strtoupper($_structure[8][0]);
  590.           }
  591.           if(is_array($_structure[8][1])) {
  592.             foreach($_structure[8][1as $key => $value{
  593.               if($key%2 == 0{
  594.                 $part->dparameters[strtoupper($_structure[8][1][$key])$_structure[8][1][$key+1];
  595.               }
  596.             }
  597.           }
  598.         }
  599.         $part->partID = $_partID;
  600.         
  601.         $_mimeParts[$_partID$part;
  602.     }
  603.  
  604.     function _parseStructureMessageArray($_structure&$_mimeParts$_partID)
  605.     {
  606.         #print "Net_IMAP::_parseStructureMessageArray _partID: $_partID<br>";
  607.         $part $this->_parseStructureCommonFields($_structure);
  608.         
  609.         if(is_array($_structure[8][0])) {
  610.           $this->_parseStructureMultipartArray($_structure[8]$subMimeParts$_partID.'.1'true);
  611.         else {
  612.           $this->_parseStructureArray($_structure[8]$subMimeParts$_partID);
  613.         }
  614.         
  615.         if(is_array($subMimeParts)) {
  616.           $part->subParts = $subMimeParts;
  617.         }
  618.         $part->partID = $_partID;
  619.  
  620.         $_mimeParts[$_partID$part;
  621.     }
  622.     
  623.     function _parseStructureTextArray($_structure&$_mimeParts$_partID
  624.     {
  625.         #print "Net_IMAP::_parseStructureTextArray _partID: $_partID<br>";
  626.         $part $this->_parseStructureCommonFields($_structure);
  627.         $part->lines = $_structure[7];
  628.         if(is_array($_structure[8])) {
  629.           if(isset($_structure[8][0]&& $_structure[8][0!= 'NIL'{
  630.             $part->disposition = strtoupper($_structure[8][0]);
  631.           }
  632.           if(is_array($_structure[8][1])) {
  633.             foreach($_structure[8][1as $key => $value{
  634.               if($key%2 == 0{
  635.                 $part->dparameters[strtoupper($_structure[8][1][$key])$_structure[8][1][$key+1];
  636.               }
  637.             }
  638.           }
  639.         }
  640.         $part->partID = $_partID;
  641.         
  642.         $_mimeParts[$_partID$part;
  643.     }
  644.  
  645.     function _parseStructureCommonFields(&$_structure
  646.     {
  647.         #print "Net_IMAP::_parseStructureTextArray _partID: $_partID<br>";
  648.         $part = new stdClass;
  649.         $part->type = strtoupper($_structure[0]);
  650.         $part->subType = strtoupper($_structure[1]);
  651.         if(is_array($_structure[2])) {
  652.           foreach($_structure[2as $key => $value{
  653.             if($key%2 == 0{
  654.               $part->parameters[strtoupper($_structure[2][$key])$_structure[2][$key+1];
  655.             }
  656.           }
  657.         }
  658.         $part->encoding = strtoupper($_structure[5]);
  659.         $part->bytes = $_structure[6];
  660.         
  661.         return $part;
  662.     }
  663.  
  664.     /*
  665.     * Returns the entire message with given message number.
  666.     *
  667.     * @param  $msg_id Message number
  668.     * @return mixed   Either entire message or false on error
  669.     */
  670.     function getMessages($msg_id = null$indexIsMessageNumber=true)
  671.     {
  672.         //$resp=$this->cmdFetch($msg_id,"(BODY[TEXT] BODY[HEADER])");
  673.         if$msg_id != null){
  674.             if(is_array($msg_id)){
  675.                 $message_set=$this->_getSearchListFromArray($msg_id);
  676.             }else{
  677.                 $message_set=$msg_id;
  678.             }
  679.         }else{
  680.             $message_set="1:*";
  681.         }
  682.  
  683.         $ret=$this->cmdFetch($message_set,"RFC822");
  684.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  685.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  686.         }
  687.         if(isset($ret["PARSED"])){
  688.             foreach($ret["PARSED"as $msg){
  689.                 if(isset($msg["EXT"]["RFC822"]["CONTENT"])){
  690.                     if($indexIsMessageNumber){
  691.                         $ret_aux[$msg["NRO"]]=$msg["EXT"]["RFC822"]["CONTENT"];
  692.                     }else{
  693.                         $ret_aux[]=$msg["EXT"]["RFC822"]["CONTENT"];
  694.                     }
  695.         }
  696.             }
  697.             return $ret_aux;
  698.        }
  699.        return array();
  700.     }
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.     /*
  713.     * Returns number of messages in this mailbox
  714.     *
  715.     * @param  string $mailbox  the mailbox
  716.     * @return mixed Either number of messages or Pear_Error on error
  717.     */
  718.     function getNumberOfMessages($mailbox '')
  719.     {
  720.         if $mailbox == '' || $mailbox == null ){
  721.             $mailbox=$this->getCurrentMailbox();
  722.         }
  723.         $ret=$this->cmdStatus$mailbox "MESSAGES" );
  724.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  725.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  726.         }
  727.         ifisset($ret["PARSED"]["STATUS"]["ATTRIBUTES"]["MESSAGES") ){
  728.             if!is_numeric$ret["PARSED"]["STATUS"]["ATTRIBUTES"]["MESSAGES") ){
  729.                 // if this array does not exists means that there is no messages in the mailbox
  730.                 return 0;
  731.             }else{
  732.                 return $ret["PARSED"]["STATUS"]["ATTRIBUTES"]["MESSAGES"];
  733.             }
  734.  
  735.         }
  736.         return 0;
  737.     }
  738.  
  739.  
  740.     /*
  741.     * Returns number of UnSeen messages in this mailbox
  742.     *
  743.     * @param  string $mailbox  the mailbox
  744.     * @return mixed Either number of messages or Pear_Error on error
  745.     */
  746.     function getNumberOfUnSeenMessages($mailbox '')
  747.     {
  748.         if $mailbox == '' ){
  749.             $mailbox=$this->getCurrentMailbox();
  750.         }
  751.         $ret=$this->cmdStatus$mailbox "UNSEEN" );
  752.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  753.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  754.         }
  755.         ifisset($ret["PARSED"]["STATUS"]["ATTRIBUTES"]["UNSEEN") ){
  756.             if!is_numeric$ret["PARSED"]["STATUS"]["ATTRIBUTES"]["UNSEEN") ){
  757.                 // if this array does not exists means that there is no messages in the mailbox
  758.                 return 0;
  759.             }else{
  760.                 return $ret["PARSED"]["STATUS"]["ATTRIBUTES"]["UNSEEN"];
  761.             }
  762.  
  763.         }
  764.         return 0;
  765.     }
  766.  
  767.     /*
  768.     * Returns number of UnSeen messages in this mailbox
  769.     *
  770.     * @param  string $mailbox  the mailbox
  771.     * @return mixed Either number of messages or Pear_Error on error
  772.     */
  773.     function getNumberOfRecentMessages($mailbox '')
  774.     {
  775.         if $mailbox == '' ){
  776.             $mailbox=$this->getCurrentMailbox();
  777.         }
  778.         $ret=$this->cmdStatus$mailbox "RECENT" );
  779.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  780.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  781.         }
  782.         ifisset($ret["PARSED"]["STATUS"]["ATTRIBUTES"]["RECENT") ){
  783.             if!is_numeric$ret["PARSED"]["STATUS"]["ATTRIBUTES"]["RECENT") ){
  784.                 // if this array does not exists means that there is no messages in the mailbox
  785.                 return 0;
  786.             }else{
  787.                 return $ret["PARSED"]["STATUS"]["ATTRIBUTES"]["RECENT"];
  788.             }
  789.  
  790.         }
  791.         return 0;
  792.     }
  793.  
  794.     /*
  795.     * Returns number of UnSeen messages in this mailbox
  796.     *
  797.     * @param  string $mailbox  the mailbox
  798.     * @return mixed Either number of messages or Pear_Error on error
  799.     */
  800.     function getStatus($mailbox '')
  801.     {
  802.         if $mailbox == '' ){
  803.             $mailbox=$this->getCurrentMailbox();
  804.         }
  805.         $ret=$this->cmdStatus$mailbox array('MESSAGES''RECENT''UIDNEXT''UIDVALIDITY''UNSEEN') );
  806.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  807.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  808.         }
  809.         ifisset($ret["PARSED"]["STATUS"]["ATTRIBUTES"]["RECENT") ){
  810.                 return $ret["PARSED"]["STATUS"]["ATTRIBUTES"];
  811.         }
  812.         return 0;
  813.     }
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.     /*
  822.     * Returns an array containing the message envelope
  823.     *
  824.     * @todo $mailbox get's not used anywhere
  825.     * @param  mixed $msg_id Message number
  826.     * @param  bool  $uidFetch  msg_id contains UID's instead of Message Sequence Number if set to true
  827.     * @return mixed Either the envelopes or Pear_Error on error
  828.     */
  829.     function getEnvelope($mailbox ''$msg_id = null$uidFetch = false)
  830.     {
  831.         if $mailbox == '' ){
  832.             $mailbox=$this->getCurrentMailbox();
  833.         }
  834.  
  835.         if$msg_id != null){
  836.             if(is_array($msg_id)){
  837.                 $message_set=$this->_getSearchListFromArray($msg_id);
  838.             }else{
  839.                 $message_set=$msg_id;
  840.             }
  841.         }else{
  842.             $message_set="1:*";
  843.         }
  844.  
  845.  
  846.         if($uidFetch{
  847.           $ret=$this->cmdUidFetch($message_set,"ENVELOPE");
  848.         else {
  849.           $ret=$this->cmdFetch($message_set,"ENVELOPE");
  850.         }
  851.  
  852.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  853.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  854.         }
  855.  
  856.         if(isset$ret["PARSED") ){
  857.             for($i=0; $i<count($ret["PARSED"]$i++){
  858.                 $a=$ret["PARSED"][$i]['EXT']['ENVELOPE'];
  859.                 $a['MSG_NUM']=$ret["PARSED"][$i]['NRO'];
  860.                 $env[]=$a;
  861.             }
  862.             return $env;
  863.         }
  864.         return new PEAR_Error('Error, undefined number of messages');
  865.  
  866.  
  867.     }
  868.  
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.     /*
  878.     * Returns the sum of all the sizes of messages in $mailbox
  879.     *           WARNING!!!  The method's performance is not good
  880.     *                       if you have a lot of messages in the mailbox
  881.     *                       Use with care!
  882.     * @return mixed Either size of maildrop or false on error
  883.     */
  884.     function getMailboxSize($mailbox '')
  885.     {
  886.  
  887.         if $mailbox != '' && $mailbox != $this->getCurrentMailbox() ){
  888.             // store the actual selected mailbox name
  889.             $mailbox_aux $this->getCurrentMailbox();
  890.             if PEAR::isError$ret $this->selectMailbox$mailbox ) ) ) {
  891.                 return $ret;
  892.             }
  893.         }
  894.  
  895.         $ret=$this->cmdFetch("1:*","RFC822.SIZE");
  896.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  897.                 // Restore the default mailbox if it was changed
  898.                 if $mailbox != '' && $mailbox != $this->getCurrentMailbox() ){
  899.                     if PEAR::isError$ret $this->selectMailbox$mailbox_aux ) ) ) {
  900.                         return $ret;
  901.                     }
  902.                 }
  903.                 // return 0 because the server says that there is no message in the mailbox
  904.                 return 0;
  905.         }
  906.  
  907.         $sum=0;
  908.  
  909.         if(!isset($ret["PARSED"]) ){
  910.             // if the server does not return a "PARSED"  part
  911.             // we think that it does not suppoprt select or has no messages in it.
  912.             return 0;
  913.         }
  914.         foreach($ret["PARSED"as $msgSize){
  915.             ifisset($msgSize["EXT"]["RFC822.SIZE"]) ){
  916.                 $sum+= $msgSize["EXT"]["RFC822.SIZE"];
  917.             }
  918.         }
  919.  
  920.         if $mailbox != '' && $mailbox != $this->getCurrentMailbox() ){
  921.             // re-select the  mailbox
  922.             if PEAR::isError$ret $this->selectMailbox$mailbox_aux ) ) ) {
  923.                 return $ret;
  924.             }
  925.         }
  926.  
  927.         return $sum;
  928.     }
  929.  
  930.  
  931.  
  932.  
  933.  
  934.  
  935.  
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943.     /*
  944.     * Marks a message for deletion. Only will be deleted if the
  945.     * disconnect() method is called with auto-expunge on true or expunge()
  946.     * method is called.
  947.     *
  948.     * @param  $msg_id Message to delete
  949.     * @param  bool $uidStore msg_id contains UID's instead of Message Sequence Number if set to true
  950.     * @return bool Success/Failure
  951.     */
  952.     function deleteMessages($msg_id = null$uidStore = false)
  953.     {
  954.         /* As said in RFC2060...
  955.         C: A003 STORE 2:4 +FLAGS (\Deleted)
  956.                 S: * 2 FETCH FLAGS (\Deleted \Seen)
  957.                 S: * 3 FETCH FLAGS (\Deleted)
  958.                 S: * 4 FETCH FLAGS (\Deleted \Flagged \Seen)
  959.                 S: A003 OK STORE completed
  960.         */
  961.         //Called without parammeters deletes all the messages in the mailbox
  962.         // You can also provide an array of numbers to delete those emails
  963.         if$msg_id != null){
  964.             if(is_array($msg_id)){
  965.                 $message_set=$this->_getSearchListFromArray($msg_id);
  966.             }else{
  967.                 $message_set=$msg_id;
  968.             }
  969.         }else{
  970.             $message_set="1:*";
  971.         }
  972.  
  973.  
  974.         $dataitem="+FLAGS.SILENT";
  975.         $value="\Deleted";
  976.         if($uidStore == true{
  977.           $ret=$this->cmdUidStore($message_set,$dataitem,$value);
  978.         else {
  979.           $ret=$this->cmdStore($message_set,$dataitem,$value);
  980.         }
  981.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  982.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  983.         }
  984.         return true;
  985.     }
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.     /**
  996.     * Copies mail from one folder to another
  997.     *
  998.     * @param string $dest_mailbox       mailbox name to copy sessages to
  999.     * @param mixed $msg_id              the messages that I want to copy (all by default) it also
  1000.     *                                      can be an array
  1001.     * @param string $source_mailbox     mailbox name from where the messages are copied
  1002.     * @param bool $uidCopy              msg_id contains UID's instead of Message Sequence Number if set to true
  1003.     *
  1004.     * @return mixed true on Success/PearError on Failure
  1005.     * @since 1.0
  1006.     */
  1007.     function copyMessages($dest_mailbox$msg_id = null $source_mailbox = null$uidCopy = false )
  1008.     {
  1009.  
  1010.         if($source_mailbox == null){
  1011.             $source_mailbox $this->getCurrentMailbox();
  1012.         }else{
  1013.             if PEAR::isError$ret $this->selectMailbox$source_mailbox  ) ) ) {
  1014.                 return $ret;
  1015.             }
  1016.         }
  1017.         //Called without parammeters copies all messages in the mailbox
  1018.         // You can also provide an array of numbers to copy those emails
  1019.         if$msg_id != null){
  1020.             if(is_array($msg_id)){
  1021.                 $message_set=$this->_getSearchListFromArray($msg_id);
  1022.             }else{
  1023.                 $message_set=$msg_id;
  1024.             }
  1025.         }else{
  1026.             $message_set="1:*";
  1027.         }
  1028.  
  1029.         if($uidCopy == true{
  1030.           $ret $this->cmdUidCopy($message_set$dest_mailbox );
  1031.         else {
  1032.           $ret $this->cmdCopy($message_set$dest_mailbox );
  1033.         }
  1034.         if PEAR::isError$ret ) ) {
  1035.             return $ret;
  1036.         }
  1037.         return true;
  1038.     }
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.     /**
  1053.     * Appends a mail to  a mailbox
  1054.     *
  1055.     * @param string $rfc_message    the message to append in RFC822 format
  1056.     * @param string $mailbox        mailbox name to append to
  1057.     *
  1058.     * @return mixed true on Success/PearError on Failure
  1059.     * @since 1.0
  1060.     */
  1061.     function appendMessage($rfc_message$mailbox = null $flags_list '')
  1062.     {
  1063.         if($mailbox == null){
  1064.             $mailbox $this->getCurrentMailbox();
  1065.         }
  1066.         $ret=$this->cmdAppend($mailbox,$rfc_message,$flags_list);
  1067.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  1068.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1069.         }
  1070.         return true;
  1071.     }
  1072.  
  1073.  
  1074.     /**
  1075.     * Appends a mail to  a mailbox
  1076.     *
  1077.     * @param string $rfc_message    the message to append in RFC822 format
  1078.     * @param string $mailbox        mailbox name to append to
  1079.     *
  1080.     * @return mixed true on Success/PearError on Failure
  1081.     * @since 1.0
  1082.     */
  1083.     function getNamespace()
  1084.     {
  1085.         $ret=$this->cmdNamespace();
  1086.         if(strtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  1087.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1088.         }
  1089.  
  1090.         foreach($ret["PARSED"]["NAMESPACES"as $type => $singleNameSpace{
  1091.           if(is_array($singleNameSpace)) {
  1092.             foreach ($singleNameSpace as $nameSpaceData{
  1093.               $nameSpaces[$type][= array(
  1094.                 'name'        => $this->utf_7_decode($nameSpaceData[0]),
  1095.                 'delimter'    => $this->utf_7_decode($nameSpaceData[1])
  1096.               );
  1097.             }
  1098.           }
  1099.         }
  1100.         
  1101.         return $nameSpaces;
  1102.     }
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.     /******************************************************************
  1119.     **                                                               **
  1120.     **           MAILBOX RELATED METHODS                             **
  1121.     **                                                               **
  1122.     ******************************************************************/
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.     /**
  1129.     * Gets the HierachyDelimiter character used to create subfolders  cyrus users "."
  1130.     *   and wu-imapd uses "/"
  1131.     *
  1132.     * $param  string  the mailbox to get the hierarchy from
  1133.     * @return string  the hierarchy delimiter
  1134.     *
  1135.     * @access public
  1136.     * @since  1.0
  1137.     */
  1138.     function getHierarchyDelimiter$mailbox '' )
  1139.     {
  1140.  
  1141.         /* RFC2060 says: "the command LIST "" "" means get the hierachy delimiter:
  1142.                     An empty ("" string) mailbox name argument is a special request to
  1143.             return the hierarchy delimiter and the root name of the name given
  1144.             in the reference.  The value returned as the root MAY be null if
  1145.             the reference is non-rooted or is null.  In all cases, the
  1146.             hierarchy delimiter is returned.  This permits a client to get the
  1147.             hierarchy delimiter even when no mailboxes by that name currently
  1148.             exist."
  1149.         */
  1150.         ifPEAR::isError$ret $this->cmdList$mailbox '' )  ) ){
  1151.             return $ret;
  1152.         }
  1153.         if(isset($ret["PARSED"][0]["EXT"]["LIST"]["HIERACHY_DELIMITER"]) ){
  1154.             return $ret["PARSED"][0]["EXT"]["LIST"]["HIERACHY_DELIMITER"];
  1155.         }
  1156.         return new PEAR_Error'the IMAP Server does not support HIERACHY_DELIMITER!' );
  1157.     }
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.     /**
  1167.     * Returns an array containing the names of the selected mailboxes
  1168.     *
  1169.     * @param string $mailbox_base         base mailbox to start the search
  1170.     *                    $mailbox_base     if $mailbox_base == ''     then $mailbox_base is the curent selected mailbox
  1171.     * @param string $restriction_search   false or 0 means return all mailboxes  true or 1 return only the mailbox that contains that exact name
  1172.                                             2  return all mailboxes in that hierarchy level
  1173.     * @param string $returnAttributes     true means return an assoc array containing mailbox names and mailbox attributes
  1174.                                           false - the default - means return an array of mailboxes
  1175.     *
  1176.     * @return mixed true on Success/PearError on Failure
  1177.     * @since 1.0
  1178.     */
  1179.  
  1180.  
  1181.  
  1182.     function getMailboxes($reference ''  $restriction_search = 0$returnAttributes=false )
  1183.     {
  1184.  
  1185.         if is_bool($restriction_search) ){
  1186.             $restriction_search = (int) $restriction_search;
  1187.         }
  1188.  
  1189.         if is_int$restriction_search ) ){
  1190.             switch $restriction_search {
  1191.                 case 0:
  1192.                     $mailbox "*";
  1193.                     break;
  1194.                 case 1:
  1195.                     $mailbox $reference;
  1196.                     $reference '%';
  1197.                     break;
  1198.                 case 2:
  1199.                     $mailbox "%";
  1200.                     break;
  1201.             }
  1202.          }else{
  1203.             if is_string$restriction_search ) ){
  1204.                 $mailbox $restriction_search;
  1205.             }else {
  1206.                 return new PEAR_Error("UPS... you ");
  1207.             }
  1208.         }
  1209.  
  1210.         ifPEAR::isError$ret $this->cmdList($reference$mailbox) ) ){
  1211.             return $ret;
  1212.         }
  1213.  
  1214.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  1215.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1216.         }
  1217.         $ret_aux=array();
  1218.         ifisset($ret["PARSED"]) ){
  1219.             foreach$ret["PARSED"as $mbox ){
  1220.  
  1221.             //If the folder has the \NoSelect atribute we don't put in the list
  1222.             // it solves a bug in wu-imap that crash the IMAP server if we select that mailbox
  1223.                 ifisset($mbox["EXT"]["LIST"]["NAME_ATTRIBUTES"]) ){
  1224.                     if!in_array('\NoSelect',$mbox["EXT"]["LIST"]["NAME_ATTRIBUTES"]) ){
  1225.                         if$returnAttributes){
  1226.                             $ret_aux[]=array(   'MAILBOX' => $mbox["EXT"]["LIST"]["MAILBOX_NAME"],
  1227.                                                 'ATTRIBUTES' => $mbox["EXT"]["LIST"]["NAME_ATTRIBUTES",
  1228.                                                 'HIERACHY_DELIMITER' => $mbox["EXT"]["LIST"]["HIERACHY_DELIMITER";
  1229.                         }else{
  1230.                             $ret_aux[]=$mbox["EXT"]["LIST"]["MAILBOX_NAME"];
  1231.                         }
  1232.                     }
  1233.                 }
  1234.             }
  1235.         }
  1236.         return $ret_aux;
  1237.     }
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.     /**
  1244.     * check if the mailbox name exists
  1245.     *
  1246.     * @param string $mailbox     mailbox name to check existance
  1247.     *
  1248.     * @return boolean true on Success/false on Failure
  1249.     * @since 1.0
  1250.     */
  1251.  
  1252.     function mailboxExist($mailbox)
  1253.     {
  1254.         // true means do an exact match
  1255.         ifPEAR::isError$ret $this->getMailboxes$mailbox true ) ) ){
  1256.             return $ret;
  1257.         }
  1258.         ifcount$ret > 0 ){
  1259.             foreach ($ret as $mailbox_name{
  1260.                 if ($mailbox_name == $mailbox{
  1261.                     return true;
  1262.                 }
  1263.             }
  1264.         }
  1265.         return false;
  1266.     }
  1267.  
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274.     /**
  1275.     * Creates the mailbox $mailbox
  1276.     *
  1277.     * @param string $mailbox     mailbox name to create
  1278.     * @param array  $options     options to pass to create
  1279.     *
  1280.     * @return mixed true on Success/PearError on Failure
  1281.     * @since 1.0
  1282.     */
  1283.     function createMailbox($mailbox$options = null)
  1284.     {
  1285.         $ret=$this->cmdCreate($mailbox$options);
  1286.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  1287.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1288.         }
  1289.         return true;
  1290.     }
  1291.  
  1292.  
  1293.  
  1294.     /**
  1295.     * Deletes the mailbox $mailbox
  1296.     *
  1297.     * @param string $mailbox     mailbox name to delete
  1298.     *
  1299.     * @return mixed true on Success/PearError on Failure
  1300.     * @since 1.0
  1301.     */
  1302.     function deleteMailbox($mailbox)
  1303.     {
  1304.     // TODO verificar que el mailbox se encuentra vacio y, sino borrar los mensajes antes~!!!!!!
  1305.         $ret=$this->cmdDelete($mailbox);
  1306.         if (PEAR::isError($ret)) {
  1307.             return $ret;
  1308.         }
  1309.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  1310.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1311.         }
  1312.         return true;
  1313.     }
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.     /**
  1324.     * Renames the mailbox $mailbox
  1325.     *
  1326.     * @param string $mailbox     mailbox name to rename
  1327.     * @param array  $options     options to pass to rename
  1328.     *
  1329.     * @return mixed true on Success/PearError on Failure
  1330.     * @since 1.0
  1331.     */
  1332.     function renameMailbox($oldmailbox$newmailbox$options = null)
  1333.     {
  1334.         $ret=$this->cmdRename($oldmailbox,$newmailbox,$options);
  1335.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  1336.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1337.         }
  1338.         return true;
  1339.     }
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.     /******************************************************************
  1350.     **                                                               **
  1351.     **           SUBSCRIPTION METHODS                                **
  1352.     **                                                               **
  1353.     ******************************************************************/
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.     /**
  1360.     * Subscribes to the selected mailbox
  1361.     *
  1362.     * @param string $mailbox     mailbox name to subscribe
  1363.     *
  1364.     * @return mixed true on Success/PearError on Failure
  1365.     * @since 1.0
  1366.     */
  1367.     function subscribeMailbox($mailbox = null )
  1368.     {
  1369.         if($mailbox == null){
  1370.             $mailbox $this->getCurrentMailbox();
  1371.         }
  1372.         $ret=$this->cmdSubscribe($mailbox);
  1373.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  1374.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1375.         }
  1376.         return true;
  1377.     }
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.     /**
  1384.     * Removes the subscription to a mailbox
  1385.     *
  1386.     * @param string $mailbox     mailbox name to unsubscribe
  1387.     *
  1388.     * @return mixed true on Success/PearError on Failure
  1389.     * @since 1.0
  1390.     */
  1391.     function unsubscribeMailbox($mailbox = null)
  1392.     {
  1393.         if($mailbox == null){
  1394.             $mailbox $this->getCurrentMailbox();
  1395.         }
  1396.         $ret=$this->cmdUnsubscribe($mailbox);
  1397.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  1398.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1399.         }
  1400.         return true;
  1401.     }
  1402.  
  1403.  
  1404.  
  1405.     /**
  1406.     * Lists the subscription to mailboxes
  1407.     *
  1408.     * @param string $mailbox_base     mailbox name start the search (see to getMailboxes() )
  1409.     * @param string $mailbox_name     mailbox name filter the search (see to getMailboxes() )
  1410.     *
  1411.     * @return mixed true on Success/PearError on Failure
  1412.     * @since 1.0
  1413.     */
  1414.  
  1415.     function listsubscribedMailboxes($reference ''  $restriction_search = 0$returnAttributes = false)
  1416.     {
  1417.         if is_bool($restriction_search) ){
  1418.             $restriction_search = (int) $restriction_search;
  1419.         }
  1420.  
  1421.         if is_int$restriction_search ) ){
  1422.             switch $restriction_search {
  1423.                 case 0:
  1424.                     $mailbox "*";
  1425.                     break;
  1426.                 case 1:
  1427.                     $mailbox $reference;
  1428.                     $reference '%';
  1429.                     break;
  1430.                 case 2:
  1431.                     $mailbox "%";
  1432.                     break;
  1433.             }
  1434.          }else{
  1435.             if is_string$restriction_search ) ){
  1436.                 $mailbox $restriction_search;
  1437.             }else {
  1438.                 return new PEAR_Error("UPS... you ");
  1439.             }
  1440.         }
  1441.  
  1442.         ifPEAR::isError$ret=$this->cmdLsub($reference$mailbox) ) ){
  1443.             return $ret;
  1444.         }
  1445.         //$ret=$this->cmdLsub($mailbox_base, $mailbox_name);
  1446.  
  1447.  
  1448.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  1449.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1450.         }
  1451.  
  1452.         $ret_aux=array();
  1453.         ifisset($ret["PARSED"]) ){
  1454.             foreach$ret["PARSED"as $mbox ){
  1455.                 ifisset($mbox["EXT"]["LSUB"]["MAILBOX_NAME"]) ){
  1456.                     if$returnAttributes){
  1457.                             $ret_aux[]=array(
  1458.                                         'MAILBOX' => $mbox["EXT"]["LSUB"]["MAILBOX_NAME"],
  1459.                                         'ATTRIBUTES' => $mbox["EXT"]["LSUB"]["NAME_ATTRIBUTES"],
  1460.                                         'HIERACHY_DELIMITER' =>  $mbox["EXT"]["LSUB"]["HIERACHY_DELIMITER"]
  1461.                                         ;
  1462.                         }else{
  1463.                             $ret_aux[]=$mbox["EXT"]["LSUB"]["MAILBOX_NAME"];
  1464.  
  1465.                         }
  1466.                 }
  1467.             }
  1468.         }
  1469.         return $ret_aux;
  1470.     }
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.     /******************************************************************
  1484.     **                                                               **
  1485.     **           FLAGS METHODS                                       **
  1486.     **                                                               **
  1487.     ******************************************************************/
  1488.  
  1489.  
  1490.  
  1491.  
  1492.     /**
  1493.     * Lists the flags of the selected messages
  1494.     *
  1495.     * @param mixes $msg_id  the message list
  1496.     *
  1497.     * @return mixed array on Success/PearError on Failure
  1498.     * @since 1.0
  1499.     */
  1500.     function getFlags$msg_id = null )
  1501.     {
  1502.       // You can also provide an array of numbers to those emails
  1503.         if$msg_id != null){
  1504.             if(is_array($msg_id)){
  1505.                 $message_set=$this->_getSearchListFromArray($msg_id);
  1506.             }else{
  1507.                 $message_set=$msg_id;
  1508.             }
  1509.         }else{
  1510.             $message_set="1:*";
  1511.         }
  1512.  
  1513.  
  1514.         $ret=$this->cmdFetch($message_set,"FLAGS");
  1515.         if(strtoupper($ret["RESPONSE"]["CODE"]!= "OK"){
  1516.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1517.         }
  1518.         $flags=array();
  1519.         if(isset($ret["PARSED"])){
  1520.             foreach($ret["PARSED"as $msg_flags){
  1521.                 if(isset($msg_flags["EXT"]["FLAGS"])){
  1522.                     $flags[]=$msg_flags["EXT"]["FLAGS"];
  1523.                 }
  1524.             }
  1525.         }
  1526.         return $flags;
  1527.     }
  1528.  
  1529.  
  1530.     /**
  1531.      * Sets the flags of the selected messages
  1532.      *
  1533.      * @param mixed  $msg_id  the message list or string "all" for all
  1534.      * @param mixed  $flags   flags to set (space separated String or array)
  1535.      * @param string $mod     "set" to set flags (default)
  1536.      *                         "add" to add flags
  1537.      *                         "remove" to remove flags
  1538.      * @param  $uidStore bool msg_id contains UID's instead of Message Sequence Number if set to true
  1539.      *
  1540.      * @return mixed    true on success/PearError on failure
  1541.      */
  1542.     function setFlags($msg_id$flags$mod 'set'$uidStore = false)
  1543.     {
  1544.         // you can also provide an array of numbers to those emails
  1545.         if ($msg_id == 'all'{
  1546.             $message_set '1:*';
  1547.         else {
  1548.             if (is_array($msg_id)) {
  1549.                 $message_set $this->_getSearchListFromArray($msg_id);
  1550.             else {
  1551.                 $message_set $msg_id;
  1552.             }
  1553.         }
  1554.         
  1555.         $flaglist '';
  1556.         if (is_array($flags)) {
  1557.             $flaglist implode(' '$flags);
  1558.         else {
  1559.             $flaglist $flags;
  1560.         }
  1561.         
  1562.         switch ($mod{
  1563.             case 'set':
  1564.                 $dataitem 'FLAGS';
  1565.                 break;
  1566.             case 'add':
  1567.                 $dataitem '+FLAGS';
  1568.                 break;
  1569.             case 'remove':
  1570.                 $dataitem '-FLAGS';
  1571.                 break;
  1572.             default:
  1573.                 // Wrong Input
  1574.                 return new PEAR_Error('wrong input $mod');
  1575.                 break;
  1576.         }
  1577.         
  1578.         if($uidStore == true{
  1579.           $ret=$this->cmdUidStore($message_set$dataitem$flaglist);
  1580.         else {
  1581.           $ret=$this->cmdStore($message_set$dataitem$flaglist);
  1582.         }
  1583.         
  1584.         if (strtoupper($ret['RESPONSE']['CODE']!= 'OK'{
  1585.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1586.         else {
  1587.             return true;
  1588.         }
  1589.     }
  1590.  
  1591.  
  1592.     /**
  1593.      * adds flags to the selected messages
  1594.      *
  1595.      * @param mixed $flags   flags to set (space separated String or array)
  1596.      * @param mixed $msg_id  the message list or string "all" for all
  1597.      *
  1598.      * @return mixed true on success/PearError on failure
  1599.      */
  1600.     function addFlags($msg_id$flags)
  1601.     {
  1602.         return $this->setFlags($msg_id$flags$mod 'add');
  1603.     }
  1604.  
  1605.  
  1606.     /**
  1607.      * adds the Seen flag (\Seen) to the selected messages
  1608.      *
  1609.      * @param mixed $msg_id  the message list or string "all" for all
  1610.      *
  1611.      * @return mixed true   on success/PearError on failure
  1612.      */
  1613.     function addSeen($msg_id)
  1614.     {
  1615.         return $this->setFlags($msg_id'\Seen'$mod 'add');
  1616.     }
  1617.  
  1618.  
  1619.     /**
  1620.      * adds the Answered flag (\Answered) to the selected messages
  1621.      *
  1622.      * @param mixed $msg_id  the message list or string "all" for all
  1623.      *
  1624.      * @return mixed    true on success/PearError on failure
  1625.      */
  1626.     function addAnswered($msg_id)
  1627.     {
  1628.         return $this->setFlags($msg_id'\Answered'$mod 'add');
  1629.     }
  1630.  
  1631.  
  1632.     /**
  1633.      * adds the Deleted flag (\Deleted) to the selected messages
  1634.      *
  1635.      * @param mixed $msg_id  the message list or string "all" for all
  1636.      *
  1637.      * @return mixed    true on success/PearError on failure
  1638.      */
  1639.     function addDeleted($msg_id)
  1640.     {
  1641.         return $this->setFlags($msg_id'\Deleted'$mod 'add');
  1642.     }
  1643.  
  1644.  
  1645.     /**
  1646.      * adds the Flagged flag (\Flagged) to the selected messages
  1647.      *
  1648.      * @param mixed $msg_id  the message list or string "all" for all
  1649.      *
  1650.      * @return mixed    true on success/PearError on failure
  1651.      */
  1652.     function addFlagged($msg_id)
  1653.     {
  1654.         return $this->setFlags($msg_id'\Flagged'$mod 'add');
  1655.     }
  1656.  
  1657.  
  1658.     /**
  1659.      * adds the Draft flag (\Draft) to the selected messages
  1660.      *
  1661.      * @param mixed $msg_id  the message list or string "all" for all
  1662.      *
  1663.      * @return mixed    true on success/PearError on failure
  1664.      */
  1665.     function addDraft($msg_id)
  1666.     {
  1667.         return $this->setFlags($msg_id'\Draft'$mod 'add');
  1668.     }
  1669.  
  1670.  
  1671.     /**
  1672.      * remove flags from the selected messages
  1673.      *
  1674.      * @param mixed $flags   flags to remove (space separated string or array)
  1675.      * @param mixed $msg_id  the message list or string "all" for all
  1676.      *
  1677.      * @return mixed    true on success/PearError on failure
  1678.      */
  1679.     function removeFlags($msg_id$flags)
  1680.     {
  1681.         return $this->setFlags($msg_id$flags$mod 'remove');
  1682.     }
  1683.  
  1684.  
  1685.     /**
  1686.      * remove the Seen flag (\Seen) from the selected messages
  1687.      *
  1688.      * @param mixed $msg_id  the message list or string "all" for all
  1689.      *
  1690.      * @return mixed    true on success/PearError on failure
  1691.      */
  1692.     function removeSeen($msg_id)
  1693.     {
  1694.         return $this->setFlags($msg_id'\Seen'$mod 'remove');
  1695.     }
  1696.  
  1697.  
  1698.     /**
  1699.      * remove the Answered flag (\Answered) from the selected messages
  1700.      *
  1701.      * @param mixed $msg_id  the message list or string "all" for all
  1702.      *
  1703.      * @return mixed    true on success/PearError on failure
  1704.      */
  1705.     function removeAnswered($msg_id)
  1706.     {
  1707.         return $this->setFlags($msg_id'\Answered'$mod 'remove');
  1708.     }
  1709.  
  1710.  
  1711.     /**
  1712.      * remove the Deleted flag (\Deleted) from the selected messages
  1713.      *
  1714.      * @param mixed $msg_id  the message list or string "all" for all
  1715.      *
  1716.      * @return mixed    true on success/PearError on failure
  1717.      */
  1718.     function removeDeleted($msg_id)
  1719.     {
  1720.         return $this->setFlags($msg_id'\Deleted'$mod 'remove');
  1721.     }
  1722.  
  1723.  
  1724.     /**
  1725.      * remove the Flagged flag (\Flagged) from the selected messages
  1726.      *
  1727.      * @param mixed $msg_id  the message list or string "all" for all
  1728.      *
  1729.      * @return mixed    true on success/PearError on failure
  1730.      */
  1731.     function removeFlagged($msg_id)
  1732.     {
  1733.         return $this->setFlags($msg_id'\Flagged'$mod 'remove');
  1734.     }
  1735.  
  1736.  
  1737.     /**
  1738.      * remove the Draft flag (\Draft) from the selected messages
  1739.      *
  1740.      * @param mixed $msg_id  the message list or string "all" for all
  1741.      *
  1742.      * @return mixed    true on success/PearError on failure
  1743.      */
  1744.     function removeDraft($msg_id)
  1745.     {
  1746.         return $this->setFlags($msg_id'\Draft'$mod 'remove');
  1747.     }
  1748.  
  1749.    /**
  1750.     * check the Seen flag
  1751.     *
  1752.     * @param mixes $message_nro the message to check
  1753.     *
  1754.     * @return mixed true or false if the flag is sert PearError on Failure
  1755.     * @since 1.0
  1756.     */
  1757.     function isSeen($message_nro)
  1758.     {
  1759.         return $this->hasFlag$message_nro"\\Seen" );
  1760.     }
  1761.  
  1762.  
  1763.  
  1764.  
  1765.    /**
  1766.     * check the Answered flag
  1767.     *
  1768.     * @param mixes $message_nro the message to check
  1769.     *
  1770.     * @return mixed true or false if the flag is sert PearError on Failure
  1771.     * @since 1.0
  1772.     */
  1773.     function isAnswered($message_nro)
  1774.     {
  1775.         return $this->hasFlag$message_nro"\\Answered" );
  1776.     }
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.    /**
  1783.     * check the flagged flag
  1784.     *
  1785.     * @param mixes $message_nro the message to check
  1786.     *
  1787.     * @return mixed true or false if the flag is sert PearError on Failure
  1788.     * @since 1.0
  1789.     */
  1790.     function isFlagged($message_nro)
  1791.     {
  1792.         return $this->hasFlag$message_nro"\\Flagged" );
  1793.     }
  1794.  
  1795.  
  1796.  
  1797.  
  1798.  
  1799.  
  1800.    /**
  1801.     * check the Draft flag
  1802.     *
  1803.     * @param mixes $message_nro the message to check
  1804.     *
  1805.     * @return mixed true or false if the flag is sert PearError on Failure
  1806.     * @since 1.0
  1807.     */
  1808.     function isDraft($message_nro)
  1809.     {
  1810.         return $this->hasFlag$message_nro"\\Draft" );
  1811.     }
  1812.  
  1813.  
  1814.  
  1815.  
  1816.  
  1817.  
  1818.  
  1819.    /**
  1820.     * check the Deleted flag
  1821.     *
  1822.     * @param mixes $message_nro the message to check
  1823.     *
  1824.     * @return mixed true or false if the flag is sert PearError on Failure
  1825.     * @since 1.0
  1826.     */
  1827.     function isDeleted($message_nro)
  1828.     {
  1829.         return $this->hasFlag$message_nro"\\Deleted" );
  1830.     }
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.     function hasFlag($message_nro,$flag)
  1838.     {
  1839.         if PEAR::isError$resp $this->getFlags$message_nro ) ) ) {
  1840.             return $resp;
  1841.         }
  1842.         if(isset($resp[0]) ){
  1843.             ifis_array$resp[0) ){
  1844.                 ifin_array$flag $resp[0) )
  1845.                     return true;
  1846.             }
  1847.         }
  1848.         return false;
  1849.     }
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.     /******************************************************************
  1856.     **                                                               **
  1857.     **           MISC METHODS                                        **
  1858.     **                                                               **
  1859.     ******************************************************************/
  1860.  
  1861.  
  1862.  
  1863.  
  1864.  
  1865.  
  1866.     /*
  1867.     * expunge function. Sends the EXPUNGE command
  1868.     *
  1869.     *
  1870.     * @return bool Success/Failure
  1871.     */
  1872.     function expunge()
  1873.     {
  1874.         $ret $this->cmdExpunge();
  1875.         ifstrtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  1876.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1877.         }
  1878.         return true;
  1879.     }
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.     /*
  1888.     * search function. Sends the SEARCH command
  1889.     *
  1890.     *
  1891.     * @return bool Success/Failure
  1892.     */
  1893.     function search($search_list$uidSearch = false)
  1894.     {
  1895.         if($uidSearch){
  1896.             $ret $this->cmdUidSearch($search_list);
  1897.         }else{
  1898.             $ret $this->cmdSearch($search_list);
  1899.         }
  1900.  
  1901.         ifstrtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  1902.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1903.         }
  1904.         return $ret["PARSED"]["SEARCH"]["SEARCH_LIST"];
  1905.     }
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.     /******************************************************************
  1915.     **                                                               **
  1916.     **           QUOTA METHODS                                       **
  1917.     **                                                               **
  1918.     ******************************************************************/
  1919.  
  1920.  
  1921.  
  1922.  
  1923.  
  1924.  
  1925.      /**
  1926.      * Returns STORAGE quota details
  1927.      * @param string $mailbox_name Mailbox to get quota info.
  1928.      * @return assoc array contaning the quota info  on success or PEAR_Error
  1929.      *
  1930.      * @access public
  1931.      * @since  1.0
  1932.      */
  1933.     function getStorageQuotaRoot($mailbox_name = null )
  1934.     {
  1935.        if($mailbox_name == null){
  1936.             $mailbox_name $this->getCurrentMailbox();
  1937.         }
  1938.  
  1939.  
  1940.         if PEAR::isError$ret $this->cmdGetQuotaRoot($mailbox_name) ) ) {
  1941.             return new PEAR_Error($ret->getMessage());
  1942.         }
  1943.  
  1944.         ifstrtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  1945.             // if the error is that the user does not have quota set return  an array
  1946.             // and not pear error
  1947.             ifsubstr(strtoupper($ret["RESPONSE"]["STR_CODE"]),0,9)  == "QUOTAROOT" ){
  1948.                 return array('USED'=>'NOT SET''QMAX'=>'NOT SET');
  1949.             }
  1950.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1951.         }
  1952.  
  1953.         ifisset$ret['PARSED']['EXT']['QUOTA']['STORAGE') ){
  1954.             return $ret['PARSED']['EXT']['QUOTA']['STORAGE'];
  1955.         }
  1956.         return array('USED'=>'NOT SET''QMAX'=>'NOT SET');
  1957.    }
  1958.  
  1959.      /**
  1960.      * Returns STORAGE quota details
  1961.      * @param string $mailbox_name Mailbox to get quota info.
  1962.      * @return assoc array contaning the quota info  on success or PEAR_Error
  1963.      *
  1964.      * @access public
  1965.      * @since  1.0
  1966.      */
  1967.     function getStorageQuota($mailbox_name = null )
  1968.     {
  1969.        if($mailbox_name == null){
  1970.             $mailbox_name $this->getCurrentMailbox();
  1971.         }
  1972.  
  1973.  
  1974.         if PEAR::isError$ret $this->cmdGetQuota($mailbox_name) ) ) {
  1975.             return new PEAR_Error($ret->getMessage());
  1976.         }
  1977.  
  1978.         ifstrtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  1979.             // if the error is that the user does not have quota set return  an array
  1980.             // and not pear error
  1981.             ifsubstr(strtoupper($ret["RESPONSE"]["STR_CODE"]),0,5)  == "QUOTA" ){
  1982.                 return array('USED'=>'NOT SET''QMAX'=>'NOT SET');
  1983.             }
  1984.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  1985.         }
  1986.  
  1987.         ifisset$ret['PARSED']['EXT']['QUOTA']['STORAGE') ){
  1988.             return $ret['PARSED']['EXT']['QUOTA']['STORAGE'];
  1989.         }
  1990.         return array('USED'=>'NOT SET''QMAX'=>'NOT SET');
  1991.    }
  1992.  
  1993.  
  1994.  
  1995.      /**
  1996.      * Returns MESSAGES quota details
  1997.      * @param string $mailbox_name Mailbox to get quota info.
  1998.      * @return assoc array contaning the quota info  on success or PEAR_Error
  1999.      *
  2000.      * @access public
  2001.      * @since  1.0
  2002.      */
  2003.     function getMessagesQuota($mailbox_name = null )
  2004.     {
  2005.        if($mailbox_name == null){
  2006.             $mailbox_name $this->getCurrentMailbox();
  2007.         }
  2008.  
  2009.         if PEAR::isError$ret $this->cmdGetQuota($mailbox_name) ) ) {
  2010.             return new PEAR_Error($ret->getMessage());
  2011.         }
  2012.  
  2013.         ifstrtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  2014.             // if the error is that the user does not have quota set return  an array
  2015.             // and not pear error
  2016.             ifsubstr(strtoupper($ret["RESPONSE"]["STR_CODE"]),0,5)  == "QUOTA" ){
  2017.                 return array('USED'=>'NOT SET''QMAX'=>'NOT SET');
  2018.             }
  2019.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  2020.         }
  2021.  
  2022.         ifisset$ret['PARSED']['EXT']['QUOTA']['MESSAGES') ){
  2023.             return $ret['PARSED']['EXT']['QUOTA']['MESSAGES'];
  2024.         }
  2025.         return array('USED'=>'NOT SET''QMAX'=>'NOT SET');
  2026.    }
  2027.  
  2028.  
  2029.  
  2030.  
  2031.      /**
  2032.      * sets STORAGE quota details
  2033.      * @param string $mailbox_name Mailbox to get quota info.
  2034.      * @return true on success or PEAR_Error
  2035.      *
  2036.      * @access public
  2037.      * @since  1.0
  2038.      */
  2039.     function setStorageQuota($mailbox_name$quota)
  2040.     {
  2041.         if PEAR::isError$ret $this->cmdSetQuota($mailbox_name,$quota) ) ) {
  2042.             return new PEAR_Error($ret->getMessage());
  2043.         }
  2044.         ifstrtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  2045.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  2046.         }
  2047.         return true;
  2048.     }
  2049.  
  2050.  
  2051.  
  2052.  
  2053.      /**
  2054.      * sets MESSAGES quota details
  2055.      * @param string $mailbox_name Mailbox to get quota info.
  2056.      * @return true on success or PEAR_Error
  2057.      *
  2058.      * @access public
  2059.      * @since  1.0
  2060.      */
  2061.     function setMessagesQuota($mailbox_name$quota)
  2062.     {
  2063.         if PEAR::isError$ret $this->cmdSetQuota($mailbox_name,'',$quota) ) ) {
  2064.             return new PEAR_Error($ret->getMessage());
  2065.         }
  2066.         ifstrtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  2067.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  2068.         }
  2069.         return true;
  2070.     }
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077.  
  2078.  
  2079.  
  2080.     /******************************************************************
  2081.     **                                                               **
  2082.     **           ACL METHODS                                         **
  2083.     **                                                               **
  2084.     ******************************************************************/
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.     /**
  2092.      * get the Access Control List details
  2093.      * @param string $mailbox_name Mailbox to get ACL info.
  2094.      * @return string on success or PEAR_Error
  2095.      *
  2096.      * @access public
  2097.      * @since  1.0
  2098.      */
  2099.     function getACL($mailbox_name = null )
  2100.     {
  2101.        if($mailbox_name == null){
  2102.             $mailbox_name $this->getCurrentMailbox();
  2103.         }
  2104.         if PEAR::isError$ret $this->cmdGetACL($mailbox_name) ) ) {
  2105.             return new PEAR_Error($ret->getMessage());
  2106.         }
  2107.  
  2108.         ifstrtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  2109.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  2110.         }
  2111.  
  2112.         ifisset($ret['PARSED']['USERS']) ){
  2113.         return $ret['PARSED']['USERS'];
  2114.         }else{
  2115.             return false;
  2116.         }
  2117.     }
  2118.  
  2119.  
  2120.  
  2121.  
  2122.  
  2123.  
  2124.  
  2125.  
  2126.     /**
  2127.     * Set ACL on a mailbox
  2128.     *
  2129.     * @param  string $mailbox_name  the mailbox
  2130.     * @param  string $user          user to set the ACL
  2131.     * @param  string $acl           ACL list
  2132.     * @return mixed                 True on success, or PEAR_Error on false
  2133.     *
  2134.     * @access public
  2135.     * @since  1.0
  2136.     */
  2137.     function setACL($mailbox_name$user$acl)
  2138.     {
  2139.         if PEAR::isError$ret $this->cmdSetACL($mailbox_name$user$acl) ) ) {
  2140.             return new PEAR_Error($ret->getMessage());
  2141.         }
  2142.         ifstrtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  2143.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  2144.         }
  2145.         return true;
  2146.     }
  2147.  
  2148.  
  2149.     /**
  2150.     * deletes the ACL on a mailbox
  2151.     *
  2152.     * @param  string $mailbox_name  the mailbox
  2153.     * @param  string $user          user to set the ACL
  2154.     * @return mixed                 True on success, or PEAR_Error on false
  2155.     *
  2156.     * @access public
  2157.     * @since  1.0
  2158.     */
  2159.     function deleteACL($mailbox_name$user)
  2160.     {
  2161.         if PEAR::isError$ret $this->cmdDeleteACL($mailbox_name$user) ) ) {
  2162.             return new PEAR_Error($ret->getMessage());
  2163.         }
  2164.         ifstrtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  2165.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  2166.         }
  2167.         return true;
  2168.     }
  2169.  
  2170.  
  2171.  
  2172.     /**
  2173.     * returns the rights that the user logged on has on the mailbox
  2174.     * this method can be used by any user, not only the administrator
  2175.     *
  2176.     * @param  string $mailbox_name  the mailbox to query rights
  2177.     * @return mixed                 string contailing the list of rights on success, or PEAR_Error on failure
  2178.     *
  2179.     * @access public
  2180.     * @since  1.0
  2181.     */
  2182.     function getMyRights($mailbox_name = null)
  2183.     {
  2184.  
  2185.         if($mailbox_name == null){
  2186.             $mailbox_name $this->getCurrentMailbox();
  2187.         }
  2188.  
  2189.  
  2190.         if PEAR::isError$ret $this->cmdMyRights($mailbox_name) ) ) {
  2191.             return new PEAR_Error($ret->getMessage());
  2192.         }
  2193.         ifstrtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  2194.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  2195.         }
  2196.  
  2197.         if(isset($ret['PARSED']['GRANTED'])){
  2198.             return $ret['PARSED']['GRANTED'];
  2199.         }
  2200.  
  2201.         return new PEAR_Error('Bogus response from server!' );
  2202.  
  2203.     }
  2204.  
  2205.  
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.     /**
  2214.     * returns an array containing the rights that a user logged on has on the mailbox
  2215.     * this method can be used by any user, not only the administrator
  2216.     *
  2217.     * @param  string $mailbox_name  the mailbox to query rights
  2218.     * @return mixed                 string contailing the list of rights on success, or PEAR_Error on failure
  2219.     *
  2220.     * @access public
  2221.     * @since  1.0
  2222.     */
  2223.     function getACLRights($user,$mailbox_name = null)
  2224.     {
  2225.  
  2226.         if($mailbox_name == null){
  2227.             $mailbox_name $this->getCurrentMailbox();
  2228.         }
  2229.  
  2230.  
  2231.         if PEAR::isError$ret $this->cmdListRights($mailbox_name$user) ) ) {
  2232.             return new PEAR_Error($ret->getMessage());
  2233.         }
  2234.         ifstrtoupper$ret["RESPONSE"]["CODE"]!= "OK" ){
  2235.             return new PEAR_Error($ret["RESPONSE"]["CODE"", " $ret["RESPONSE"]["STR_CODE"]);
  2236.         }
  2237.  
  2238.  
  2239.         if(isset($ret['PARSED']['GRANTED'])){
  2240.             return $ret['PARSED']['GRANTED'];
  2241.         }
  2242.  
  2243.         return new PEAR_Error('Bogus response from server!' );
  2244.  
  2245.     }
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251.  
  2252.  
  2253.  
  2254.  
  2255.  
  2256.  
  2257.  
  2258.     /******************************************************************
  2259.     **                                                               **
  2260.     **           ANNOTATEMORE METHODS                                **
  2261.     **                                                               **
  2262.     ******************************************************************/
  2263.  
  2264.  
  2265.  
  2266.  
  2267.  
  2268.  
  2269.     function setAnnotation($entry$values$mailbox_name = null )
  2270.     {
  2271.         if($mailbox_name == null){
  2272.             $mailbox_name $this->getCurrentMailbox();
  2273.         }
  2274.  
  2275.         if (PEAR::isError($ret $this->cmdSetAnnotation($mailbox_name$entry$values))) {
  2276.             return new PEAR_Error($ret->getMessage());
  2277.         }
  2278.         if (strtoupper($ret['RESPONSE']['CODE']!= 'OK'{
  2279.             return new PEAR_Error($ret['RESPONSE']['CODE'', ' $ret['RESPONSE']['STR_CODE']);
  2280.         }
  2281.         return true;
  2282.     }
  2283.  
  2284.  
  2285.  
  2286.  
  2287.  
  2288.  
  2289.     function deleteAnnotation($entry$values$mailbox_name = null )
  2290.     {
  2291.         if($mailbox_name == null){
  2292.             $mailbox_name $this->getCurrentMailbox();
  2293.         }
  2294.  
  2295.         if (PEAR::isError($ret $this->cmdDeleteAnnotation($mailbox_name$entry$values))) {
  2296.             return new PEAR_Error($ret->getMessage());
  2297.         }
  2298.         if (strtoupper($ret['RESPONSE']['CODE']!= 'OK'{
  2299.             return new PEAR_Error($ret['RESPONSE']['CODE'', ' $ret['RESPONSE']['STR_CODE']);
  2300.         }
  2301.         return true;
  2302.     }
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.     function getAnnotation($entries$values$mailbox_name = null)
  2310.     {
  2311.         if($mailbox_name == null){
  2312.             $mailbox_name $this->getCurrentMailbox();
  2313.         }
  2314.         if (!is_array($entries)) {
  2315.             $entries = array($entries);
  2316.         }
  2317.         if (!is_array($values)) {
  2318.             $values = array($values);
  2319.         }
  2320.  
  2321.         if (PEAR::isError($ret $this->cmdGetAnnotation($mailbox_name$entries$values))) {
  2322.             return new PEAR_Error($ret->getMessage());
  2323.         }
  2324.         if (strtoupper($ret['RESPONSE']['CODE']!= 'OK'{
  2325.             return new PEAR_Error($ret['RESPONSE']['CODE'', ' $ret['RESPONSE']['STR_CODE']);
  2326.         }
  2327.         $ret_aux = array();
  2328.         if (isset($ret['PARSED'])) {
  2329.             foreach ($ret['PARSED'as $mbox{
  2330.                 $rawvalues $mbox['EXT']['ATTRIBUTES'];
  2331.                 $values = array();
  2332.                 for ($i = 0; $i count($rawvalues)$i += 2{
  2333.                     $values[$rawvalues[$i]] $rawvalues[$i + 1];
  2334.                 }
  2335.                 $mbox['EXT']['ATTRIBUTES'$values;
  2336.                 $ret_aux[$mbox['EXT'];
  2337.             }
  2338.         }
  2339.         if (count($ret_aux== 1 && $ret_aux[0]['MAILBOX'== $mailbox_name{
  2340.             if (count($entries== 1 && $ret_aux[0]['ENTRY'== $entries[0]{
  2341.                 if (count($ret_aux[0]['ATTRIBUTES']== 1 && count($values== 1{
  2342.                     $attrs array_keys($ret_aux[0]['ATTRIBUTES']);
  2343.                     $vals array_keys($values);
  2344.                     if ($attrs[0== $vals[0]{
  2345.                         return $ret_aux[0]['ATTRIBUTES'][$attrs[0]];
  2346.                     }
  2347.                 }
  2348.             }
  2349.         }
  2350.         return $ret_aux;
  2351.     }
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  
  2359.  
  2360.  
  2361.     /*
  2362.     *   Transform an array to a list to be used in the cmdFetch method
  2363.     *
  2364.     */
  2365.     function _getSearchListFromArray($arr){
  2366.  
  2367.         $txt=implode(',' $arr);
  2368.         return $txt;
  2369.     }
  2370.  
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.     /*****************************************************
  2379.         Net_POP3 Compatibility functions:
  2380.  
  2381.         Warning!!!
  2382.             Those functions could dissapear in the future
  2383.  
  2384.     *********************************************************/
  2385.  
  2386.  
  2387.  
  2388.  
  2389.     function getSize(){
  2390.         return $this->getMailboxSize();
  2391.     }
  2392.  
  2393.  
  2394.     function numMsg($mailbox = null){
  2395.         return $this->getNumberOfMessages($mailbox);
  2396.     }
  2397.  
  2398.  
  2399.  
  2400.     /*
  2401.     * Returns the entire message with given message number.
  2402.     *
  2403.     * @param  $msg_id Message number
  2404.     * @return mixed   Either entire message or false on error
  2405.     */
  2406.     function getMsg($msg_id)
  2407.     {
  2408.         $ret=$this->getMessages($msg_id,false);
  2409.         // false means that getMessages() must not use the msg number as array key
  2410.         if(isset($ret[0])){
  2411.             return $ret[0];
  2412.         }else{
  2413.             return $ret;
  2414.         }
  2415.  
  2416.     }
  2417.  
  2418.  
  2419.     function getListing($msg_id = null)
  2420.     {
  2421.         return $this->getMessagesList($msg_id);
  2422.     }
  2423.  
  2424.  
  2425.     function deleteMsg($msg_id){
  2426.         return $this->deleteMessages($msg_id);
  2427.     }
  2428.  
  2429.  
  2430.  
  2431.  
  2432.  
  2433. }
  2434. ?>

Documentation generated on Mon, 11 Mar 2019 14:54:13 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.