| | |
| | | |
| | | public static $mupdate; |
| | | |
| | | private $fp; |
| | | private $host; |
| | | private $logged = false; |
| | | private $capability = array(); |
| | | private $capability_readed = false; |
| | | private $prefs; |
| | | private $cmd_tag; |
| | | private $cmd_num = 0; |
| | | private $resourceid; |
| | | private $_debug = false; |
| | | private $_debug_handler = false; |
| | | protected $fp; |
| | | protected $host; |
| | | protected $logged = false; |
| | | protected $capability = array(); |
| | | protected $capability_readed = false; |
| | | protected $prefs; |
| | | protected $cmd_tag; |
| | | protected $cmd_num = 0; |
| | | protected $resourceid; |
| | | protected $_debug = false; |
| | | protected $_debug_handler = false; |
| | | |
| | | const ERROR_OK = 0; |
| | | const ERROR_NO = -1; |
| | |
| | | * |
| | | * @return bool True if connection is closed |
| | | */ |
| | | private function eof() |
| | | protected function eof() |
| | | { |
| | | if (!is_resource($this->fp)) { |
| | | return true; |
| | |
| | | /** |
| | | * Closes connection stream. |
| | | */ |
| | | private function closeSocket() |
| | | protected function closeSocket() |
| | | { |
| | | @fclose($this->fp); |
| | | $this->fp = null; |
| | |
| | | return false; |
| | | } |
| | | |
| | | private function hasCapability($name) |
| | | protected function hasCapability($name) |
| | | { |
| | | if (empty($this->capability) || $name == '') { |
| | | return false; |
| | |
| | | * Folder creation (CREATE) |
| | | * |
| | | * @param string $mailbox Mailbox name |
| | | * @param array $types Optional folder types (RFC 6154) |
| | | * |
| | | * @return bool True on success, False on error |
| | | */ |
| | | function createFolder($mailbox) |
| | | function createFolder($mailbox, $types = null) |
| | | { |
| | | $result = $this->execute('CREATE', array($this->escape($mailbox)), |
| | | self::COMMAND_NORESPONSE); |
| | | $args = array($this->escape($mailbox)); |
| | | |
| | | // RFC 6154: CREATE-SPECIAL-USE |
| | | if (!empty($types) && $this->getCapability('CREATE-SPECIAL-USE')) { |
| | | $args[] = '(USE (' . implode(' ', $types) . '))'; |
| | | } |
| | | |
| | | $result = $this->execute('CREATE', $args, self::COMMAND_NORESPONSE); |
| | | |
| | | return ($result == self::ERROR_OK); |
| | | } |
| | |
| | | * @param string $ref Reference name |
| | | * @param string $mailbox Mailbox name |
| | | * @param bool $subscribed Enables returning subscribed mailboxes only |
| | | * @param array $status_opts List of STATUS options (RFC5819: LIST-STATUS) |
| | | * Possible: MESSAGES, RECENT, UIDNEXT, UIDVALIDITY, UNSEEN |
| | | * @param array $status_opts List of STATUS options |
| | | * (RFC5819: LIST-STATUS: MESSAGES, RECENT, UIDNEXT, UIDVALIDITY, UNSEEN) |
| | | * or RETURN options (RFC5258: LIST_EXTENDED: SUBSCRIBED, CHILDREN) |
| | | * @param array $select_opts List of selection options (RFC5258: LIST-EXTENDED) |
| | | * Possible: SUBSCRIBED, RECURSIVEMATCH, REMOTE |
| | | * Possible: SUBSCRIBED, RECURSIVEMATCH, REMOTE, |
| | | * SPECIAL-USE (RFC6154) |
| | | * |
| | | * @return array List of mailboxes or hash of options if $status_ops argument |
| | | * is non-empty. |
| | | */ |
| | | private function _listMailboxes($ref, $mailbox, $subscribed=false, |
| | | protected function _listMailboxes($ref, $mailbox, $subscribed=false, |
| | | $status_opts=array(), $select_opts=array()) |
| | | { |
| | | if (!strlen($mailbox)) { |
| | |
| | | } |
| | | |
| | | $args = array(); |
| | | $rets = array(); |
| | | |
| | | if (!empty($select_opts) && $this->getCapability('LIST-EXTENDED')) { |
| | | $select_opts = (array) $select_opts; |
| | |
| | | $args[] = $this->escape($ref); |
| | | $args[] = $this->escape($mailbox); |
| | | |
| | | if (!empty($status_opts) && $this->getCapability('LIST-STATUS')) { |
| | | $status_opts = (array) $status_opts; |
| | | $lstatus = true; |
| | | if (!empty($status_opts) && $this->getCapability('LIST-EXTENDED')) { |
| | | $rets = array_intersect($status_opts, array('SUBSCRIBED', 'CHILDREN')); |
| | | } |
| | | |
| | | $args[] = 'RETURN (STATUS (' . implode(' ', $status_opts) . '))'; |
| | | if (!empty($status_opts) && $this->getCapability('LIST-STATUS')) { |
| | | $status_opts = array_intersect($status_opts, array('MESSAGES', 'RECENT', 'UIDNEXT', 'UIDVALIDITY', 'UNSEEN')); |
| | | |
| | | if (!empty($status_opts)) { |
| | | $lstatus = true; |
| | | $rets[] = 'STATUS (' . implode(' ', $status_opts) . ')'; |
| | | } |
| | | } |
| | | |
| | | if (!empty($rets)) { |
| | | $args[] = 'RETURN (' . implode(' ', $rets) . ')'; |
| | | } |
| | | |
| | | list($code, $response) = $this->execute($subscribed ? 'LSUB' : 'LIST', $args); |
| | |
| | | * |
| | | * @return bool True on success, False on failure |
| | | */ |
| | | private function modFlag($mailbox, $messages, $flag, $mod = '+') |
| | | protected function modFlag($mailbox, $messages, $flag, $mod = '+') |
| | | { |
| | | if ($mod != '+' && $mod != '-') { |
| | | $mod = '+'; |
| | |
| | | if (isset($mbox) && is_array($data[$i])) { |
| | | $size_sub = count($data[$i]); |
| | | for ($x=0; $x<$size_sub; $x++) { |
| | | $result[$mbox][$data[$i][$x]] = $data[$i][++$x]; |
| | | if ($data[$i][$x+1] !== null) |
| | | $result[$mbox][$data[$i][$x]] = $data[$i][++$x]; |
| | | } |
| | | unset($data[$i]); |
| | | } |
| | |
| | | } |
| | | } |
| | | else if (isset($mbox)) { |
| | | $result[$mbox][$data[$i]] = $data[++$i]; |
| | | if ($data[$i+1] !== null) |
| | | $result[$mbox][$data[$i]] = $data[++$i]; |
| | | unset($data[$i]); |
| | | unset($data[$i-1]); |
| | | } |
| | |
| | | for ($x=0, $len=count($attribs); $x<$len;) { |
| | | $attr = $attribs[$x++]; |
| | | $value = $attribs[$x++]; |
| | | if ($attr == 'value.priv') { |
| | | if ($attr == 'value.priv' && $value !== null) { |
| | | $result[$mbox]['/private' . $entry] = $value; |
| | | } |
| | | else if ($attr == 'value.shared') { |
| | | else if ($attr == 'value.shared' && $value !== null) { |
| | | $result[$mbox]['/shared' . $entry] = $value; |
| | | } |
| | | } |
| | |
| | | return $result; |
| | | } |
| | | |
| | | private function _xor($string, $string2) |
| | | protected function _xor($string, $string2) |
| | | { |
| | | $result = ''; |
| | | $size = strlen($string); |
| | |
| | | * |
| | | * @return string Space-separated list of flags |
| | | */ |
| | | private function flagsToStr($flags) |
| | | protected function flagsToStr($flags) |
| | | { |
| | | foreach ((array)$flags as $idx => $flag) { |
| | | if ($flag = $this->flags[strtoupper($flag)]) { |
| | |
| | | /** |
| | | * CAPABILITY response parser |
| | | */ |
| | | private function parseCapability($str, $trusted=false) |
| | | protected function parseCapability($str, $trusted=false) |
| | | { |
| | | $str = preg_replace('/^\* CAPABILITY /i', '', $str); |
| | | |
| | |
| | | * |
| | | * @since 0.5-stable |
| | | */ |
| | | private function debug($message) |
| | | protected function debug($message) |
| | | { |
| | | if (($len = strlen($message)) > self::DEBUG_LINE_LENGTH) { |
| | | $diff = $len - self::DEBUG_LINE_LENGTH; |