| | |
| | | | program/include/rcube_imap.inc | |
| | | | | |
| | | | This file is part of the RoundCube Webmail client | |
| | | | Copyright (C) 2005, RoundCube Dev. - Switzerland | |
| | | | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland | |
| | | | Licensed under the GNU GPL | |
| | | | | |
| | | | PURPOSE: | |
| | |
| | | */ |
| | | |
| | | |
| | | /** |
| | | /* |
| | | * Obtain classes from the Iloha IMAP library |
| | | */ |
| | | require_once('lib/imap.inc'); |
| | |
| | | * |
| | | * This is a wrapper that implements the Iloha IMAP Library (IIL) |
| | | * |
| | | * @package RoundCube Webmail |
| | | * @package Mail |
| | | * @author Thomas Bruederli <roundcube@gmail.com> |
| | | * @version 1.34 |
| | | * @version 1.40 |
| | | * @link http://ilohamail.org |
| | | */ |
| | | class rcube_imap |
| | | { |
| | | { |
| | | var $db; |
| | | var $conn; |
| | | var $root_ns = ''; |
| | |
| | | var $sort_order = 'DESC'; |
| | | var $delimiter = NULL; |
| | | var $caching_enabled = FALSE; |
| | | var $default_charset = 'ISO-8859-1'; |
| | | var $default_folders = array('INBOX'); |
| | | var $default_folders_lc = array('inbox'); |
| | | var $cache = array(); |
| | |
| | | var $msg_headers = array(); |
| | | var $capabilities = array(); |
| | | var $skip_deleted = FALSE; |
| | | var $search_set = NULL; |
| | | var $search_subject = ''; |
| | | var $search_string = ''; |
| | | var $search_charset = ''; |
| | | var $debug_level = 1; |
| | | var $error_code = 0; |
| | | |
| | | |
| | | /** |
| | | * Object constructor |
| | | * |
| | | * @param object Database connection |
| | | * @param object DB Database connection |
| | | */ |
| | | function __construct($db_conn) |
| | | { |
| | |
| | | * @param string Username for IMAP account |
| | | * @param string Password for IMAP account |
| | | * @param number Port to connect to |
| | | * @param boolean Use SSL connection |
| | | * @param string SSL schema (either ssl or tls) or null if plain connection |
| | | * @return boolean TRUE on success, FALSE on failure |
| | | * @access public |
| | | */ |
| | | function connect($host, $user, $pass, $port=143, $use_ssl=FALSE) |
| | | function connect($host, $user, $pass, $port=143, $use_ssl=null) |
| | | { |
| | | global $ICL_SSL, $ICL_PORT, $IMAP_USE_INTERNAL_DATE; |
| | | |
| | | // check for Open-SSL support in PHP build |
| | | if ($use_ssl && in_array('openssl', get_loaded_extensions())) |
| | | $ICL_SSL = TRUE; |
| | | $ICL_SSL = $use_ssl == 'imaps' ? 'ssl' : $use_ssl; |
| | | else if ($use_ssl) |
| | | { |
| | | raise_error(array('code' => 403, 'type' => 'imap', 'file' => __FILE__, |
| | |
| | | // write error log |
| | | else if (!$this->conn && $GLOBALS['iil_error']) |
| | | { |
| | | $this->error_code = $GLOBALS['iil_errornum']; |
| | | raise_error(array('code' => 403, |
| | | 'type' => 'imap', |
| | | 'message' => $GLOBALS['iil_error']), TRUE, FALSE); |
| | |
| | | |
| | | |
| | | /** |
| | | * Set default message charset |
| | | * |
| | | * This will be used for message decoding if a charset specification is not available |
| | | * |
| | | * @param string Charset string |
| | | * @access public |
| | | */ |
| | | function set_charset($cs) |
| | | { |
| | | $this->default_charset = $ch; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * This list of folders will be listed above all other folders |
| | | * |
| | | * @param array Indexed list of folder names |
| | |
| | | function set_pagesize($size) |
| | | { |
| | | $this->page_size = (int)$size; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Save a set of message ids for future message listing methods |
| | | * |
| | | * @param array List of IMAP fields to search in |
| | | * @param string Search string |
| | | * @param array List of message ids or NULL if empty |
| | | */ |
| | | function set_search_set($subject, $str=null, $msgs=null, $charset=null) |
| | | { |
| | | if (is_array($subject) && $str == null && $msgs == null) |
| | | list($subject, $str, $msgs, $charset) = $subject; |
| | | if ($msgs != null && !is_array($msgs)) |
| | | $msgs = split(',', $msgs); |
| | | |
| | | $this->search_subject = $subject; |
| | | $this->search_string = $str; |
| | | $this->search_set = (array)$msgs; |
| | | $this->search_charset = $charset; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return the saved search set as hash array |
| | | * @return array Search set |
| | | */ |
| | | function get_search_set() |
| | | { |
| | | return array($this->search_subject, $this->search_string, $this->search_set, $this->search_charset); |
| | | } |
| | | |
| | | |
| | |
| | | * Private method for mailbox listing |
| | | * |
| | | * @return array List of mailboxes/folders |
| | | * @see rcube_imap::list_mailboxes() |
| | | * @access private |
| | | * @see rcube_imap::list_mailboxes |
| | | */ |
| | | function _list_mailboxes($root='', $filter='*') |
| | | { |
| | |
| | | * @param string Mailbox/folder name |
| | | * @param string Mode for count [ALL|UNSEEN|RECENT] |
| | | * @param boolean Force reading from server and update cache |
| | | * @return number Number of messages |
| | | * @access public |
| | | * @return int Number of messages |
| | | * @access public |
| | | */ |
| | | function messagecount($mbox_name='', $mode='ALL', $force=FALSE) |
| | | { |
| | |
| | | * Private method for getting nr of messages |
| | | * |
| | | * @access private |
| | | * @see rcube_imap::messagecount |
| | | * @see rcube_imap::messagecount() |
| | | */ |
| | | function _messagecount($mailbox='', $mode='ALL', $force=FALSE) |
| | | { |
| | |
| | | |
| | | if (empty($mailbox)) |
| | | $mailbox = $this->mailbox; |
| | | |
| | | // count search set |
| | | if ($this->search_string && $mailbox == $this->mailbox && $mode == 'ALL' && !$force) |
| | | return count((array)$this->search_set); |
| | | |
| | | $a_mailbox_cache = $this->get_cache('messagecount'); |
| | | |
| | |
| | | * convert mailbox name with root dir first |
| | | * |
| | | * @param string Mailbox/folder name |
| | | * @param number Current page to list |
| | | * @param int Current page to list |
| | | * @param string Header field to sort by |
| | | * @param string Sort order [ASC|DESC] |
| | | * @return array Indexed array with message header objects |
| | |
| | | { |
| | | if (!strlen($mailbox)) |
| | | return array(); |
| | | |
| | | if ($sort_field!=NULL) |
| | | $this->sort_field = $sort_field; |
| | | if ($sort_order!=NULL) |
| | | $this->sort_order = strtoupper($sort_order); |
| | | |
| | | // use saved message set |
| | | if ($this->search_string && $mailbox == $this->mailbox) |
| | | return $this->_list_header_set($mailbox, $this->search_set, $page, $sort_field, $sort_order); |
| | | |
| | | $this->_set_sort_order($sort_field, $sort_order); |
| | | |
| | | $max = $this->_messagecount($mailbox); |
| | | $start_msg = ($this->list_page-1) * $this->page_size; |
| | | |
| | | list($begin, $end) = $this->_get_message_range($max, $page); |
| | | |
| | | // mailbox is empty |
| | | // mailbox is empty |
| | | if ($begin >= $end) |
| | | return array(); |
| | | |
| | | |
| | | $headers_sorted = FALSE; |
| | | $cache_key = $mailbox.'.msg'; |
| | | $cache_status = $this->check_cache_status($mailbox, $cache_key); |
| | |
| | | $a_msg_headers = array(); |
| | | $deleted_count = $this->_fetch_headers($mailbox, $msgs, $a_msg_headers, $cache_key); |
| | | |
| | | // delete cached messages with a higher index than $max |
| | | $this->clear_message_cache($cache_key, $max); |
| | | // delete cached messages with a higher index than $max+1 |
| | | // Changed $max to $max+1 to fix this bug : #1484295 |
| | | $this->clear_message_cache($cache_key, $max + 1); |
| | | |
| | | |
| | | // kick child process to sync cache |
| | |
| | | * |
| | | * @param string Mailbox/folder name |
| | | * @param array List of message ids to list |
| | | * @param number Current page to list |
| | | * @param int Current page to list |
| | | * @param string Header field to sort by |
| | | * @param string Sort order [ASC|DESC] |
| | | * @return array Indexed array with message header objects |
| | |
| | | * Private method for listing a set of message headers |
| | | * |
| | | * @access private |
| | | * @see rcube_imap::list_header_set |
| | | * @see rcube_imap::list_header_set() |
| | | */ |
| | | function _list_header_set($mailbox, $msgs, $page=NULL, $sort_field=NULL, $sort_order=NULL) |
| | | { |
| | |
| | | if (!strlen($mailbox) || empty($msgs)) |
| | | return array(); |
| | | |
| | | if ($sort_field!=NULL) |
| | | $this->sort_field = $sort_field; |
| | | if ($sort_order!=NULL) |
| | | $this->sort_order = strtoupper($sort_order); |
| | | $this->_set_sort_order($sort_field, $sort_order); |
| | | |
| | | $max = count($msgs); |
| | | $start_msg = ($this->list_page-1) * $this->page_size; |
| | |
| | | $this->_fetch_headers($mailbox, join(',', $msgs), $a_msg_headers, NULL); |
| | | |
| | | // return empty array if no messages found |
| | | if (!is_array($a_msg_headers) || empty($a_msg_headers)) |
| | | return array(); |
| | | if (!is_array($a_msg_headers) || empty($a_msg_headers)) |
| | | return array(); |
| | | |
| | | // if not already sorted |
| | | $a_msg_headers = iil_SortHeaders($a_msg_headers, $this->sort_field, $this->sort_order); |
| | | |
| | | // only return the requested part of the set |
| | | return array_slice(array_values($a_msg_headers), $start_msg, min($max-$start_msg, $this->page_size)); |
| | | // only return the requested part of the set |
| | | return array_slice(array_values($a_msg_headers), $start_msg, min($max-$start_msg, $this->page_size)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Helper function to get first and last index of the requested set |
| | | * |
| | | * @param number message count |
| | | * @param int message count |
| | | * @param mixed page number to show, or string 'all' |
| | | * @return array array with two values: first index, last index |
| | | * @access private |
| | |
| | | * @param string Message index to fetch |
| | | * @param array Reference to message headers array |
| | | * @param array Array with cache index |
| | | * @return number Number of deleted messages |
| | | * @return int Number of deleted messages |
| | | * @access private |
| | | */ |
| | | function _fetch_headers($mailbox, $msgs, &$a_msg_headers, $cache_key) |
| | |
| | | */ |
| | | function message_index($mbox_name='', $sort_field=NULL, $sort_order=NULL) |
| | | { |
| | | if ($sort_field!=NULL) |
| | | $this->sort_field = $sort_field; |
| | | if ($sort_order!=NULL) |
| | | $this->sort_order = strtoupper($sort_order); |
| | | $this->_set_sort_order($sort_field, $sort_order); |
| | | |
| | | $mailbox = $mbox_name ? $this->_mod_mailbox($mbox_name) : $this->mailbox; |
| | | $key = "$mbox:".$this->sort_field.":".$this->sort_order.".msgi"; |
| | | $key = "{$mailbox}:{$this->sort_field}:{$this->sort_order}:{$this->search_string}.msgi"; |
| | | |
| | | // we have a saved search result. get index from there |
| | | if (!isset($this->cache[$key]) && $this->search_string && $mailbox == $this->mailbox) |
| | | { |
| | | $this->cache[$key] = $a_msg_headers = array(); |
| | | $this->_fetch_headers($mailbox, join(',', $this->search_set), $a_msg_headers, NULL); |
| | | |
| | | foreach (iil_SortHeaders($a_msg_headers, $this->sort_field, $this->sort_order) as $i => $msg) |
| | | $this->cache[$key][] = $msg->uid; |
| | | } |
| | | |
| | | // have stored it in RAM |
| | | if (isset($this->cache[$key])) |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function sync_header_index($mailbox) |
| | | { |
| | | $cache_key = $mailbox.'.msg'; |
| | |
| | | function search($mbox_name='', $criteria='ALL', $str=NULL, $charset=NULL) |
| | | { |
| | | $mailbox = $mbox_name ? $this->_mod_mailbox($mbox_name) : $this->mailbox; |
| | | if ($str && $criteria) |
| | | |
| | | // have an array of criterias => execute multiple searches |
| | | if (is_array($criteria) && $str) |
| | | { |
| | | $results = array(); |
| | | foreach ($criteria as $crit) |
| | | if ($search_result = $this->search($mbox_name, $crit, $str, $charset)) |
| | | $results = array_merge($results, $search_result); |
| | | |
| | | $results = array_unique($results); |
| | | $this->set_search_set($criteria, $str, $results, $charset); |
| | | return $results; |
| | | } |
| | | else if ($str && $criteria) |
| | | { |
| | | $search = (!empty($charset) ? "CHARSET $charset " : '') . sprintf("%s {%d}\r\n%s", $criteria, strlen($str), $str); |
| | | $results = $this->_search_index($mailbox, $search); |
| | |
| | | if (empty($results) && !empty($charset) && $charset!='ISO-8859-1') |
| | | $results = $this->search($mbox_name, $criteria, rcube_charset_convert($str, $charset, 'ISO-8859-1'), 'ISO-8859-1'); |
| | | |
| | | $this->set_search_set($criteria, $str, $results, $charset); |
| | | return $results; |
| | | } |
| | | else |
| | |
| | | |
| | | return $a_messages; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Refresh saved search set |
| | | * |
| | | * @return array Current search set |
| | | */ |
| | | function refresh_search() |
| | | { |
| | | if (!empty($this->search_subject) && !empty($this->search_string)) |
| | | $this->search_set = $this->search('', $this->search_subject, $this->search_string, $this->search_charset); |
| | | |
| | | return $this->get_search_set(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Check if the given message ID is part of the current search set |
| | | * |
| | | * @return boolean True on match or if no search request is stored |
| | | */ |
| | | function in_searchset($msgid) |
| | | { |
| | | if (!empty($this->search_string)) |
| | | return in_array("$msgid", (array)$this->search_set, true); |
| | | else |
| | | return true; |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | // write headers cache |
| | | if ($headers) |
| | | { |
| | | if ($is_uid) |
| | | $this->uid_id_map[$mbox_name][$uid] = $headers->id; |
| | | if ($headers->uid && $headers->id) |
| | | $this->uid_id_map[$mailbox][$headers->uid] = $headers->id; |
| | | |
| | | $this->add_message_cache($mailbox.'.msg', $headers->id, $headers); |
| | | } |
| | |
| | | * Fetch body structure from the IMAP server and build |
| | | * an object structure similar to the one generated by PEAR::Mail_mimeDecode |
| | | * |
| | | * @param Int Message UID to fetch |
| | | * @return object Standard object tree or False on failure |
| | | * @param int Message UID to fetch |
| | | * @return object stdClass Message part tree or False on failure |
| | | */ |
| | | function &get_structure($uid) |
| | | { |
| | |
| | | if (!($msg_id = $this->_uid2id($uid))) |
| | | return FALSE; |
| | | |
| | | $structure_str = iil_C_FetchStructureString($this->conn, $this->mailbox, $msg_id); |
| | | $structure = iml_GetRawStructureArray($structure_str); |
| | | $struct = false; |
| | | |
| | | $structure_str = iil_C_FetchStructureString($this->conn, $this->mailbox, $msg_id); |
| | | $structure = iml_GetRawStructureArray($structure_str); |
| | | $struct = false; |
| | | |
| | | // parse structure and add headers |
| | | if (!empty($structure)) |
| | | { |
| | | $this->_msg_id = $msg_id; |
| | | $headers = $this->get_headers($msg_id, NULL, FALSE); |
| | | $headers = $this->get_headers($uid); |
| | | |
| | | $struct = &$this->_structure_part($structure); |
| | | $struct->headers = get_object_vars($headers); |
| | |
| | | if ($this->caching_enabled) |
| | | $this->add_message_cache($cache_key, $msg_id, $headers, $struct); |
| | | } |
| | | |
| | | return $struct; |
| | | } |
| | | |
| | | return $struct; |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | for ($i=0, $count=0; $i<count($part); $i++) |
| | | if (is_array($part[$i]) && count($part[$i]) > 5) |
| | | $struct->parts[] = $this->_structure_part($part[$i], ++$count, $struct->mime_id); |
| | | |
| | | return $struct; |
| | | |
| | | return $struct; |
| | | } |
| | | |
| | | |
| | |
| | | $struct->ctype_primary = strtolower($part[0]); |
| | | $struct->ctype_secondary = strtolower($part[1]); |
| | | $struct->mimetype = $struct->ctype_primary.'/'.$struct->ctype_secondary; |
| | | |
| | | |
| | | // read content type parameters |
| | | if (is_array($part[2])) |
| | | { |
| | | $struct->ctype_parameters = array(); |
| | | if (is_array($part[2])) |
| | | { |
| | | $struct->ctype_parameters = array(); |
| | | for ($i=0; $i<count($part[2]); $i+=2) |
| | | $struct->ctype_parameters[strtolower($part[2][$i])] = $part[2][$i+1]; |
| | | |
| | | if (isset($struct->ctype_parameters['charset'])) |
| | | $struct->charset = $struct->ctype_parameters['charset']; |
| | | } |
| | | |
| | | // read content encoding |
| | | if (!empty($part[5]) && $part[5]!='NIL') |
| | | { |
| | | $struct->encoding = strtolower($part[5]); |
| | | $struct->headers['content-transfer-encoding'] = $struct->encoding; |
| | | } |
| | | |
| | | // get part size |
| | | if (!empty($part[6]) && $part[6]!='NIL') |
| | | $struct->size = intval($part[6]); |
| | | |
| | | // read part disposition |
| | | } |
| | | |
| | | // read content encoding |
| | | if (!empty($part[5]) && $part[5]!='NIL') |
| | | { |
| | | $struct->encoding = strtolower($part[5]); |
| | | $struct->headers['content-transfer-encoding'] = $struct->encoding; |
| | | } |
| | | |
| | | // get part size |
| | | if (!empty($part[6]) && $part[6]!='NIL') |
| | | $struct->size = intval($part[6]); |
| | | |
| | | // read part disposition |
| | | $di = count($part) - 2; |
| | | if (is_array($part[$di])) |
| | | if ((is_array($part[$di]) && count($part[$di]) == 2 && is_array($part[$di][1])) || |
| | | (is_array($part[--$di]) && count($part[$di]) == 2)) |
| | | { |
| | | $struct->disposition = strtolower($part[$di][0]); |
| | | |
| | |
| | | if (is_array($part[8][$i]) && count($part[8][$i]) > 5) |
| | | $struct->parts[] = $this->_structure_part($part[8][$i], ++$count, $struct->mime_id); |
| | | } |
| | | |
| | | // get part ID |
| | | if (!empty($part[3]) && $part[3]!='NIL') |
| | | { |
| | | $struct->content_id = $part[3]; |
| | | $struct->headers['content-id'] = $part[3]; |
| | | |
| | | if (empty($struct->disposition)) |
| | | $struct->disposition = 'inline'; |
| | | } |
| | | |
| | | // get part ID |
| | | if (!empty($part[3]) && $part[3]!='NIL') |
| | | { |
| | | $struct->content_id = $part[3]; |
| | | $struct->headers['content-id'] = $part[3]; |
| | | |
| | | if (empty($struct->disposition)) |
| | | $struct->disposition = 'inline'; |
| | | } |
| | | |
| | | // fetch message headers if message/rfc822 |
| | | if ($struct->ctype_primary=='message') |
| | | { |
| | | $headers = iil_C_FetchPartBody($this->conn, $this->mailbox, $this->_msg_id, $struct->mime_id.'.HEADER'); |
| | | $struct->headers = $this->_parse_headers($headers); |
| | | |
| | | if (is_array($part[8]) && empty($struct->parts)) |
| | | $struct->parts[] = $this->_structure_part($part[8], ++$count, $struct->mime_id); |
| | | } |
| | | |
| | | return $struct; |
| | | |
| | | // normalize filename property |
| | | if ($filename_mime = $struct->d_parameters['filename'] ? $struct->d_parameters['filename'] : $struct->ctype_parameters['name']) |
| | | $struct->filename = rcube_imap::decode_mime_string($filename_mime, $this->default_charset); |
| | | else if ($filename_encoded = $struct->d_parameters['filename*'] ? $struct->d_parameters['filename*'] : $struct->ctype_parameters['name*']) |
| | | { |
| | | // decode filename according to RFC 2231, Section 4 |
| | | list($filename_charset,, $filename_urlencoded) = split('\'', $filename_encoded); |
| | | $struct->filename = rcube_charset_convert(urldecode($filename_urlencoded), $filename_charset); |
| | | } |
| | | else if (!empty($struct->headers['content-description'])) |
| | | $struct->filename = rcube_imap::decode_mime_string($struct->headers['content-description'], $this->default_charset); |
| | | |
| | | return $struct; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return a flat array with references to all parts, indexed by part numbmers |
| | | * Return a flat array with references to all parts, indexed by part numbers |
| | | * |
| | | * @param object Message body structure |
| | | * @param object rcube_message_part Message body structure |
| | | * @return Array with part number -> object pairs |
| | | */ |
| | | function get_mime_numbers(&$structure) |
| | |
| | | /** |
| | | * Helper method for recursive calls |
| | | * |
| | | * @access |
| | | * @access private |
| | | */ |
| | | function _get_part_numbers(&$part, &$a_parts) |
| | | { |
| | |
| | | * |
| | | * @param int Message UID |
| | | * @param string Part number |
| | | * @param object Part object created by get_structure() |
| | | * @param object rcube_message_part Part object created by get_structure() |
| | | * @param mixed True to print part, ressource to write part contents in |
| | | * @return Message/part body if not printed |
| | | * @return string Message/part body if not printed |
| | | */ |
| | | function &get_message_part($uid, $part=1, $o_part=NULL, $print=NULL) |
| | | { |
| | |
| | | |
| | | if ($print) |
| | | { |
| | | iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, $part, ($o_part->encoding=='base64'?3:2)); |
| | | $body = TRUE; |
| | | $mode = $o_part->encoding == 'base64' ? 3 : ($o_part->encoding == 'quoted-printable' ? 1 : 2); |
| | | $body = iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, $part, $mode); |
| | | |
| | | // we have to decode the part manually before printing |
| | | if ($mode == 1) |
| | | { |
| | | echo $this->mime_decode($body, $o_part->encoding); |
| | | $body = true; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | $body = iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, $part, 1); |
| | | |
| | | // decode part body |
| | | if ($o_part->encoding=='base64' || $o_part->encoding=='quoted-printable') |
| | | if ($o_part->encoding) |
| | | $body = $this->mime_decode($body, $o_part->encoding); |
| | | |
| | | // convert charset (if text or message part) |
| | | if ($o_part->ctype_primary=='text' || $o_part->ctype_primary=='message') |
| | | { |
| | | // assume ISO-8859-1 if no charset specified |
| | | // assume default if no charset specified |
| | | if (empty($o_part->charset)) |
| | | $o_part->charset = 'ISO-8859-1'; |
| | | $o_part->charset = $this->default_charset; |
| | | |
| | | $body = rcube_charset_convert($body, $o_part->charset); |
| | | } |
| | |
| | | * Fetch message body of a specific message from the server |
| | | * |
| | | * @param int Message UID |
| | | * @return Message/part body |
| | | * @see ::get_message_part() |
| | | * @return string Message/part body |
| | | * @see rcube_imap::get_message_part() |
| | | */ |
| | | function &get_body($uid, $part=1) |
| | | { |
| | |
| | | * Returns the whole message source as string |
| | | * |
| | | * @param int Message UID |
| | | * @return Message source string |
| | | * @return string Message source string |
| | | */ |
| | | function &get_raw_body($uid) |
| | | { |
| | | if (!($msg_id = $this->_uid2id($uid))) |
| | | return FALSE; |
| | | |
| | | $body = iil_C_FetchPartHeader($this->conn, $this->mailbox, $msg_id, NULL); |
| | | $body .= iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, NULL, 1); |
| | | $body = iil_C_FetchPartHeader($this->conn, $this->mailbox, $msg_id, NULL); |
| | | $body .= iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, NULL, 1); |
| | | |
| | | return $body; |
| | | } |
| | |
| | | if (!($msg_id = $this->_uid2id($uid))) |
| | | return FALSE; |
| | | |
| | | print iil_C_FetchPartHeader($this->conn, $this->mailbox, $msg_id, NULL); |
| | | flush(); |
| | | iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, NULL, 2); |
| | | print iil_C_FetchPartHeader($this->conn, $this->mailbox, $msg_id, NULL); |
| | | flush(); |
| | | iil_C_HandlePartBody($this->conn, $this->mailbox, $msg_id, NULL, 2); |
| | | } |
| | | |
| | | |
| | |
| | | * Set message flag to one or several messages |
| | | * |
| | | * @param mixed Message UIDs as array or as comma-separated string |
| | | * @param string Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT |
| | | * @return True on success, False on failure |
| | | * @param string Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT |
| | | * @return boolean True on success, False on failure |
| | | */ |
| | | function set_flag($uids, $flag) |
| | | { |
| | |
| | | } |
| | | |
| | | |
| | | // append a mail message (source) to a specific mailbox |
| | | /** |
| | | * Append a mail message (source) to a specific mailbox |
| | | * |
| | | * @param string Target mailbox |
| | | * @param string Message source |
| | | * @return boolean True on success, False on error |
| | | */ |
| | | function save_message($mbox_name, &$message) |
| | | { |
| | | $mbox_name = stripslashes($mbox_name); |
| | |
| | | } |
| | | |
| | | |
| | | // move a message from one mailbox to another |
| | | /** |
| | | * Move a message from one mailbox to another |
| | | * |
| | | * @param string List of UIDs to move, separated by comma |
| | | * @param string Target mailbox |
| | | * @param string Source mailbox |
| | | * @return boolean True on success, False on error |
| | | */ |
| | | function move_message($uids, $to_mbox, $from_mbox='') |
| | | { |
| | | $to_mbox = stripslashes($to_mbox); |
| | |
| | | // make sure mailbox exists |
| | | if (!in_array($to_mbox, $this->_list_mailboxes())) |
| | | { |
| | | if (in_array(strtolower($to_mbox), $this->default_folders)) |
| | | if (in_array($to_mbox, $this->default_folders)) |
| | | $this->create_mailbox($to_mbox, TRUE); |
| | | else |
| | | return FALSE; |
| | |
| | | foreach ($a_uids as $uid) |
| | | $a_mids[] = $this->_uid2id($uid, $from_mbox); |
| | | |
| | | $moved = iil_C_Move($this->conn, join(',', $a_mids), $from_mbox, $to_mbox); |
| | | $iil_move = iil_C_Move($this->conn, join(',', $a_mids), $from_mbox, $to_mbox); |
| | | $moved = !($iil_move === false || $iil_move < 0); |
| | | |
| | | // send expunge command in order to have the moved message |
| | | // really deleted from the source mailbox |
| | |
| | | $this->_clear_messagecount($from_mbox); |
| | | $this->_clear_messagecount($to_mbox); |
| | | } |
| | | |
| | | // remove message ids from search set |
| | | if ($moved && $this->search_set && $from_mbox == $this->mailbox) |
| | | $this->search_set = array_diff($this->search_set, $a_mids); |
| | | |
| | | // update cached message headers |
| | | $cache_key = $from_mbox.'.msg'; |
| | |
| | | $start_index = 100000; |
| | | foreach ($a_uids as $uid) |
| | | { |
| | | if(($index = array_search($uid, $a_cache_index)) !== FALSE) |
| | | $start_index = min($index, $start_index); |
| | | if (($index = array_search($uid, $a_cache_index)) !== FALSE) |
| | | $start_index = min($index, $start_index); |
| | | } |
| | | |
| | | // clear cache from the lowest index on |
| | |
| | | } |
| | | |
| | | |
| | | // mark messages as deleted and expunge mailbox |
| | | /** |
| | | * Mark messages as deleted and expunge mailbox |
| | | * |
| | | * @param string List of UIDs to move, separated by comma |
| | | * @param string Source mailbox |
| | | * @return boolean True on success, False on error |
| | | */ |
| | | function delete_message($uids, $mbox_name='') |
| | | { |
| | | $mbox_name = stripslashes($mbox_name); |
| | |
| | | $this->_clear_messagecount($mailbox); |
| | | } |
| | | |
| | | // remove message ids from search set |
| | | if ($moved && $this->search_set && $mailbox == $this->mailbox) |
| | | $this->search_set = array_diff($this->search_set, $a_mids); |
| | | |
| | | // remove deleted messages from cache |
| | | $cache_key = $mailbox.'.msg'; |
| | | if ($deleted && ($a_cache_index = $this->get_message_cache_index($cache_key))) |
| | |
| | | $start_index = 100000; |
| | | foreach ($a_uids as $uid) |
| | | { |
| | | $index = array_search($uid, $a_cache_index); |
| | | $start_index = min($index, $start_index); |
| | | if (($index = array_search($uid, $a_cache_index)) !== FALSE) |
| | | $start_index = min($index, $start_index); |
| | | } |
| | | |
| | | // clear cache from the lowest index on |
| | |
| | | } |
| | | |
| | | |
| | | // clear all messages in a specific mailbox |
| | | /** |
| | | * Clear all messages in a specific mailbox |
| | | * |
| | | * @param string Mailbox name |
| | | * @return int Above 0 on success |
| | | */ |
| | | function clear_mailbox($mbox_name=NULL) |
| | | { |
| | | $mbox_name = stripslashes($mbox_name); |
| | |
| | | } |
| | | |
| | | |
| | | // send IMAP expunge command and clear cache |
| | | /** |
| | | * Send IMAP expunge command and clear cache |
| | | * |
| | | * @param string Mailbox name |
| | | * @param boolean False if cache should not be cleared |
| | | * @return boolean True on success |
| | | */ |
| | | function expunge($mbox_name='', $clear_cache=TRUE) |
| | | { |
| | | $mbox_name = stripslashes($mbox_name); |
| | |
| | | } |
| | | |
| | | |
| | | // send IMAP expunge command and clear cache |
| | | /** |
| | | * Send IMAP expunge command and clear cache |
| | | * |
| | | * @see rcube_imap::expunge() |
| | | * @access private |
| | | */ |
| | | function _expunge($mailbox, $clear_cache=TRUE) |
| | | { |
| | | $result = iil_C_Expunge($this->conn, $mailbox); |
| | | |
| | | if ($result>=0 && $clear_cache) |
| | | { |
| | | //$this->clear_message_cache($mailbox.'.msg'); |
| | | $this->clear_message_cache($mailbox.'.msg'); |
| | | $this->_clear_messagecount($mailbox); |
| | | } |
| | | |
| | |
| | | * Get a list of all folders available on the IMAP server |
| | | * |
| | | * @param string IMAP root dir |
| | | * @return array Inbdexed array with folder names |
| | | * @return array Indexed array with folder names |
| | | */ |
| | | function list_unsubscribed($root='') |
| | | { |
| | |
| | | |
| | | |
| | | /** |
| | | * Get quota |
| | | * Get mailbox quota information |
| | | * added by Nuny |
| | | * |
| | | * @return mixed Quota info or False if not supported |
| | | */ |
| | | function get_quota() |
| | | { |
| | | if ($this->get_capability('QUOTA')) |
| | | return array('total' => 2048 * 1024, 'used' => 500 * 1024, 'percent' => 32); //iil_C_GetQuota($this->conn); |
| | | return iil_C_GetQuota($this->conn); |
| | | |
| | | return FALSE; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * subscribe to a specific mailbox(es) |
| | | * Subscribe to a specific mailbox(es) |
| | | * |
| | | * @param string Mailbox name(s) |
| | | * @return boolean True on success |
| | | */ |
| | | function subscribe($mbox_name, $mode='subscribe') |
| | | function subscribe($mbox_name) |
| | | { |
| | | if (is_array($mbox_name)) |
| | | $a_mboxes = $mbox_name; |
| | |
| | | |
| | | |
| | | /** |
| | | * unsubscribe mailboxes |
| | | * Unsubscribe mailboxes |
| | | * |
| | | * @param string Mailbox name(s) |
| | | * @return boolean True on success |
| | | */ |
| | | function unsubscribe($mbox_name) |
| | | { |
| | |
| | | $abs_name = $this->_mod_mailbox($name); |
| | | $a_mailbox_cache = $this->get_cache('mailboxes'); |
| | | |
| | | if (strlen($abs_name) && (!is_array($a_mailbox_cache) || !in_array_nocase($abs_name, $a_mailbox_cache))) |
| | | if (strlen($abs_name) && (!is_array($a_mailbox_cache) || !in_array($abs_name, $a_mailbox_cache))) |
| | | $result = iil_C_CreateFolder($this->conn, $abs_name); |
| | | |
| | | // try to subscribe it |
| | | if ($subscribe) |
| | | if ($result && $subscribe) |
| | | $this->subscribe($name); |
| | | |
| | | return $result ? $name : FALSE; |
| | |
| | | * |
| | | * @param string Mailbox to rename (as utf-7 string) |
| | | * @param string New mailbox name (as utf-7 string) |
| | | * @param string Name of the renames mailbox, false on error |
| | | * @return string Name of the renames mailbox, False on error |
| | | */ |
| | | function rename_mailbox($mbox_name, $new_name) |
| | | { |
| | |
| | | if (strlen($abs_name)) |
| | | $result = iil_C_RenameFolder($this->conn, $mailbox, $abs_name); |
| | | |
| | | // clear cache |
| | | if ($result) |
| | | { |
| | | $delm = $this->get_hierarchy_delimiter(); |
| | | |
| | | // check if mailbox children are subscribed |
| | | foreach ($a_subscribed as $c_subscribed) |
| | | if (preg_match('/^'.preg_quote($mailbox.$delm, '/').'/', $c_subscribed)) |
| | | { |
| | | iil_C_UnSubscribe($this->conn, $c_subscribed); |
| | | iil_C_Subscribe($this->conn, preg_replace('/^'.preg_quote($mailbox, '/').'/', $abs_name, $c_subscribed)); |
| | | } |
| | | |
| | | // clear cache |
| | | $this->clear_message_cache($mailbox.'.msg'); |
| | | $this->clear_cache('mailboxes'); |
| | | } |
| | |
| | | |
| | | |
| | | /** |
| | | * remove mailboxes from server |
| | | * Remove mailboxes from server |
| | | * |
| | | * @param string Mailbox name |
| | | * @return boolean True on success |
| | | */ |
| | | function delete_mailbox($mbox_name) |
| | | { |
| | |
| | | $a_mboxes = $mbox_name; |
| | | else if (is_string($mbox_name) && strlen($mbox_name)) |
| | | $a_mboxes = explode(',', $mbox_name); |
| | | |
| | | $all_mboxes = iil_C_ListMailboxes($this->conn, $this->_mod_mailbox($root), '*'); |
| | | |
| | | if (is_array($a_mboxes)) |
| | | foreach ($a_mboxes as $mbox_name) |
| | |
| | | $result = iil_C_DeleteFolder($this->conn, $mailbox); |
| | | if ($result>=0) |
| | | $deleted = TRUE; |
| | | |
| | | foreach ($all_mboxes as $c_mbox) |
| | | { |
| | | $regex = preg_quote($mailbox . $this->delimiter, '/'); |
| | | $regex = '/^' . $regex . '/'; |
| | | if (preg_match($regex, $c_mbox)) |
| | | { |
| | | iil_C_UnSubscribe($this->conn, $c_mbox); |
| | | $result = iil_C_DeleteFolder($this->conn, $c_mbox); |
| | | if ($result>=0) |
| | | $deleted = TRUE; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // clear mailboxlist cache |
| | |
| | | foreach ($this->default_folders as $folder) |
| | | { |
| | | $abs_name = $this->_mod_mailbox($folder); |
| | | if (!in_array_nocase($abs_name, $a_subscribed)) |
| | | { |
| | | if (!in_array_nocase($abs_name, $a_folders)) |
| | | $this->create_mailbox($folder, TRUE); |
| | | else |
| | | $this->subscribe($folder); |
| | | } |
| | | if (!in_array_nocase($abs_name, $a_folders)) |
| | | $this->create_mailbox($folder, TRUE); |
| | | else if (!in_array_nocase($abs_name, $a_subscribed)) |
| | | $this->subscribe($folder); |
| | | } |
| | | } |
| | | |
| | |
| | | * internal caching methods |
| | | * --------------------------------*/ |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function set_caching($set) |
| | | { |
| | | if ($set && is_object($this->db)) |
| | |
| | | $this->caching_enabled = FALSE; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function get_cache($key) |
| | | { |
| | | // read cache |
| | |
| | | return $this->cache[$key]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function update_cache($key, $data) |
| | | { |
| | | $this->cache[$key] = $data; |
| | |
| | | $this->cache_changes[$key] = TRUE; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function write_cache() |
| | | { |
| | | if ($this->caching_enabled && $this->cache_changed) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function clear_cache($key=NULL) |
| | | { |
| | | if ($key===NULL) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function _read_cache_record($key) |
| | | { |
| | | $cache_data = FALSE; |
| | |
| | | } |
| | | } |
| | | |
| | | return $cache_data; |
| | | return $cache_data; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function _write_cache_record($key, $data) |
| | | { |
| | | if (!$this->db) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function _clear_cache_record($key) |
| | | { |
| | | $this->db->query( |
| | |
| | | * --------------------------------*/ |
| | | |
| | | |
| | | // checks if the cache is up-to-date |
| | | // return: -3 = off, -2 = incomplete, -1 = dirty |
| | | /** |
| | | * Checks if the cache is up-to-date |
| | | * |
| | | * @param string Mailbox name |
| | | * @param string Internal cache key |
| | | * @return int -3 = off, -2 = incomplete, -1 = dirty |
| | | */ |
| | | function check_cache_status($mailbox, $cache_key) |
| | | { |
| | | if (!$this->caching_enabled) |
| | |
| | | return -2; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function get_message_cache($key, $from, $to, $sort_field, $sort_order) |
| | | { |
| | | $cache_key = "$key:$from:$to:$sort_field:$sort_order"; |
| | |
| | | { |
| | | $uid = $sql_arr['uid']; |
| | | $this->cache[$cache_key][$uid] = unserialize($sql_arr['headers']); |
| | | |
| | | // featch headers if unserialize failed |
| | | if (empty($this->cache[$cache_key][$uid])) |
| | | $this->cache[$cache_key][$uid] = iil_C_FetchHeader($this->conn, preg_replace('/.msg$/', '', $key), $uid, true); |
| | | } |
| | | } |
| | | |
| | | return $this->cache[$cache_key]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function &get_cached_message($key, $uid, $struct=false) |
| | | { |
| | | if (!$this->caching_enabled) |
| | | return FALSE; |
| | | |
| | | $internal_key = '__single_msg'; |
| | | |
| | | if ($this->caching_enabled && (!isset($this->cache[$internal_key][$uid]) || |
| | | ($struct && empty($this->cache[$internal_key][$uid]->structure)))) |
| | | { |
| | |
| | | return $this->cache[$internal_key][$uid]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function get_message_cache_index($key, $force=FALSE, $sort_col='idx', $sort_order='ASC') |
| | | { |
| | | static $sa_message_index = array(); |
| | | |
| | | // empty key -> empty array |
| | | if (empty($key)) |
| | | if (!$this->caching_enabled || empty($key)) |
| | | return array(); |
| | | |
| | | if (!empty($sa_message_index[$key]) && !$force) |
| | |
| | | return $sa_message_index[$key]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function add_message_cache($key, $index, $headers, $struct=null) |
| | | { |
| | | if (empty($key) || !is_object($headers) || empty($headers->uid)) |
| | | return; |
| | | |
| | | // add to internal (fast) cache |
| | | $this->cache['__single_msg'][$headers->uid] = $headers; |
| | | $this->cache['__single_msg'][$headers->uid]->structure = $struct; |
| | | |
| | | // no further caching |
| | | if (!$this->caching_enabled) |
| | | return; |
| | | |
| | | |
| | | // check for an existing record (probly headers are cached but structure not) |
| | | $sql_result = $this->db->query( |
| | | "SELECT message_id |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function remove_message_cache($key, $index) |
| | | { |
| | | $this->db->query( |
| | |
| | | $index); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function clear_message_cache($key, $start_index=1) |
| | | { |
| | | $this->db->query( |
| | |
| | | * encoding/decoding methods |
| | | * --------------------------------*/ |
| | | |
| | | |
| | | function decode_address_list($input, $max=NULL) |
| | | /** |
| | | * Split an address list into a structured array list |
| | | * |
| | | * @param string Input string |
| | | * @param int List only this number of addresses |
| | | * @param boolean Decode address strings |
| | | * @return array Indexed list of addresses |
| | | */ |
| | | function decode_address_list($input, $max=null, $decode=true) |
| | | { |
| | | $a = $this->_parse_address_list($input); |
| | | $a = $this->_parse_address_list($input, $decode); |
| | | $out = array(); |
| | | |
| | | if (!is_array($a)) |
| | |
| | | $j++; |
| | | $address = $val['address']; |
| | | $name = preg_replace(array('/^[\'"]/', '/[\'"]$/'), '', trim($val['name'])); |
| | | $string = $name!==$address ? sprintf('%s <%s>', strpos($name, ',')!==FALSE ? '"'.$name.'"' : $name, $address) : $address; |
| | | if ($name && $address && $name != $address) |
| | | $string = sprintf('%s <%s>', strpos($name, ',')!==FALSE ? '"'.$name.'"' : $name, $address); |
| | | else if ($address) |
| | | $string = $address; |
| | | else if ($name) |
| | | $string = $name; |
| | | |
| | | $out[$j] = array('name' => $name, |
| | | 'mailto' => $address, |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Decode a message header value |
| | | * |
| | | * @param string Header value |
| | | * @param boolean Remove quotes if necessary |
| | | * @return string Decoded string |
| | | */ |
| | | function decode_header($input, $remove_quotes=FALSE) |
| | | { |
| | | $str = $this->decode_mime_string((string)$input); |
| | | $str = rcube_imap::decode_mime_string((string)$input, $this->default_charset); |
| | | if ($str{0}=='"' && $remove_quotes) |
| | | { |
| | | $str = str_replace('"', '', $str); |
| | | } |
| | | |
| | | return $str; |
| | | } |
| | |
| | | /** |
| | | * Decode a mime-encoded string to internal charset |
| | | * |
| | | * @access static |
| | | * @param string Header value |
| | | * @param string Fallback charset if none specified |
| | | * @return string Decoded string |
| | | * @static |
| | | */ |
| | | function decode_mime_string($input, $recursive=false) |
| | | function decode_mime_string($input, $fallback=null) |
| | | { |
| | | $out = ''; |
| | | |
| | |
| | | $rest = substr($input, $end_pos+2); |
| | | |
| | | $out .= rcube_imap::_decode_mime_string_part($encstr); |
| | | $out .= rcube_imap::decode_mime_string($rest); |
| | | $out .= rcube_imap::decode_mime_string($rest, $fallback); |
| | | |
| | | return $out; |
| | | } |
| | | |
| | | // no encoding information, defaults to what is specified in the class header |
| | | return rcube_charset_convert($input, 'ISO-8859-1'); |
| | | // no encoding information, use fallback |
| | | return rcube_charset_convert($input, !empty($fallback) ? $fallback : 'ISO-8859-1'); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Decode a part of a mime-encoded string |
| | | * |
| | | * @access static |
| | | * @access private |
| | | */ |
| | | function _decode_mime_string_part($str) |
| | | { |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Decode a mime part |
| | | * |
| | | * @param string Input string |
| | | * @param string Part encoding |
| | | * @return string Decoded string |
| | | * @access private |
| | | */ |
| | | function mime_decode($input, $encoding='7bit') |
| | | { |
| | | switch (strtolower($encoding)) |
| | |
| | | } |
| | | |
| | | |
| | | function mime_encode($input, $encoding='7bit') |
| | | { |
| | | switch ($encoding) |
| | | { |
| | | case 'quoted-printable': |
| | | return quoted_printable_encode($input); |
| | | break; |
| | | |
| | | case 'base64': |
| | | return base64_encode($input); |
| | | break; |
| | | |
| | | default: |
| | | return $input; |
| | | } |
| | | } |
| | | |
| | | |
| | | // convert body chars according to the ctype_parameters |
| | | /** |
| | | * Convert body charset to UTF-8 according to the ctype_parameters |
| | | * |
| | | * @param string Part body to decode |
| | | * @param string Charset to convert from |
| | | * @return string Content converted to internal charset |
| | | */ |
| | | function charset_decode($body, $ctype_param) |
| | | { |
| | | if (is_array($ctype_param) && !empty($ctype_param['charset'])) |
| | | return rcube_charset_convert($body, $ctype_param['charset']); |
| | | |
| | | // defaults to what is specified in the class header |
| | | return rcube_charset_convert($body, 'ISO-8859-1'); |
| | | return rcube_charset_convert($body, $this->default_charset); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Translate UID to message ID |
| | | * |
| | | * @param int Message UID |
| | | * @param string Mailbox name |
| | | * @return int Message ID |
| | | */ |
| | | function get_id($uid, $mbox_name=NULL) |
| | | { |
| | | $mailbox = $mbox_name ? $this->_mod_mailbox($mbox_name) : $this->mailbox; |
| | | return $this->_uid2id($uid, $mailbox); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Translate message number to UID |
| | | * |
| | | * @param int Message ID |
| | | * @param string Mailbox name |
| | | * @return int Message UID |
| | | */ |
| | | function get_uid($id,$mbox_name=NULL) |
| | | { |
| | | $mailbox = $mbox_name ? $this->_mod_mailbox($mbox_name) : $this->mailbox; |
| | | return $this->_id2uid($id, $mailbox); |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | * --------------------------------*/ |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function _mod_mailbox($mbox_name, $mode='in') |
| | | { |
| | | if ((!empty($this->root_ns) && $this->root_ns == $mbox_name) || $mbox_name == 'INBOX') |
| | |
| | | return $mbox_name; |
| | | } |
| | | |
| | | /** |
| | | * Validate the given input and save to local properties |
| | | * @access private |
| | | */ |
| | | function _set_sort_order($sort_field, $sort_order) |
| | | { |
| | | if ($sort_field != null) |
| | | $this->sort_field = asciiwords($sort_field); |
| | | if ($sort_order != null) |
| | | $this->sort_order = strtoupper($sort_order) == 'DESC' ? 'DESC' : 'ASC'; |
| | | } |
| | | |
| | | // sort mailboxes first by default folders and then in alphabethical order |
| | | /** |
| | | * Sort mailboxes first by default folders and then in alphabethical order |
| | | * @access private |
| | | */ |
| | | function _sort_mailbox_list($a_folders) |
| | | { |
| | | $a_out = $a_defaults = array(); |
| | |
| | | foreach($a_folders as $i => $folder) |
| | | { |
| | | if ($folder{0}=='.') |
| | | continue; |
| | | continue; |
| | | |
| | | if (($p = array_search(strtolower($folder), $this->default_folders_lc))!==FALSE) |
| | | $a_defaults[$p] = $folder; |
| | | if (($p = array_search(strtolower($folder), $this->default_folders_lc)) !== false && !$a_defaults[$p]) |
| | | $a_defaults[$p] = $folder; |
| | | else |
| | | $a_out[] = $folder; |
| | | } |
| | | |
| | | sort($a_out); |
| | | natcasesort($a_out); |
| | | ksort($a_defaults); |
| | | |
| | | return array_merge($a_defaults, $a_out); |
| | | } |
| | | |
| | | function get_id($uid, $mbox_name=NULL) |
| | | { |
| | | return $this->_uid2id($uid, $mbox_name); |
| | | } |
| | | |
| | | function get_uid($id,$mbox_name=NULL) |
| | | { |
| | | return $this->_id2uid($id, $mbox_name); |
| | | } |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function _uid2id($uid, $mbox_name=NULL) |
| | | { |
| | | if (!$mbox_name) |
| | |
| | | return $this->uid_id_map[$mbox_name][$uid]; |
| | | } |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function _id2uid($id, $mbox_name=NULL) |
| | | { |
| | | if (!$mbox_name) |
| | | $mbox_name = $this->mailbox; |
| | | |
| | | return iil_C_ID2UID($this->conn, $mbox_name, $id); |
| | | $index = array_flip((array)$this->uid_id_map[$mbox_name]); |
| | | if (isset($index[$id])) |
| | | $uid = $index[$id]; |
| | | else |
| | | { |
| | | $uid = iil_C_ID2UID($this->conn, $mbox_name, $id); |
| | | $this->uid_id_map[$mbox_name][$uid] = $id; |
| | | } |
| | | |
| | | return $uid; |
| | | } |
| | | |
| | | |
| | | // parse string or array of server capabilities and put them in internal array |
| | | /** |
| | | * Parse string or array of server capabilities and put them in internal array |
| | | * @access private |
| | | */ |
| | | function _parse_capability($caps) |
| | | { |
| | | if (!is_array($caps)) |
| | |
| | | } |
| | | |
| | | |
| | | // subscribe/unsubscribe a list of mailboxes and update local cache |
| | | /** |
| | | * Subscribe/unsubscribe a list of mailboxes and update local cache |
| | | * @access private |
| | | */ |
| | | function _change_subscription($a_mboxes, $mode) |
| | | { |
| | | $updated = FALSE; |
| | |
| | | } |
| | | |
| | | |
| | | // increde/decrese messagecount for a specific mailbox |
| | | /** |
| | | * Increde/decrese messagecount for a specific mailbox |
| | | * @access private |
| | | */ |
| | | function _set_messagecount($mbox_name, $mode, $increment) |
| | | { |
| | | $a_mailbox_cache = FALSE; |
| | |
| | | } |
| | | |
| | | |
| | | // remove messagecount of a specific mailbox from cache |
| | | /** |
| | | * Remove messagecount of a specific mailbox from cache |
| | | * @access private |
| | | */ |
| | | function _clear_messagecount($mbox_name='') |
| | | { |
| | | $a_mailbox_cache = FALSE; |
| | |
| | | } |
| | | |
| | | |
| | | // split RFC822 header string into an associative array |
| | | /** |
| | | * Split RFC822 header string into an associative array |
| | | * @access private |
| | | */ |
| | | function _parse_headers($headers) |
| | | { |
| | | $a_headers = array(); |
| | |
| | | } |
| | | |
| | | |
| | | function _parse_address_list($str) |
| | | /** |
| | | * @access private |
| | | */ |
| | | function _parse_address_list($str, $decode=true) |
| | | { |
| | | $a = $this->_explode_quoted_string(',', $str); |
| | | // remove any newlines and carriage returns before |
| | | $a = $this->_explode_quoted_string('[,;]', preg_replace( "/[\r\n]/", " ", $str)); |
| | | $result = array(); |
| | | |
| | | foreach ($a as $key => $val) |
| | | { |
| | | $val = str_replace("\"<", "\" <", $val); |
| | | $sub_a = $this->_explode_quoted_string(' ', $this->decode_header($val)); |
| | | $val = preg_replace("/([\"\w])</", "$1 <", $val); |
| | | $sub_a = $this->_explode_quoted_string(' ', $decode ? $this->decode_header($val) : $val); |
| | | $result[$key]['name'] = ''; |
| | | |
| | | foreach ($sub_a as $k => $v) |
| | | { |
| | | if ((strpos($v, '@') > 0) && (strpos($v, '.') > 0)) |
| | | if (strpos($v, '@') > 0) |
| | | $result[$key]['address'] = str_replace('<', '', str_replace('>', '', $v)); |
| | | else |
| | | $result[$key]['name'] .= (empty($result[$key]['name'])?'':' ').str_replace("\"",'',stripslashes($v)); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function _explode_quoted_string($delimiter, $string) |
| | | { |
| | | $quotes = explode("\"", $string); |
| | | foreach ($quotes as $key => $val) |
| | | if (($key % 2) == 1) |
| | | $quotes[$key] = str_replace($delimiter, "_!@!_", $quotes[$key]); |
| | | |
| | | $string = implode("\"", $quotes); |
| | | |
| | | $result = explode($delimiter, $string); |
| | | foreach ($result as $key => $val) |
| | | $result[$key] = str_replace("_!@!_", $delimiter, $result[$key]); |
| | | $result = array(); |
| | | $strlen = strlen($string); |
| | | for ($q=$p=$i=0; $i < $strlen; $i++) |
| | | { |
| | | if ($string{$i} == "\"" && $string{$i-1} != "\\") |
| | | $q = $q ? false : true; |
| | | else if (!$q && preg_match("/$delimiter/", $string{$i})) |
| | | { |
| | | $result[] = substr($string, $p, $i - $p); |
| | | $p = $i + 1; |
| | | } |
| | | } |
| | | |
| | | $result[] = substr($string, $p); |
| | | return $result; |
| | | } |
| | | } |
| | | |
| | | } // end class rcube_imap |
| | | |
| | | |
| | | /** |
| | | * Class representing a message part |
| | | * |
| | | * @package Mail |
| | | */ |
| | | class rcube_message_part |
| | | { |
| | |
| | | var $ctype_secondary = 'plain'; |
| | | var $mimetype = 'text/plain'; |
| | | var $disposition = ''; |
| | | var $filename = ''; |
| | | var $encoding = '8bit'; |
| | | var $charset = ''; |
| | | var $size = 0; |
| | |
| | | |
| | | |
| | | /** |
| | | * rcube_header_sorter |
| | | * |
| | | * Class for sorting an array of iilBasicHeader objects in a predetermined order. |
| | | * |
| | | * @package Mail |
| | | * @author Eric Stadtherr |
| | | */ |
| | | class rcube_header_sorter |
| | |
| | | var $sequence_numbers = array(); |
| | | |
| | | /** |
| | | * set the predetermined sort order. |
| | | * Set the predetermined sort order. |
| | | * |
| | | * @param array $seqnums numerically indexed array of IMAP message sequence numbers |
| | | * @param array Numerically indexed array of IMAP message sequence numbers |
| | | */ |
| | | function set_sequence_numbers($seqnums) |
| | | { |
| | |
| | | } |
| | | |
| | | /** |
| | | * sort the array of header objects |
| | | * Sort the array of header objects |
| | | * |
| | | * @param array $headers array of iilBasicHeader objects indexed by UID |
| | | * @param array Array of iilBasicHeader objects indexed by UID |
| | | */ |
| | | function sort_headers(&$headers) |
| | | { |
| | |
| | | } |
| | | |
| | | /** |
| | | * get the position of a message sequence number in my sequence_numbers array |
| | | * Get the position of a message sequence number in my sequence_numbers array |
| | | * |
| | | * @param integer $seqnum message sequence number contained in sequence_numbers |
| | | * @param int Message sequence number contained in sequence_numbers |
| | | * @return int Position, -1 if not found |
| | | */ |
| | | function position_of($seqnum) |
| | | { |
| | |
| | | /** |
| | | * Add quoted-printable encoding to a given string |
| | | * |
| | | * @param string $input string to encode |
| | | * @param int $line_max add new line after this number of characters |
| | | * @param boolena $space_conf true if spaces should be converted into =20 |
| | | * @return encoded string |
| | | * @param string String to encode |
| | | * @param int Add new line after this number of characters |
| | | * @param boolean True if spaces should be converted into =20 |
| | | * @return string Encoded string |
| | | */ |
| | | function quoted_printable_encode($input, $line_max=76, $space_conv=false) |
| | | { |