| | |
| | | protected $search_sort_field = ''; |
| | | protected $search_threads = false; |
| | | protected $search_sorted = false; |
| | | protected $options = array('auth_method' => 'check'); |
| | | protected $options = array('auth_type' => 'check'); |
| | | protected $caching = false; |
| | | protected $messages_caching = false; |
| | | protected $threading = false; |
| | |
| | | public function check_permflag($flag) |
| | | { |
| | | $flag = strtoupper($flag); |
| | | $imap_flag = $this->conn->flags[$flag]; |
| | | $perm_flags = $this->get_permflags($this->folder); |
| | | $imap_flag = $this->conn->flags[$flag]; |
| | | |
| | | return in_array_nocase($imap_flag, $perm_flags); |
| | | return $imap_flag && !empty($perm_flags) && in_array_nocase($imap_flag, $perm_flags); |
| | | } |
| | | |
| | | |
| | |
| | | if (!strlen($folder)) { |
| | | return array(); |
| | | } |
| | | /* |
| | | Checking PERMANENTFLAGS is rather rare, so we disable caching of it |
| | | Re-think when we'll use it for more than only MDNSENT flag |
| | | |
| | | $cache_key = 'mailboxes.permanentflags.' . $folder; |
| | | $permflags = $this->get_cache($cache_key); |
| | | |
| | | if ($permflags !== null) { |
| | | return explode(' ', $permflags); |
| | | } |
| | | */ |
| | | if (!$this->check_connection()) { |
| | | return array(); |
| | | } |
| | |
| | | if (!is_array($permflags)) { |
| | | $permflags = array(); |
| | | } |
| | | /* |
| | | // Store permflags as string to limit cached object size |
| | | $this->update_cache($cache_key, implode(' ', $permflags)); |
| | | */ |
| | | |
| | | return $permflags; |
| | | } |
| | | |
| | |
| | | // use memory less expensive (and quick) method for big result set |
| | | $index = clone $this->index('', $this->sort_field, $this->sort_order); |
| | | // get messages uids for one page... |
| | | $index->slice($start_msg, min($cnt-$from, $this->page_size)); |
| | | $index->slice($from, min($cnt-$from, $this->page_size)); |
| | | |
| | | if ($slice) { |
| | | $index->slice(-$slice, $slice); |
| | |
| | | // THREAD=REFERENCES: sorting by sent date of root message |
| | | // THREAD=REFS: sorting by the most recent date in each thread |
| | | |
| | | if ($this->sort_field && ($this->sort_field != 'date' || $this->get_capability('THREAD') != 'REFS')) { |
| | | $index = $this->index_direct($this->folder, $this->sort_field, $this->sort_order, false); |
| | | if ($this->threading != 'REFS' || ($this->sort_field && $this->sort_field != 'date')) { |
| | | $sortby = $this->sort_field ? $this->sort_field : 'date'; |
| | | $index = $this->index_direct($this->folder, $sortby, $this->sort_order, false); |
| | | |
| | | if (!$index->is_empty()) { |
| | | $threads->sort($index); |
| | | } |
| | | } |
| | | else { |
| | | if ($this->sort_order != $threads->get_parameters('ORDER')) { |
| | | $threads->revert(); |
| | | } |
| | | else if ($this->sort_order != $threads->get_parameters('ORDER')) { |
| | | $threads->revert(); |
| | | } |
| | | } |
| | | |
| | |
| | | // Example of structure for malformed MIME message: |
| | | // ("text" "plain" NIL NIL NIL "7bit" 2154 70 NIL NIL NIL) |
| | | if ($headers->ctype && !is_array($structure[0]) && $headers->ctype != 'text/plain' |
| | | && strtolower($structure[0].'/'.$structure[1]) == 'text/plain') { |
| | | && strtolower($structure[0].'/'.$structure[1]) == 'text/plain' |
| | | ) { |
| | | // A special known case "Content-type: text" (#1488968) |
| | | if ($headers->ctype == 'text') { |
| | | $structure[1] = 'plain'; |
| | | $headers->ctype = 'text/plain'; |
| | | } |
| | | // we can handle single-part messages, by simple fix in structure (#1486898) |
| | | if (preg_match('/^(text|application)\/(.*)/', $headers->ctype, $m)) { |
| | | else if (preg_match('/^(text|application)\/(.*)/', $headers->ctype, $m)) { |
| | | $structure[0] = $m[1]; |
| | | $structure[1] = $m[2]; |
| | | } |
| | |
| | | $struct = $this->structure_part($structure, 0, '', $headers); |
| | | } |
| | | |
| | | // don't trust given content-type |
| | | if (empty($struct->parts) && !empty($headers->ctype)) { |
| | | $struct->mime_id = '1'; |
| | | $struct->mimetype = strtolower($headers->ctype); |
| | | list($struct->ctype_primary, $struct->ctype_secondary) = explode('/', $struct->mimetype); |
| | | // some workarounds on simple messages... |
| | | if (empty($struct->parts)) { |
| | | // ...don't trust given content-type |
| | | if (!empty($headers->ctype)) { |
| | | $struct->mime_id = '1'; |
| | | $struct->mimetype = strtolower($headers->ctype); |
| | | list($struct->ctype_primary, $struct->ctype_secondary) = explode('/', $struct->mimetype); |
| | | } |
| | | |
| | | // ...and charset (there's a case described in #1488968 where invalid content-type |
| | | // results in invalid charset in BODYSTRUCTURE) |
| | | if (!empty($headers->charset) && $headers->charset != $struct->ctype_parameters['charset']) { |
| | | $struct->charset = $headers->charset; |
| | | $struct->ctype_parameters['charset'] = $headers->charset; |
| | | } |
| | | } |
| | | |
| | | $headers->structure = $struct; |
| | |
| | | |
| | | // filter folders list according to rights requirements |
| | | if ($rights && $this->get_capability('ACL')) { |
| | | $a_folders = $this->filter_rights($a_folders, $rights); |
| | | $a_mboxes = $this->filter_rights($a_mboxes, $rights); |
| | | } |
| | | |
| | | // filter folders and sort them |
| | |
| | | { |
| | | if (!empty($this->options['fetch_headers'])) { |
| | | $headers = explode(' ', $this->options['fetch_headers']); |
| | | $headers = array_map('strtoupper', $headers); |
| | | } |
| | | else { |
| | | $headers = array(); |
| | |
| | | $headers = array_merge($headers, $this->all_headers); |
| | | } |
| | | |
| | | return implode(' ', array_unique($headers)); |
| | | return $headers; |
| | | } |
| | | |
| | | |