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

Documentation generated on Mon, 02 Jan 2012 03:00:06 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.