| | |
| | | $this->conn = new rcube_imap_generic(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Connect to an IMAP server |
| | | * |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Close IMAP connection |
| | | * Usually done on script shutdown |
| | |
| | | $this->write_cache(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Close IMAP connection and re-connect |
| | | * This is used to avoid some strange socket errors when talking to Courier IMAP |
| | |
| | | $this->conn->select($this->mailbox); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Set options to be used in rcube_imap_generic::connect() |
| | | * |
| | |
| | | $this->options = array_merge($this->options, (array)$opt); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Set a root folder for the IMAP connection. |
| | | * |
| | |
| | | $this->get_hierarchy_delimiter(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Set default message charset |
| | | * |
| | |
| | | $this->default_charset = $cs; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * This list of folders will be listed above all other folders |
| | | * |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Set internal mailbox reference. |
| | | * |
| | |
| | | $this->_clear_messagecount($mailbox); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Set internal list page |
| | | * |
| | |
| | | $this->list_page = (int)$page; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Set internal page size |
| | | * |
| | |
| | | $this->page_size = (int)$size; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Save a set of message ids for future message listing methods |
| | | * |
| | |
| | | $this->search_sorted = $sorted; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Return the saved search set as hash array |
| | | * @return array Search set |
| | |
| | | ); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Returns the currently used mailbox name |
| | | * |
| | |
| | | return $this->conn->connected() ? $this->mod_mailbox($this->mailbox, 'out') : ''; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Returns the IMAP server's capability |
| | | * |
| | |
| | | return $this->conn->getCapability(strtoupper($cap)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Sets threading flag to the best supported THREAD algorithm |
| | | * |
| | |
| | | return $this->threading; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Checks the PERMANENTFLAGS capability of the current mailbox |
| | | * and returns true if the given flag is supported by the IMAP server |
| | | * |
| | | * @param string $flag Permanentflag name |
| | | * @return mixed True if this flag is supported |
| | | * @return boolean True if this flag is supported |
| | | * @access public |
| | | */ |
| | | function check_permflag($flag) |
| | |
| | | return (in_array_nocase($imap_flag, $this->conn->permanentflags)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Returns the delimiter that is used by the IMAP server for folder separation |
| | | * |
| | |
| | | return $this->delimiter; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get message count for a specific mailbox |
| | | * |
| | |
| | | return $this->_messagecount($mailbox, $mode, $force, $status); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Private method for getting nr of messages |
| | | * |
| | |
| | | /** |
| | | * Private method for getting nr of threads |
| | | * |
| | | * @param string $mailbox |
| | | * @param int $msg_count |
| | | * @param string $mailbox Folder name |
| | | * @param int $msg_count Number of messages in the folder |
| | | * @access private |
| | | * @see rcube_imap::messagecount() |
| | | */ |
| | |
| | | return count($thread_tree); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Public method for listing headers |
| | | * convert mailbox name with root dir first |
| | |
| | | return $this->_list_headers($mailbox, $page, $sort_field, $sort_order, false, $slice); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Private method for listing message headers |
| | | * |
| | |
| | | return array_values($a_msg_headers); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Private method for listing message headers using threads |
| | | * |
| | |
| | | * @param int $page Current page to list |
| | | * @param string $sort_field Header field to sort by |
| | | * @param string $sort_order Sort order [ASC|DESC] |
| | | * @param boolean $recursive |
| | | * @param boolean $recursive True if called recursively |
| | | * @param int $slice Number of slice items to extract from result array |
| | | * @return array Indexed array with message header objects |
| | | * @access private |
| | |
| | | /** |
| | | * Private method for fetching threaded messages headers |
| | | * |
| | | * @param string $mailbox Mailbox name |
| | | * @param string $thread_tree |
| | | * @param int $msg_depth |
| | | * @param boolean $has_children |
| | | * @param int $msg_index |
| | | * @param int $page |
| | | * @param int $slice |
| | | * @param string $mailbox Mailbox name |
| | | * @param array $thread_tree Thread tree data |
| | | * @param array $msg_depth Thread depth data |
| | | * @param array $has_children Thread children data |
| | | * @param array $msg_index Messages index |
| | | * @param int $page List page number |
| | | * @param int $slice Number of threads to slice |
| | | * @return array Messages headers |
| | | * @access private |
| | | */ |
| | | private function _fetch_thread_headers($mailbox, $thread_tree, $msg_depth, $has_children, $msg_index, $page, $slice=0) |
| | |
| | | /** |
| | | * Helper function to get first and last index of the requested set |
| | | * |
| | | * @param int $max message count |
| | | * @param mixed $page page number to show, or string 'all' |
| | | * @return array array with two values: first index, last index |
| | | * @param int $max Messages count |
| | | * @param mixed $page Page number to show, or string 'all' |
| | | * @return array Array with two values: first index, last index |
| | | * @access private |
| | | */ |
| | | private function _get_message_range($max, $page) |
| | |
| | | |
| | | |
| | | /** |
| | | * Fetches message headers |
| | | * Used for loop |
| | | * Fetches message headers (used for loop) |
| | | * |
| | | * @param string Mailbox name |
| | | * @param string Message index to fetch |
| | | * @param array Reference to message headers array |
| | | * @param string Cache index string |
| | | * @param string $mailbox Mailbox name |
| | | * @param string $msgs Message index to fetch |
| | | * @param array $a_msg_headers Reference to message headers array |
| | | * @param string $cache_key Cache index key |
| | | * @return int Messages count |
| | | * @access private |
| | | */ |
| | |
| | | * @param string $mbox_name Mailbox to get index from |
| | | * @param string $sort_field Sort column |
| | | * @param string $sort_order Sort order [ASC, DESC] |
| | | * @return array Indexed array with message ids |
| | | * @return array Indexed array with message IDs |
| | | */ |
| | | function message_index($mbox_name='', $sort_field=NULL, $sort_order=NULL) |
| | | { |
| | |
| | | /** |
| | | * Invoke search request to IMAP server |
| | | * |
| | | * @param string $mbox_name mailbox name to search in |
| | | * @param string $str search string |
| | | * @param string $charset search string charset |
| | | * @param string $sort_field header field to sort by |
| | | * @return array search results as list of message ids |
| | | * @param string $mbox_name Mailbox name to search in |
| | | * @param string $str Search criteria |
| | | * @param string $charset Search charset |
| | | * @param string $sort_field Header field to sort by |
| | | * @return array search results as list of message IDs |
| | | * @access public |
| | | */ |
| | | function search($mbox_name='', $str=NULL, $charset=NULL, $sort_field=NULL) |
| | |
| | | /** |
| | | * Set attachment filename from message part structure |
| | | * |
| | | * @access private |
| | | * @param rcube_message_part $part Part object |
| | | * @param string $headers Part's raw headers |
| | | * @access private |
| | | */ |
| | | private function _set_part_filename(&$part, $headers=null) |
| | | { |
| | |
| | | /** |
| | | * Get charset name from message structure (first part) |
| | | * |
| | | * @access private |
| | | * @param array $structure Message structure |
| | | * @return string Charset name |
| | | * @access private |
| | | */ |
| | | function _structure_charset($structure) |
| | | private function _structure_charset($structure) |
| | | { |
| | | while (is_array($structure)) { |
| | | if (is_array($structure[2]) && $structure[2][0] == 'charset') |
| | |
| | | $this->caching_enabled = false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Returns cached value |
| | | * |
| | |
| | | return $this->cache[$key]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Update cache |
| | | * |
| | |
| | | $this->cache_changed = true; |
| | | $this->cache_changes[$key] = true; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Writes the cache |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Clears the cache. |
| | |
| | | unset($this->cache[$key]); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Returns cached entry |
| | |
| | | |
| | | return $this->cache[$key]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Writes single cache record |
| | |
| | | $this->cache_keys[$key] = $sql_arr['cache_id']; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Clears cache for single record |
| | |
| | | return -2; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @param string $key Cache key |
| | | * @param string $from |
| | |
| | | return $result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @param string $key Cache key |
| | | * @param int $uid User id |
| | | * @param int $uid Message UID |
| | | * @return mixed |
| | | * @access private |
| | | */ |
| | |
| | | return $this->icache[$internal_key][$uid]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @param string $key Cache key |
| | | * @param boolean $force Force flag |
| | | * @param string $sort_field |
| | | * @param string $sort_order |
| | | * @param string $key Cache key |
| | | * @param string $sort_field Sorting column |
| | | * @param string $sort_order Sorting order |
| | | * @return array Messages index |
| | | * @access private |
| | | */ |
| | | private function get_message_cache_index($key, $sort_field='idx', $sort_order='ASC') |
| | |
| | | if (!$sort_field || !in_array($sort_field, $this->db_header_fields)) |
| | | $sort_field = 'idx'; |
| | | |
| | | $ord = $sort_field . $sort_order; |
| | | |
| | | if (array_key_exists('index', $this->icache) |
| | | && $this->icache['index']['key'] == $key |
| | | && $this->icache['index']['ord'] == $ord |
| | | && $this->icache['index']['sort_field'] == $sort_field |
| | | ) { |
| | | return $this->icache['index']['result']; |
| | | if ($this->icache['index']['sort_order'] == $sort_order) |
| | | return $this->icache['index']['result']; |
| | | else |
| | | return array_reverse($this->icache['index']['result'], true); |
| | | } |
| | | |
| | | $this->icache['index'] = array( |
| | | 'result' => array(), |
| | | 'ord' => $ord, |
| | | 'key' => $key, |
| | | 'result' => array(), |
| | | 'key' => $key, |
| | | 'sort_field' => $sort_field, |
| | | 'sort_order' => $sort_order, |
| | | ); |
| | | |
| | | $sql_result = $this->db->query( |
| | |
| | | |
| | | return $this->icache['index']['result']; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | |
| | | unset($this->icache['index']); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | |
| | | |
| | | unset($this->icache['index']); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @param string $key Cache key |
| | |
| | | |
| | | unset($this->icache['index']); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | |
| | | return $sql_arr['minidx']; |
| | | else |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @param string $key Cache key |
| | | * @param int $id Message (sequence) ID |
| | | * @return int Message UID |
| | | * @access private |
| | | */ |
| | | private function get_cache_id2uid($key, $id) |
| | | { |
| | | if (!$this->caching_enabled) |
| | | return null; |
| | | |
| | | if (array_key_exists('index', $this->icache) |
| | | && $this->icache['index']['key'] == $key |
| | | ) { |
| | | return $this->icache['index']['result'][$id]; |
| | | } |
| | | |
| | | $sql_result = $this->db->query( |
| | | "SELECT uid". |
| | | " FROM ".get_table_name('messages'). |
| | | " WHERE user_id=?". |
| | | " AND cache_key=?". |
| | | " AND idx=?", |
| | | $_SESSION['user_id'], $key, $id); |
| | | |
| | | if ($sql_arr = $this->db->fetch_assoc($sql_result)) |
| | | return intval($sql_arr['uid']); |
| | | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @param string $key Cache key |
| | | * @param int $uid Message UID |
| | | * @return int Message (sequence) ID |
| | | * @access private |
| | | */ |
| | | private function get_cache_uid2id($key, $uid) |
| | | { |
| | | if (!$this->caching_enabled) |
| | | return null; |
| | | |
| | | if (array_key_exists('index', $this->icache) |
| | | && $this->icache['index']['key'] == $key |
| | | ) { |
| | | return array_search($uid, $this->icache['index']['result']); |
| | | } |
| | | |
| | | $sql_result = $this->db->query( |
| | | "SELECT idx". |
| | | " FROM ".get_table_name('messages'). |
| | | " WHERE user_id=?". |
| | | " AND cache_key=?". |
| | | " AND uid=?", |
| | | $_SESSION['user_id'], $key, $uid); |
| | | |
| | | if ($sql_arr = $this->db->fetch_assoc($sql_result)) |
| | | return intval($sql_arr['idx']); |
| | | |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | $this->sort_order = strtoupper($sort_order) == 'DESC' ? 'DESC' : 'ASC'; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Sort mailboxes first by default folders and then in alphabethical order |
| | | * |
| | |
| | | |
| | | |
| | | /** |
| | | * @param int $uid User id |
| | | * @param int $uid Message UID |
| | | * @param string $mbox_name Mailbox name |
| | | * @return int |
| | | * @return int Message (sequence) ID |
| | | * @access private |
| | | */ |
| | | private function _uid2id($uid, $mbox_name=NULL) |
| | |
| | | if (!$mbox_name) |
| | | $mbox_name = $this->mailbox; |
| | | |
| | | if (!isset($this->uid_id_map[$mbox_name][$uid])) |
| | | $this->uid_id_map[$mbox_name][$uid] = $this->conn->UID2ID($mbox_name, $uid); |
| | | if (!isset($this->uid_id_map[$mbox_name][$uid])) { |
| | | if (!($id = $this->get_cache_uid2id($mbox_name.'.msg', $uid))) |
| | | $id = $this->conn->UID2ID($mbox_name, $uid); |
| | | |
| | | $this->uid_id_map[$mbox_name][$uid] = $id; |
| | | } |
| | | |
| | | return $this->uid_id_map[$mbox_name][$uid]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @param int $id Id |
| | | * @param int $id Message (sequence) ID |
| | | * @param string $mbox_name Mailbox name |
| | | * @return int |
| | | * @return int Message UID |
| | | * @access private |
| | | */ |
| | | private function _id2uid($id, $mbox_name=NULL) |
| | |
| | | if ($uid = array_search($id, (array)$this->uid_id_map[$mbox_name])) |
| | | return $uid; |
| | | |
| | | $uid = $this->conn->ID2UID($mbox_name, $id); |
| | | if (!($uid = $this->get_cache_id2uid($mbox_name.'.msg', $id))) |
| | | $uid = $this->conn->ID2UID($mbox_name, $id); |
| | | |
| | | $this->uid_id_map[$mbox_name][$uid] = $id; |
| | | |
| | | return $uid; |