| | |
| | | |
| | | $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)); |
| | |
| | | // get server properties |
| | | if ($this->conn) |
| | | { |
| | | if (!empty($this->conn->delimiter)) |
| | | $this->delimiter = $this->conn->delimiter; |
| | | if (!empty($this->conn->rootdir)) |
| | | { |
| | | $this->set_rootdir($this->conn->rootdir); |
| | | $this->root_ns = preg_replace('/[.\/]$/', '', $this->conn->rootdir); |
| | | } |
| | | if (empty($this->delimiter)) |
| | | $this->get_hierarchy_delimiter(); |
| | | } |
| | | |
| | | return $this->conn ? TRUE : FALSE; |
| | |
| | | { |
| | | if ($this->skip_deleted) { |
| | | // @TODO: this could be cached |
| | | $msg_index = $this->_search_index($mailbox, 'ALL UNDELETED'); |
| | | $max = max($msg_index); |
| | | list($begin, $end) = $this->_get_message_range(count($msg_index), $page); |
| | | $msg_index = array_slice($msg_index, $begin, $end-$begin); |
| | | if ($msg_index = $this->_search_index($mailbox, 'ALL UNDELETED')) { |
| | | $max = max($msg_index); |
| | | list($begin, $end) = $this->_get_message_range(count($msg_index), $page); |
| | | $msg_index = array_slice($msg_index, $begin, $end-$begin); |
| | | } |
| | | } else if ($max = iil_C_CountMessages($this->conn, $mailbox)) { |
| | | list($begin, $end) = $this->_get_message_range($max, $page); |
| | | $msg_index = range($begin+1, $end); |
| | | } else |
| | | return array(); |
| | | $msg_index = array(); |
| | | |
| | | if ($slice) |
| | | $msg_index = array_slice($msg_index, ($this->sort_order == 'DESC' ? 0 : -$slice), $slice); |
| | | |
| | | // fetch reqested headers from server |
| | | $this->_fetch_headers($mailbox, join(",", $msg_index), $a_msg_headers, $cache_key); |
| | | if ($msg_index) |
| | | $this->_fetch_headers($mailbox, join(",", $msg_index), $a_msg_headers, $cache_key); |
| | | } |
| | | // use SORT command |
| | | else if ($this->get_capability('sort') && ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) |
| | |
| | | $this->_fetch_headers($mailbox, join(',', $msg_index), $a_msg_headers, $cache_key); |
| | | } |
| | | // fetch specified header for all messages and sort |
| | | else |
| | | else if ($a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:*", $this->sort_field, $this->skip_deleted)) |
| | | { |
| | | $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:*", $this->sort_field, $this->skip_deleted); |
| | | |
| | | if (empty($a_index)) |
| | | return array(); |
| | | |
| | | asort($a_index); // ASC |
| | | $msg_index = array_keys($a_index); |
| | | $max = max($msg_index); |
| | |
| | | else |
| | | $this->struct_charset = $this->_structure_charset($structure); |
| | | |
| | | /* |
| | | @TODO: here we can recognize malformed BODYSTRUCTURE and parse |
| | | the message in other way to create our own message structure. |
| | | Example of structure for malformed MIME message: |
| | | ("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 2154 70 NIL NIL NIL) |
| | | |
| | | if ($headers->ctype != 'text/plain' |
| | | && !is_array($structure[0]) && $structure[0] == 'text' |
| | | && !is_array($structure[1]) && $structure[1] == 'plain') |
| | | { } |
| | | */ |
| | | // Here we can recognize malformed BODYSTRUCTURE and |
| | | // 1. [@TODO] parse the message in other way to create our own message structure |
| | | // 2. or just show the raw message body. |
| | | // Example of structure for malformed MIME message: |
| | | // ("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 2154 70 NIL NIL NIL) |
| | | if ($headers->ctype && $headers->ctype != 'text/plain' |
| | | && $structure[0] == 'text' && $structure[1] == 'plain') { |
| | | return false; |
| | | } |
| | | |
| | | $struct = &$this->_structure_part($structure); |
| | | $struct->headers = get_object_vars($headers); |
| | |
| | | } |
| | | |
| | | if ($struct->ctype_primary=='message') { |
| | | if (is_array($part[8]) && empty($struct->parts)) |
| | | if (is_array($part[8]) && $di != 8 && empty($struct->parts)) |
| | | $struct->parts[] = $this->_structure_part($part[8], ++$count, $struct->mime_id); |
| | | } |
| | | |
| | |
| | | // make sure mailbox exists |
| | | if ($to_mbox != 'INBOX' && !in_array($to_mbox, $this->_list_mailboxes())) |
| | | { |
| | | if (in_array($to_mbox_in, $this->default_folders)) |
| | | $this->create_mailbox($to_mbox_in, TRUE); |
| | | if (in_array($tbox, $this->default_folders)) |
| | | $this->create_mailbox($tbox, TRUE); |
| | | else |
| | | return FALSE; |
| | | } |