| | |
| | | * |
| | | * @package Mail |
| | | * @author Thomas Bruederli <roundcube@gmail.com> |
| | | * @version 1.40 |
| | | * @version 1.5 |
| | | * @link http://ilohamail.org |
| | | */ |
| | | class rcube_imap |
| | |
| | | var $debug_level = 1; |
| | | var $error_code = 0; |
| | | var $options = array('imap' => 'check'); |
| | | |
| | | private $host, $user, $pass, $port, $ssl; |
| | | |
| | | |
| | | /** |
| | |
| | | // check for Open-SSL support in PHP build |
| | | if ($use_ssl && extension_loaded('openssl')) |
| | | $ICL_SSL = $use_ssl == 'imaps' ? 'ssl' : $use_ssl; |
| | | else if ($use_ssl) |
| | | { |
| | | else if ($use_ssl) { |
| | | raise_error(array('code' => 403, 'type' => 'imap', 'file' => __FILE__, |
| | | 'message' => 'Open SSL not available;'), TRUE, FALSE); |
| | | $port = 143; |
| | | } |
| | | } |
| | | |
| | | $ICL_PORT = $port; |
| | | $IMAP_USE_INTERNAL_DATE = false; |
| | | |
| | | $attempt = 0; |
| | | do { |
| | | $data = rcmail::get_instance()->plugins->exec_hook('imap_connect', array('host' => $host, 'user' => $user, 'attempt' => ++$attempt)); |
| | | if (!empty($data['pass'])) |
| | | $pass = $data['pass']; |
| | | |
| | | $this->conn = iil_Connect($host, $user, $pass, $this->options); |
| | | $this->host = $host; |
| | | $this->user = $user; |
| | | $this->conn = iil_Connect($data['host'], $data['user'], $pass, $this->options); |
| | | } while(!$this->conn && $data['retry']); |
| | | |
| | | $this->host = $data['host']; |
| | | $this->user = $data['user']; |
| | | $this->pass = $pass; |
| | | $this->port = $port; |
| | | $this->ssl = $use_ssl; |
| | |
| | | // retrieve headers from IMAP |
| | | $a_msg_headers = array(); |
| | | |
| | | if ($this->get_capability('sort') && ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) |
| | | if (!$this->get_capability('sort') && ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) |
| | | { |
| | | list($begin, $end) = $this->_get_message_range(count($msg_index), $page); |
| | | $max = max($msg_index); |
| | |
| | | else |
| | | { |
| | | $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:*", $this->sort_field, $this->skip_deleted); |
| | | |
| | | |
| | | if (empty($a_index)) |
| | | return array(); |
| | | |
| | |
| | | if (!is_array($uids)) |
| | | $uids = explode(',',$uids); |
| | | |
| | | if ($flag=='UNDELETED') |
| | | $result = iil_C_Undelete($this->conn, $mailbox, join(',', $uids)); |
| | | else if ($flag=='UNSEEN') |
| | | $result = iil_C_Unseen($this->conn, $mailbox, join(',', $uids)); |
| | | else if ($flag=='UNFLAGGED') |
| | | $result = iil_C_UnFlag($this->conn, $mailbox, join(',', $uids), 'FLAGGED'); |
| | | if (strpos($flag, 'UN') === 0) |
| | | $result = iil_C_UnFlag($this->conn, $mailbox, join(',', $uids), substr($flag, 2)); |
| | | else |
| | | $result = iil_C_Flag($this->conn, $mailbox, join(',', $uids), $flag); |
| | | |
| | |
| | | $this->_set_messagecount($mailbox, 'ALL', $count*(-1)); |
| | | |
| | | return $result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Remove message flag for one or several messages |
| | | * |
| | | * @param mixed Message UIDs as array or as comma-separated string |
| | | * @param string Flag to unset: SEEN, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT |
| | | * @param string Folder name |
| | | * @return boolean True on success, False on failure |
| | | * @see set_flag |
| | | */ |
| | | function unset_flag($uids, $flag, $mbox_name=NULL) |
| | | { |
| | | return $this->set_flag($uids, 'UN'.$flag, $mbox_name); |
| | | } |
| | | |
| | | |
| | |
| | | private function _change_subscription($a_mboxes, $mode) |
| | | { |
| | | $updated = FALSE; |
| | | |
| | | |
| | | if (is_array($a_mboxes)) |
| | | foreach ($a_mboxes as $i => $mbox_name) |
| | | { |
| | |
| | | $a_mboxes[$i] = $mailbox; |
| | | |
| | | if ($mode=='subscribe') |
| | | $result = iil_C_Subscribe($this->conn, $mailbox); |
| | | $updated = iil_C_Subscribe($this->conn, $mailbox); |
| | | else if ($mode=='unsubscribe') |
| | | $result = iil_C_UnSubscribe($this->conn, $mailbox); |
| | | |
| | | if ($result>=0) |
| | | $updated = TRUE; |
| | | $updated = iil_C_UnSubscribe($this->conn, $mailbox); |
| | | } |
| | | |
| | | // get cached mailbox list |
| | | |
| | | // get cached mailbox list |
| | | if ($updated) |
| | | { |
| | | $a_mailbox_cache = $this->get_cache('mailboxes'); |
| | |
| | | $a_mailbox_cache = array_merge($a_mailbox_cache, $a_mboxes); |
| | | else if ($mode=='unsubscribe') |
| | | $a_mailbox_cache = array_diff($a_mailbox_cache, $a_mboxes); |
| | | |
| | | |
| | | // write mailboxlist to cache |
| | | $this->update_cache('mailboxes', $this->_sort_mailbox_list($a_mailbox_cache)); |
| | | } |