annotate program/lib/Roundcube/rcube_imap.php @ 24:e53add5ddac5

More cleaning up php8 Warnings/deprecations
author Charlie Root
date Fri, 17 Oct 2025 17:31:22 -0400
parents 303b85d5b561
children c32b53434b47
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1 <?php
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4 +-----------------------------------------------------------------------+
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5 | This file is part of the Roundcube Webmail client |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6 | Copyright (C) 2005-2012, The Roundcube Dev Team |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7 | Copyright (C) 2011-2012, Kolab Systems AG |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8 | |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9 | Licensed under the GNU General Public License version 3 or |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
10 | any later version with exceptions for skins & plugins. |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
11 | See the README file for a full license statement. |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
12 | |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
13 | PURPOSE: |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
14 | IMAP Storage Engine |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
15 +-----------------------------------------------------------------------+
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
16 | Author: Thomas Bruederli <roundcube@gmail.com> |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
17 | Author: Aleksander Machniak <alec@alec.pl> |
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
18 +-----------------------------------------------------------------------+
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
19 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
20
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
21 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
22 * Interface class for accessing an IMAP server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
23 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
24 * @package Framework
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
25 * @subpackage Storage
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
26 * @author Thomas Bruederli <roundcube@gmail.com>
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
27 * @author Aleksander Machniak <alec@alec.pl>
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
28 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
29 class rcube_imap extends rcube_storage
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
30 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
31 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
32 * Instance of rcube_imap_generic
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
33 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
34 * @var rcube_imap_generic
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
35 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
36 public $conn;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
37
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
38 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
39 * Instance of rcube_imap_cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
40 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
41 * @var rcube_imap_cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
42 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
43 protected $mcache;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
44
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
45 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
46 * Instance of rcube_cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
47 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
48 * @var rcube_cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
49 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
50 protected $cache;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
51
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
52 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
53 * Internal (in-memory) cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
54 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
55 * @var array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
56 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
57 protected $icache = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
58
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
59 protected $plugins;
21
73124dd49283 More cleaning up php8 Warnings/deprecations,
Charlie Root
parents: 19
diff changeset
60 protected $parts;
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
61 protected $delimiter;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
62 protected $namespace;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
63 protected $sort_field = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
64 protected $sort_order = 'DESC';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
65 protected $struct_charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
66 protected $search_set;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
67 protected $search_string = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
68 protected $search_charset = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
69 protected $search_sort_field = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
70 protected $search_threads = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
71 protected $search_sorted = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
72 protected $options = array('auth_type' => 'check');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
73 protected $caching = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
74 protected $messages_caching = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
75 protected $threading = false;
15
85a746e95663 slowly working through deprecations/warnings from 8.3
Charlie Root
parents: 5
diff changeset
76 protected $connect_done;
85a746e95663 slowly working through deprecations/warnings from 8.3
Charlie Root
parents: 5
diff changeset
77 protected $sort_folder_collator;
19
b6a96bdd6b29 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 17
diff changeset
78 protected $msg_uid;
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
79
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
80 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
81 * Object constructor.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
82 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
83 public function __construct()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
84 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
85 $this->conn = new rcube_imap_generic();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
86 $this->plugins = rcube::get_instance()->plugins;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
87
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
88 // Set namespace and delimiter from session,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
89 // so some methods would work before connection
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
90 if (isset($_SESSION['imap_namespace'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
91 $this->namespace = $_SESSION['imap_namespace'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
92 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
93 if (isset($_SESSION['imap_delimiter'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
94 $this->delimiter = $_SESSION['imap_delimiter'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
95 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
96 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
97
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
98 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
99 * Magic getter for backward compat.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
100 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
101 * @deprecated.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
102 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
103 public function __get($name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
104 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
105 if (isset($this->{$name})) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
106 return $this->{$name};
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
107 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
108 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
109
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
110 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
111 * Connect to an IMAP server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
112 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
113 * @param string $host Host to connect
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
114 * @param string $user Username for IMAP account
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
115 * @param string $pass Password for IMAP account
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
116 * @param integer $port Port to connect to
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
117 * @param string $use_ssl SSL schema (either ssl or tls) or null if plain connection
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
118 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
119 * @return boolean True on success, False on failure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
120 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
121 public function connect($host, $user, $pass, $port=143, $use_ssl=null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
122 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
123 // check for OpenSSL support in PHP build
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
124 if ($use_ssl && extension_loaded('openssl')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
125 $this->options['ssl_mode'] = $use_ssl == 'imaps' ? 'ssl' : $use_ssl;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
126 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
127 else if ($use_ssl) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
128 rcube::raise_error(array('code' => 403, 'type' => 'imap',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
129 'file' => __FILE__, 'line' => __LINE__,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
130 'message' => "OpenSSL not available"), true, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
131 $port = 143;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
132 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
133
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
134 $this->options['port'] = $port;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
135
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
136 if ($this->options['debug']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
137 $this->set_debug(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
138
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
139 $this->options['ident'] = array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
140 'name' => 'Roundcube',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
141 'version' => RCUBE_VERSION,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
142 'php' => PHP_VERSION,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
143 'os' => PHP_OS,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
144 'command' => $_SERVER['REQUEST_URI'],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
145 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
146 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
147
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
148 $attempt = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
149 do {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
150 $data = $this->plugins->exec_hook('storage_connect',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
151 array_merge($this->options, array('host' => $host, 'user' => $user,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
152 'attempt' => ++$attempt)));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
153
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
154 if (!empty($data['pass'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
155 $pass = $data['pass'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
156 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
157
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
158 // Handle per-host socket options
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
159 rcube_utils::parse_socket_options($data['socket_options'], $data['host']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
160
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
161 $this->conn->connect($data['host'], $data['user'], $pass, $data);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
162 } while(!$this->conn->connected() && $data['retry']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
163
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
164 $config = array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
165 'host' => $data['host'],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
166 'user' => $data['user'],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
167 'password' => $pass,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
168 'port' => $port,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
169 'ssl' => $use_ssl,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
170 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
171
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
172 $this->options = array_merge($this->options, $config);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
173 $this->connect_done = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
174
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
175 if ($this->conn->connected()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
176 // check for session identifier
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
177 $session = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
178 if (preg_match('/\s+SESSIONID=([^=\s]+)/', $this->conn->result, $m)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
179 $session = $m[1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
180 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
181
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
182 // get namespace and delimiter
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
183 $this->set_env();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
184
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
185 // trigger post-connect hook
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
186 $this->plugins->exec_hook('storage_connected', array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
187 'host' => $host, 'user' => $user, 'session' => $session
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
188 ));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
189
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
190 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
191 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
192 // write error log
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
193 else if ($this->conn->error) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
194 if ($pass && $user) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
195 $message = sprintf("Login failed for %s from %s. %s",
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
196 $user, rcube_utils::remote_ip(), $this->conn->error);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
197
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
198 rcube::raise_error(array('code' => 403, 'type' => 'imap',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
199 'file' => __FILE__, 'line' => __LINE__,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
200 'message' => $message), true, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
201 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
202 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
203
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
204 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
205 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
206
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
207 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
208 * Close IMAP connection.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
209 * Usually done on script shutdown
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
210 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
211 public function close()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
212 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
213 $this->connect_done = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
214 $this->conn->closeConnection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
215
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
216 if ($this->mcache) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
217 $this->mcache->close();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
218 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
219 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
220
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
221 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
222 * Check connection state, connect if not connected.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
223 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
224 * @return bool Connection state.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
225 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
226 public function check_connection()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
227 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
228 // Establish connection if it wasn't done yet
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
229 if (!$this->connect_done && !empty($this->options['user'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
230 return $this->connect(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
231 $this->options['host'],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
232 $this->options['user'],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
233 $this->options['password'],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
234 $this->options['port'],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
235 $this->options['ssl']
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
236 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
237 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
238
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
239 return $this->is_connected();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
240 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
241
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
242 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
243 * Checks IMAP connection.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
244 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
245 * @return boolean TRUE on success, FALSE on failure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
246 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
247 public function is_connected()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
248 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
249 return $this->conn->connected();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
250 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
251
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
252 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
253 * Returns code of last error
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
254 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
255 * @return int Error code
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
256 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
257 public function get_error_code()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
258 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
259 return $this->conn->errornum;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
260 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
261
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
262 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
263 * Returns text of last error
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
264 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
265 * @return string Error string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
266 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
267 public function get_error_str()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
268 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
269 return $this->conn->error;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
270 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
271
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
272 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
273 * Returns code of last command response
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
274 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
275 * @return int Response code
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
276 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
277 public function get_response_code()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
278 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
279 switch ($this->conn->resultcode) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
280 case 'NOPERM':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
281 return self::NOPERM;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
282 case 'READ-ONLY':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
283 return self::READONLY;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
284 case 'TRYCREATE':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
285 return self::TRYCREATE;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
286 case 'INUSE':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
287 return self::INUSE;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
288 case 'OVERQUOTA':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
289 return self::OVERQUOTA;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
290 case 'ALREADYEXISTS':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
291 return self::ALREADYEXISTS;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
292 case 'NONEXISTENT':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
293 return self::NONEXISTENT;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
294 case 'CONTACTADMIN':
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
295 return self::CONTACTADMIN;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
296 default:
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
297 return self::UNKNOWN;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
298 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
299 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
300
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
301 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
302 * Activate/deactivate debug mode
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
303 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
304 * @param boolean $dbg True if IMAP conversation should be logged
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
305 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
306 public function set_debug($dbg = true)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
307 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
308 $this->options['debug'] = $dbg;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
309 $this->conn->setDebug($dbg, array($this, 'debug_handler'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
310 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
311
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
312 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
313 * Set internal folder reference.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
314 * All operations will be performed on this folder.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
315 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
316 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
317 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
318 public function set_folder($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
319 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
320 $this->folder = $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
321 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
322
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
323 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
324 * Save a search result for future message listing methods
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
325 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
326 * @param array $set Search set, result from rcube_imap::get_search_set():
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
327 * 0 - searching criteria, string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
328 * 1 - search result, rcube_result_index|rcube_result_thread
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
329 * 2 - searching character set, string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
330 * 3 - sorting field, string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
331 * 4 - true if sorted, bool
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
332 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
333 public function set_search_set($set)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
334 {
22
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 21
diff changeset
335 $set = (array) $set;
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 21
diff changeset
336
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 21
diff changeset
337 $this->search_string = $set[0] ?? null;
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 21
diff changeset
338 $this->search_set = $set[1] ?? null;
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 21
diff changeset
339 $this->search_charset = $set[2] ?? null;
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 21
diff changeset
340 $this->search_sort_field = $set[3] ?? null;
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 21
diff changeset
341 $this->search_sorted = $set[4] ?? null;
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 21
diff changeset
342 $this->search_threads = is_a($this->search_set, 'rcube_result_thread');
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 21
diff changeset
343
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 21
diff changeset
344 if (is_a($this->search_set, 'rcube_result_multifolder')) {
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 21
diff changeset
345 $this->set_threading(false);
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 21
diff changeset
346 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
347 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
348
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
349 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
350 * Return the saved search set as hash array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
351 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
352 * @return array Search set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
353 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
354 public function get_search_set()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
355 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
356 if (empty($this->search_set)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
357 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
358 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
359
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
360 return array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
361 $this->search_string,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
362 $this->search_set,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
363 $this->search_charset,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
364 $this->search_sort_field,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
365 $this->search_sorted,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
366 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
367 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
368
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
369 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
370 * Returns the IMAP server's capability.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
371 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
372 * @param string $cap Capability name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
373 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
374 * @return mixed Capability value or TRUE if supported, FALSE if not
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
375 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
376 public function get_capability($cap)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
377 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
378 $cap = strtoupper($cap);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
379 $sess_key = "STORAGE_$cap";
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
380
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
381 if (!isset($_SESSION[$sess_key])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
382 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
383 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
384 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
385
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
386 $_SESSION[$sess_key] = $this->conn->getCapability($cap);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
387 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
388
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
389 return $_SESSION[$sess_key];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
390 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
391
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
392 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
393 * Checks the PERMANENTFLAGS capability of the current folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
394 * and returns true if the given flag is supported by the IMAP server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
395 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
396 * @param string $flag Permanentflag name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
397 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
398 * @return boolean True if this flag is supported
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
399 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
400 public function check_permflag($flag)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
401 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
402 $flag = strtoupper($flag);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
403 $perm_flags = $this->get_permflags($this->folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
404 $imap_flag = $this->conn->flags[$flag];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
405
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
406 return $imap_flag && !empty($perm_flags) && in_array_nocase($imap_flag, $perm_flags);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
407 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
408
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
409 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
410 * Returns PERMANENTFLAGS of the specified folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
411 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
412 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
413 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
414 * @return array Flags
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
415 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
416 public function get_permflags($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
417 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
418 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
419 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
420 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
421
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
422 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
423 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
424 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
425
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
426 if ($this->conn->select($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
427 $permflags = $this->conn->data['PERMANENTFLAGS'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
428 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
429 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
430 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
431 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
432
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
433 if (!is_array($permflags)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
434 $permflags = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
435 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
436
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
437 return $permflags;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
438 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
439
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
440 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
441 * Returns the delimiter that is used by the IMAP server for folder separation
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
442 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
443 * @return string Delimiter string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
444 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
445 public function get_hierarchy_delimiter()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
446 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
447 return $this->delimiter;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
448 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
449
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
450 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
451 * Get namespace
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
452 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
453 * @param string $name Namespace array index: personal, other, shared, prefix
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
454 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
455 * @return array Namespace data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
456 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
457 public function get_namespace($name = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
458 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
459 $ns = $this->namespace;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
460
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
461 if ($name) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
462 // an alias for BC
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
463 if ($name == 'prefix') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
464 $name = 'prefix_in';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
465 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
466
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
467 return isset($ns[$name]) ? $ns[$name] : null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
468 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
469
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
470 unset($ns['prefix_in'], $ns['prefix_out']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
471
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
472 return $ns;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
473 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
474
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
475 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
476 * Sets delimiter and namespaces
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
477 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
478 protected function set_env()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
479 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
480 if ($this->delimiter !== null && $this->namespace !== null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
481 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
482 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
483
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
484 $config = rcube::get_instance()->config;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
485 $imap_personal = $config->get('imap_ns_personal');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
486 $imap_other = $config->get('imap_ns_other');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
487 $imap_shared = $config->get('imap_ns_shared');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
488 $imap_delimiter = $config->get('imap_delimiter');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
489
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
490 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
491 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
492 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
493
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
494 $ns = $this->conn->getNamespace();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
495
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
496 // Set namespaces (NAMESPACE supported)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
497 if (is_array($ns)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
498 $this->namespace = $ns;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
499 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
500 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
501 $this->namespace = array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
502 'personal' => NULL,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
503 'other' => NULL,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
504 'shared' => NULL,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
505 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
506 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
507
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
508 if ($imap_delimiter) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
509 $this->delimiter = $imap_delimiter;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
510 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
511 if (empty($this->delimiter)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
512 $this->delimiter = $this->namespace['personal'][0][1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
513 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
514 if (empty($this->delimiter)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
515 $this->delimiter = $this->conn->getHierarchyDelimiter();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
516 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
517 if (empty($this->delimiter)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
518 $this->delimiter = '/';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
519 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
520
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
521 // Overwrite namespaces
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
522 if ($imap_personal !== null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
523 $this->namespace['personal'] = NULL;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
524 foreach ((array)$imap_personal as $dir) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
525 $this->namespace['personal'][] = array($dir, $this->delimiter);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
526 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
527 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
528 if ($imap_other !== null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
529 $this->namespace['other'] = NULL;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
530 foreach ((array)$imap_other as $dir) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
531 if ($dir) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
532 $this->namespace['other'][] = array($dir, $this->delimiter);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
533 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
534 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
535 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
536 if ($imap_shared !== null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
537 $this->namespace['shared'] = NULL;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
538 foreach ((array)$imap_shared as $dir) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
539 if ($dir) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
540 $this->namespace['shared'][] = array($dir, $this->delimiter);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
541 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
542 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
543 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
544
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
545 // Find personal namespace prefix(es) for self::mod_folder()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
546 if (is_array($this->namespace['personal']) && !empty($this->namespace['personal'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
547 // There can be more than one namespace root,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
548 // - for prefix_out get the first one but only
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
549 // if there is only one root
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
550 // - for prefix_in get the first one but only
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
551 // if there is no non-prefixed namespace root (#5403)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
552 $roots = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
553 foreach ($this->namespace['personal'] as $ns) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
554 $roots[] = $ns[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
555 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
556
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
557 if (!in_array('', $roots)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
558 $this->namespace['prefix_in'] = $roots[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
559 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
560 if (count($roots) == 1) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
561 $this->namespace['prefix_out'] = $roots[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
562 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
563 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
564
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
565 $_SESSION['imap_namespace'] = $this->namespace;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
566 $_SESSION['imap_delimiter'] = $this->delimiter;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
567 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
568
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
569 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
570 * Returns IMAP server vendor name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
571 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
572 * @return string Vendor name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
573 * @since 1.2
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
574 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
575 public function get_vendor()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
576 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
577 if ($_SESSION['imap_vendor'] !== null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
578 return $_SESSION['imap_vendor'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
579 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
580
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
581 $config = rcube::get_instance()->config;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
582 $imap_vendor = $config->get('imap_vendor');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
583
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
584 if ($imap_vendor) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
585 return $imap_vendor;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
586 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
587
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
588 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
589 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
590 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
591
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
592 if (($ident = $this->conn->data['ID']) === null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
593 $ident = $this->conn->id(array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
594 'name' => 'Roundcube',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
595 'version' => RCUBE_VERSION,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
596 'php' => PHP_VERSION,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
597 'os' => PHP_OS,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
598 ));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
599 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
600
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
601 $vendor = (string) (!empty($ident) ? $ident['name'] : '');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
602 $ident = strtolower($vendor . ' ' . $this->conn->data['GREETING']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
603 $vendors = array('cyrus', 'dovecot', 'uw-imap', 'gmail', 'hmail');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
604
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
605 foreach ($vendors as $v) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
606 if (strpos($ident, $v) !== false) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
607 $vendor = $v;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
608 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
609 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
610 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
611
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
612 return $_SESSION['imap_vendor'] = $vendor;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
613 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
614
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
615 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
616 * Get message count for a specific folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
617 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
618 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
619 * @param string $mode Mode for count [ALL|THREADS|UNSEEN|RECENT|EXISTS]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
620 * @param boolean $force Force reading from server and update cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
621 * @param boolean $status Enables storing folder status info (max UID/count),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
622 * required for folder_status()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
623 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
624 * @return int Number of messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
625 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
626 public function count($folder='', $mode='ALL', $force=false, $status=true)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
627 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
628 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
629 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
630 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
631
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
632 return $this->countmessages($folder, $mode, $force, $status);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
633 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
634
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
635 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
636 * Protected method for getting number of messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
637 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
638 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
639 * @param string $mode Mode for count [ALL|THREADS|UNSEEN|RECENT|EXISTS]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
640 * @param boolean $force Force reading from server and update cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
641 * @param boolean $status Enables storing folder status info (max UID/count),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
642 * required for folder_status()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
643 * @param boolean $no_search Ignore current search result
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
644 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
645 * @return int Number of messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
646 * @see rcube_imap::count()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
647 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
648 protected function countmessages($folder, $mode = 'ALL', $force = false, $status = true, $no_search = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
649 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
650 $mode = strtoupper($mode);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
651
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
652 // Count search set, assume search set is always up-to-date (don't check $force flag)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
653 // @TODO: this could be handled in more reliable way, e.g. a separate method
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
654 // maybe in rcube_imap_search
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
655 if (!$no_search && $this->search_string && $folder == $this->folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
656 if ($mode == 'ALL') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
657 return $this->search_set->count_messages();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
658 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
659 else if ($mode == 'THREADS') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
660 return $this->search_set->count();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
661 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
662 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
663
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
664 // EXISTS is a special alias for ALL, it allows to get the number
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
665 // of all messages in a folder also when search is active and with
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
666 // any skip_deleted setting
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
667
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
668 if ($this->caching) {
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
669 $a_folder_cache = $this->get_cache('messagecount');
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
670
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
671 // return cached value
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
672 if (!$force && is_array($a_folder_cache[$folder]) && isset($a_folder_cache[$folder][$mode])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
673 return $a_folder_cache[$folder][$mode];
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
674 }
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
675
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
676 if (!is_array($a_folder_cache[$folder])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
677 $a_folder_cache[$folder] = array();
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
678 }
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
679 }
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
680 if ($mode == 'THREADS') {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
681 $res = $this->threads($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
682 $count = $res->count();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
683
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
684 if ($status) {
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
685 $msg_count = $res->count_messages();
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
686 $this->set_folder_stats($folder, 'cnt', $msg_count);
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
687 $this->set_folder_stats($folder, 'maxuid', $msg_count ? $this->id2uid($msg_count, $folder) : 0);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
688 }
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
689 }
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
690 // Need connection here
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
691 else if (!$this->check_connection()) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
692 return 0;
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
693 }
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
694 // RECENT count is fetched a bit different
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
695 else if ($mode == 'RECENT') {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
696 $count = $this->conn->countRecent($folder);
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
697 }
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
698 // use SEARCH for message counting
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
699 else if ($mode != 'EXISTS' && !empty($this->options['skip_deleted'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
700 $search_str = "ALL UNDELETED";
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
701 $keys = array('COUNT');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
702
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
703 if ($mode == 'UNSEEN') {
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
704 $search_str .= " UNSEEN";
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
705 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
706 else {
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
707 if ($this->messages_caching) {
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
708 $keys[] = 'ALL';
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
709 }
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
710 if ($status) {
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
711 $keys[] = 'MAX';
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
712 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
713 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
714
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
715 // @TODO: if $mode == 'ALL' we could try to use cache index here
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
716
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
717 // get message count using (E)SEARCH
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
718 // not very performant but more precise (using UNDELETED)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
719 $index = $this->conn->search($folder, $search_str, true, $keys);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
720 $count = $index->count();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
721
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
722 if ($mode == 'ALL') {
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
723 // Cache index data, will be used in index_direct()
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
724 $this->icache['undeleted_idx'] = $index;
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
725
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
726 if ($status) {
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
727 $this->set_folder_stats($folder, 'cnt', $count);
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
728 $this->set_folder_stats($folder, 'maxuid', $index->max());
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
729 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
730 }
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
731 }
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
732 else {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
733 if ($mode == 'UNSEEN') {
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
734 $count = $this->conn->countUnseen($folder);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
735 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
736 else {
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
737 $count = $this->conn->countMessages($folder);
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
738 if ($status && $mode == 'ALL') {
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
739 $this->set_folder_stats($folder, 'cnt', $count);
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
740 $this->set_folder_stats($folder, 'maxuid', $count ? $this->id2uid($count, $folder) : 0);
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
741 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
742 }
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
743 }
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
744
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
745 if ($this->caching) {
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
746 $a_folder_cache[$folder][$mode] = (int)$count;
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
747
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
748 // write back to cache
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
749 $this->update_cache('messagecount', $a_folder_cache);
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
750 }
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
751
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
752 return (int)$count;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
753 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
754
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
755 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
756 * Public method for listing message flags
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
757 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
758 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
759 * @param array $uids Message UIDs
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
760 * @param int $mod_seq Optional MODSEQ value (of last flag update)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
761 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
762 * @return array Indexed array with message flags
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
763 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
764 public function list_flags($folder, $uids, $mod_seq = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
765 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
766 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
767 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
768 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
769
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
770 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
771 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
772 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
773
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
774 // @TODO: when cache was synchronized in this request
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
775 // we might already have asked for flag updates, use it.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
776
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
777 $flags = $this->conn->fetch($folder, $uids, true, array('FLAGS'), $mod_seq);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
778 $result = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
779
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
780 if (!empty($flags)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
781 foreach ($flags as $message) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
782 $result[$message->uid] = $message->flags;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
783 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
784 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
785
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
786 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
787 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
788
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
789 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
790 * Public method for listing headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
791 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
792 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
793 * @param int $page Current page to list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
794 * @param string $sort_field Header field to sort by
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
795 * @param string $sort_order Sort order [ASC|DESC]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
796 * @param int $slice Number of slice items to extract from result array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
797 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
798 * @return array Indexed array with message header objects
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
799 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
800 public function list_messages($folder='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $slice=0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
801 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
802 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
803 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
804 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
805
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
806 return $this->_list_messages($folder, $page, $sort_field, $sort_order, $slice);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
807 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
808
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
809 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
810 * protected method for listing message headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
811 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
812 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
813 * @param int $page Current page to list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
814 * @param string $sort_field Header field to sort by
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
815 * @param string $sort_order Sort order [ASC|DESC]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
816 * @param int $slice Number of slice items to extract from result array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
817 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
818 * @return array Indexed array with message header objects
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
819 * @see rcube_imap::list_messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
820 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
821 protected function _list_messages($folder='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $slice=0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
822 {
5
3a5f959af5ae debugging aids, all commented out
Charlie Root
parents: 0
diff changeset
823 #rcube::write_log('mail',"_lm |$folder| $sort_field ".$this->threading);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
824 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
825 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
826 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
827
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
828 $this->set_sort_order($sort_field, $sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
829 $page = $page ? $page : $this->list_page;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
830
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
831 // use saved message set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
832 if ($this->search_string) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
833 return $this->list_search_messages($folder, $page, $slice);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
834 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
835
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
836 if ($this->threading) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
837 return $this->list_thread_messages($folder, $page, $slice);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
838 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
839
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
840 // get UIDs of all messages in the folder, sorted
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
841 $index = $this->index($folder, $this->sort_field, $this->sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
842
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
843 if ($index->is_empty()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
844 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
845 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
846
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
847 $from = ($page-1) * $this->page_size;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
848 $to = $from + $this->page_size;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
849
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
850 $index->slice($from, $to - $from);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
851
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
852 if ($slice) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
853 $index->slice(-$slice, $slice);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
854 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
855
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
856 // fetch reqested messages headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
857 $a_index = $index->get();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
858 $a_msg_headers = $this->fetch_headers($folder, $a_index);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
859
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
860 return array_values($a_msg_headers);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
861 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
862
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
863 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
864 * protected method for listing message headers using threads
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
865 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
866 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
867 * @param int $page Current page to list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
868 * @param int $slice Number of slice items to extract from result array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
869 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
870 * @return array Indexed array with message header objects
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
871 * @see rcube_imap::list_messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
872 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
873 protected function list_thread_messages($folder, $page, $slice=0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
874 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
875 // get all threads (not sorted)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
876 if ($mcache = $this->get_mcache_engine()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
877 $threads = $mcache->get_thread($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
878 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
879 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
880 $threads = $this->threads($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
881 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
882
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
883 return $this->fetch_thread_headers($folder, $threads, $page, $slice);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
884 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
885
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
886 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
887 * Method for fetching threads data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
888 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
889 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
890 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
891 * @return rcube_imap_thread Thread data object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
892 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
893 function threads($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
894 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
895 if ($mcache = $this->get_mcache_engine()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
896 // don't store in self's internal cache, cache has it's own internal cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
897 return $mcache->get_thread($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
898 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
899
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
900 if (!empty($this->icache['threads'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
901 if ($this->icache['threads']->get_parameters('MAILBOX') == $folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
902 return $this->icache['threads'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
903 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
904 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
905
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
906 // get all threads
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
907 $result = $this->threads_direct($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
908
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
909 // add to internal (fast) cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
910 return $this->icache['threads'] = $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
911 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
912
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
913 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
914 * Method for direct fetching of threads data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
915 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
916 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
917 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
918 * @return rcube_imap_thread Thread data object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
919 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
920 function threads_direct($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
921 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
922 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
923 return new rcube_result_thread();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
924 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
925
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
926 // get all threads
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
927 return $this->conn->thread($folder, $this->threading,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
928 $this->options['skip_deleted'] ? 'UNDELETED' : '', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
929 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
930
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
931 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
932 * protected method for fetching threaded messages headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
933 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
934 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
935 * @param rcube_result_thread $threads Threads data object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
936 * @param int $page List page number
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
937 * @param int $slice Number of threads to slice
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
938 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
939 * @return array Messages headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
940 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
941 protected function fetch_thread_headers($folder, $threads, $page, $slice=0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
942 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
943 // Sort thread structure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
944 $this->sort_threads($threads);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
945
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
946 $from = ($page-1) * $this->page_size;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
947 $to = $from + $this->page_size;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
948
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
949 $threads->slice($from, $to - $from);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
950
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
951 if ($slice) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
952 $threads->slice(-$slice, $slice);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
953 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
954
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
955 // Get UIDs of all messages in all threads
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
956 $a_index = $threads->get();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
957
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
958 // fetch reqested headers from server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
959 $a_msg_headers = $this->fetch_headers($folder, $a_index);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
960
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
961 unset($a_index);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
962
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
963 // Set depth, has_children and unread_children fields in headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
964 $this->set_thread_flags($a_msg_headers, $threads);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
965
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
966 return array_values($a_msg_headers);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
967 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
968
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
969 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
970 * protected method for setting threaded messages flags:
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
971 * depth, has_children, unread_children, flagged_children
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
972 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
973 * @param array $headers Reference to headers array indexed by message UID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
974 * @param rcube_result_thread $threads Threads data object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
975 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
976 * @return array Message headers array indexed by message UID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
977 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
978 protected function set_thread_flags(&$headers, $threads)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
979 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
980 $parents = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
981
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
982 list ($msg_depth, $msg_children) = $threads->get_thread_data();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
983
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
984 foreach ($headers as $uid => $header) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
985 $depth = $msg_depth[$uid];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
986 $parents = array_slice($parents, 0, $depth);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
987
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
988 if (!empty($parents)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
989 $headers[$uid]->parent_uid = end($parents);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
990 if (empty($header->flags['SEEN'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
991 $headers[$parents[0]]->unread_children++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
992 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
993 if (!empty($header->flags['FLAGGED'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
994 $headers[$parents[0]]->flagged_children++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
995 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
996 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
997 array_push($parents, $uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
998
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
999 $headers[$uid]->depth = $depth;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1000 $headers[$uid]->has_children = $msg_children[$uid];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1001 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1002 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1003
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1004 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1005 * protected method for listing a set of message headers (search results)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1006 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1007 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1008 * @param int $page Current page to list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1009 * @param int $slice Number of slice items to extract from result array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1010 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1011 * @return array Indexed array with message header objects
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1012 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1013 protected function list_search_messages($folder, $page, $slice=0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1014 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1015 if (!strlen($folder) || empty($this->search_set) || $this->search_set->is_empty()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1016 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1017 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1018
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1019 // gather messages from a multi-folder search
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1020 if ($this->search_set->multi) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1021 $page_size = $this->page_size;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1022 $sort_field = $this->sort_field;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1023 $search_set = $this->search_set;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1024
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1025 // prepare paging
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1026 $cnt = $search_set->count();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1027 $from = ($page-1) * $page_size;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1028 $to = $from + $page_size;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1029 $slice_length = min($page_size, $cnt - $from);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1030
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1031 // fetch resultset headers, sort and slice them
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1032 if (!empty($sort_field) && $search_set->get_parameters('SORT') != $sort_field) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1033 $this->sort_field = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1034 $this->page_size = 1000; // fetch up to 1000 matching messages per folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1035 $this->threading = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1036
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1037 $a_msg_headers = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1038 foreach ($search_set->sets as $resultset) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1039 if (!$resultset->is_empty()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1040 $this->search_set = $resultset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1041 $this->search_threads = $resultset instanceof rcube_result_thread;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1042
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1043 $a_headers = $this->list_search_messages($resultset->get_parameters('MAILBOX'), 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1044 $a_msg_headers = array_merge($a_msg_headers, $a_headers);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1045 unset($a_headers);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1046 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1047 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1048
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1049 // sort headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1050 if (!empty($a_msg_headers)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1051 $a_msg_headers = rcube_imap_generic::sortHeaders($a_msg_headers, $sort_field, $this->sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1052 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1053
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1054 // store (sorted) message index
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1055 $search_set->set_message_index($a_msg_headers, $sort_field, $this->sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1056
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1057 // only return the requested part of the set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1058 $a_msg_headers = array_slice(array_values($a_msg_headers), $from, $slice_length);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1059 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1060 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1061 if ($this->sort_order != $search_set->get_parameters('ORDER')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1062 $search_set->revert();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1063 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1064
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1065 // slice resultset first...
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1066 $fetch = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1067 foreach (array_slice($search_set->get(), $from, $slice_length) as $msg_id) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1068 list($uid, $folder) = explode('-', $msg_id, 2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1069 $fetch[$folder][] = $uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1070 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1071
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1072 // ... and fetch the requested set of headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1073 $a_msg_headers = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1074 foreach ($fetch as $folder => $a_index) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1075 $a_msg_headers = array_merge($a_msg_headers, array_values($this->fetch_headers($folder, $a_index)));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1076 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1077 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1078
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1079 if ($slice) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1080 $a_msg_headers = array_slice($a_msg_headers, -$slice, $slice);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1081 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1082
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1083 // restore members
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1084 $this->sort_field = $sort_field;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1085 $this->page_size = $page_size;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1086 $this->search_set = $search_set;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1087
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1088 return $a_msg_headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1089 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1090
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1091 // use saved messages from searching
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1092 if ($this->threading) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1093 return $this->list_search_thread_messages($folder, $page, $slice);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1094 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1095
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1096 // search set is threaded, we need a new one
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1097 if ($this->search_threads) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1098 $this->search('', $this->search_string, $this->search_charset, $this->sort_field);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1099 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1100
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1101 $index = clone $this->search_set;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1102 $from = ($page-1) * $this->page_size;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1103 $to = $from + $this->page_size;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1104
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1105 // return empty array if no messages found
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1106 if ($index->is_empty()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1107 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1108 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1109
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1110 // quickest method (default sorting)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1111 if (!$this->search_sort_field && !$this->sort_field) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1112 $got_index = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1113 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1114 // sorted messages, so we can first slice array and then fetch only wanted headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1115 else if ($this->search_sorted) { // SORT searching result
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1116 $got_index = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1117 // reset search set if sorting field has been changed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1118 if ($this->sort_field && $this->search_sort_field != $this->sort_field) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1119 $this->search('', $this->search_string, $this->search_charset, $this->sort_field);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1120
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1121 $index = clone $this->search_set;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1122
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1123 // return empty array if no messages found
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1124 if ($index->is_empty()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1125 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1126 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1127 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1128 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1129
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1130 if ($got_index) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1131 if ($this->sort_order != $index->get_parameters('ORDER')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1132 $index->revert();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1133 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1134
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1135 // get messages uids for one page
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1136 $index->slice($from, $to-$from);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1137
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1138 if ($slice) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1139 $index->slice(-$slice, $slice);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1140 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1141
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1142 // fetch headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1143 $a_index = $index->get();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1144 $a_msg_headers = $this->fetch_headers($folder, $a_index);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1145
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1146 return array_values($a_msg_headers);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1147 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1148
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1149 // SEARCH result, need sorting
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1150 $cnt = $index->count();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1151
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1152 // 300: experimantal value for best result
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1153 if (($cnt > 300 && $cnt > $this->page_size) || !$this->sort_field) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1154 // use memory less expensive (and quick) method for big result set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1155 $index = clone $this->index('', $this->sort_field, $this->sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1156 // get messages uids for one page...
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1157 $index->slice($from, min($cnt-$from, $this->page_size));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1158
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1159 if ($slice) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1160 $index->slice(-$slice, $slice);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1161 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1162
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1163 // ...and fetch headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1164 $a_index = $index->get();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1165 $a_msg_headers = $this->fetch_headers($folder, $a_index);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1166
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1167 return array_values($a_msg_headers);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1168 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1169 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1170 // for small result set we can fetch all messages headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1171 $a_index = $index->get();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1172 $a_msg_headers = $this->fetch_headers($folder, $a_index, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1173
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1174 // return empty array if no messages found
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1175 if (!is_array($a_msg_headers) || empty($a_msg_headers)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1176 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1177 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1178
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1179 // if not already sorted
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1180 $a_msg_headers = rcube_imap_generic::sortHeaders(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1181 $a_msg_headers, $this->sort_field, $this->sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1182
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1183 // only return the requested part of the set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1184 $slice_length = min($this->page_size, $cnt - ($to > $cnt ? $from : $to));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1185 $a_msg_headers = array_slice(array_values($a_msg_headers), $from, $slice_length);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1186
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1187 if ($slice) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1188 $a_msg_headers = array_slice($a_msg_headers, -$slice, $slice);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1189 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1190
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1191 return $a_msg_headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1192 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1193 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1194
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1195 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1196 * protected method for listing a set of threaded message headers (search results)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1197 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1198 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1199 * @param int $page Current page to list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1200 * @param int $slice Number of slice items to extract from result array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1201 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1202 * @return array Indexed array with message header objects
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1203 * @see rcube_imap::list_search_messages()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1204 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1205 protected function list_search_thread_messages($folder, $page, $slice=0)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1206 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1207 // update search_set if previous data was fetched with disabled threading
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1208 if (!$this->search_threads) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1209 if ($this->search_set->is_empty()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1210 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1211 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1212 $this->search('', $this->search_string, $this->search_charset, $this->sort_field);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1213 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1214
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1215 return $this->fetch_thread_headers($folder, clone $this->search_set, $page, $slice);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1216 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1217
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1218 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1219 * Fetches messages headers (by UID)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1220 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1221 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1222 * @param array $msgs Message UIDs
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1223 * @param bool $sort Enables result sorting by $msgs
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1224 * @param bool $force Disables cache use
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1225 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1226 * @return array Messages headers indexed by UID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1227 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1228 function fetch_headers($folder, $msgs, $sort = true, $force = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1229 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1230 if (empty($msgs)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1231 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1232 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1233
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1234 if (!$force && ($mcache = $this->get_mcache_engine())) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1235 $headers = $mcache->get_messages($folder, $msgs);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1236 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1237 else if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1238 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1239 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1240 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1241 // fetch reqested headers from server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1242 $headers = $this->conn->fetchHeaders(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1243 $folder, $msgs, true, false, $this->get_fetch_headers());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1244 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1245
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1246 if (empty($headers)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1247 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1248 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1249
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1250 foreach ($headers as $h) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1251 $h->folder = $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1252 $a_msg_headers[$h->uid] = $h;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1253 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1254
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1255 if ($sort) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1256 // use this class for message sorting
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1257 $sorter = new rcube_message_header_sorter();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1258 $sorter->set_index($msgs);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1259 $sorter->sort_headers($a_msg_headers);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1260 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1261
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1262 return $a_msg_headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1263 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1264
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1265 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1266 * Returns current status of a folder (compared to the last time use)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1267 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1268 * We compare the maximum UID to determine the number of
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1269 * new messages because the RECENT flag is not reliable.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1270 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1271 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1272 * @param array $diff Difference data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1273 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1274 * @return int Folder status
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1275 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1276 public function folder_status($folder = null, &$diff = array())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1277 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1278 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1279 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1280 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1281 $old = $this->get_folder_stats($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1282
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1283 // refresh message count -> will update
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1284 $this->countmessages($folder, 'ALL', true, true, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1285
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1286 $result = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1287
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1288 if (empty($old)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1289 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1290 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1291
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1292 $new = $this->get_folder_stats($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1293
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1294 // got new messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1295 if ($new['maxuid'] > $old['maxuid']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1296 $result += 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1297 // get new message UIDs range, that can be used for example
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1298 // to get the data of these messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1299 $diff['new'] = ($old['maxuid'] + 1 < $new['maxuid'] ? ($old['maxuid']+1).':' : '') . $new['maxuid'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1300 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1301 // some messages has been deleted
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1302 if ($new['cnt'] < $old['cnt']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1303 $result += 2;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1304 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1305
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1306 // @TODO: optional checking for messages flags changes (?)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1307 // @TODO: UIDVALIDITY checking
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1308
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1309 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1310 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1311
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1312 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1313 * Stores folder statistic data in session
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1314 * @TODO: move to separate DB table (cache?)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1315 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1316 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1317 * @param string $name Data name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1318 * @param mixed $data Data value
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1319 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1320 protected function set_folder_stats($folder, $name, $data)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1321 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1322 $_SESSION['folders'][$folder][$name] = $data;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1323 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1324
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1325 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1326 * Gets folder statistic data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1327 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1328 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1329 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1330 * @return array Stats data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1331 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1332 protected function get_folder_stats($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1333 {
24
e53add5ddac5 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 22
diff changeset
1334 if (!empty($_SESSION['folders'][$folder])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1335 return (array) $_SESSION['folders'][$folder];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1336 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1337
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1338 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1339 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1340
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1341 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1342 * Return sorted list of message UIDs
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1343 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1344 * @param string $folder Folder to get index from
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1345 * @param string $sort_field Sort column
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1346 * @param string $sort_order Sort order [ASC, DESC]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1347 * @param bool $no_threads Get not threaded index
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1348 * @param bool $no_search Get index not limited to search result (optionally)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1349 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1350 * @return rcube_result_index|rcube_result_thread List of messages (UIDs)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1351 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1352 public function index($folder = '', $sort_field = NULL, $sort_order = NULL,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1353 $no_threads = false, $no_search = false
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1354 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1355 if (!$no_threads && $this->threading) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1356 return $this->thread_index($folder, $sort_field, $sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1357 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1358
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1359 $this->set_sort_order($sort_field, $sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1360
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1361 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1362 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1363 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1364
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1365 // we have a saved search result, get index from there
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1366 if ($this->search_string) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1367 if ($this->search_set->is_empty()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1368 return new rcube_result_index($folder, '* SORT');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1369 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1370
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1371 if ($this->search_set instanceof rcube_result_multifolder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1372 $index = $this->search_set;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1373 $index->folder = $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1374 // TODO: handle changed sorting
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1375 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1376 // search result is an index with the same sorting?
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1377 else if (($this->search_set instanceof rcube_result_index)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1378 && ((!$this->sort_field && !$this->search_sorted) ||
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1379 ($this->search_sorted && $this->search_sort_field == $this->sort_field))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1380 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1381 $index = $this->search_set;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1382 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1383 // $no_search is enabled when we are not interested in
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1384 // fetching index for search result, e.g. to sort
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1385 // threaded search result we can use full mailbox index.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1386 // This makes possible to use index from cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1387 else if (!$no_search) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1388 if (!$this->sort_field) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1389 // No sorting needed, just build index from the search result
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1390 // @TODO: do we need to sort by UID here?
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1391 $search = $this->search_set->get_compressed();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1392 $index = new rcube_result_index($folder, '* ESEARCH ALL ' . $search);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1393 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1394 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1395 $index = $this->index_direct($folder, $this->sort_field, $this->sort_order, $this->search_set);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1396 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1397 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1398
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1399 if (isset($index)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1400 if ($this->sort_order != $index->get_parameters('ORDER')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1401 $index->revert();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1402 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1403
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1404 return $index;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1405 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1406 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1407
5
3a5f959af5ae debugging aids, all commented out
Charlie Root
parents: 0
diff changeset
1408 #rcube::write_log('mail','cache? '.$this->get_mcache_engine());
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1409 // check local cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1410 if ($mcache = $this->get_mcache_engine()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1411 return $mcache->get_index($folder, $this->sort_field, $this->sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1412 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1413
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1414 // fetch from IMAP server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1415 return $this->index_direct($folder, $this->sort_field, $this->sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1416 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1417
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1418 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1419 * Return sorted list of message UIDs ignoring current search settings.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1420 * Doesn't uses cache by default.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1421 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1422 * @param string $folder Folder to get index from
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1423 * @param string $sort_field Sort column
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1424 * @param string $sort_order Sort order [ASC, DESC]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1425 * @param rcube_result_* $search Optional messages set to limit the result
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1426 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1427 * @return rcube_result_index Sorted list of message UIDs
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1428 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1429 public function index_direct($folder, $sort_field = null, $sort_order = null, $search = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1430 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1431 if (!empty($search)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1432 $search = $search->get_compressed();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1433 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1434
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1435 // use message index sort as default sorting
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1436 if (!$sort_field) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1437 // use search result from count() if possible
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1438 if (empty($search) && $this->options['skip_deleted']
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1439 && !empty($this->icache['undeleted_idx'])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1440 && $this->icache['undeleted_idx']->get_parameters('ALL') !== null
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1441 && $this->icache['undeleted_idx']->get_parameters('MAILBOX') == $folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1442 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1443 $index = $this->icache['undeleted_idx'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1444 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1445 else if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1446 return new rcube_result_index();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1447 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1448 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1449 $query = $this->options['skip_deleted'] ? 'UNDELETED' : '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1450 if ($search) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1451 $query = trim($query . ' UID ' . $search);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1452 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1453
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1454 $index = $this->conn->search($folder, $query, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1455 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1456 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1457 else if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1458 return new rcube_result_index();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1459 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1460 // fetch complete message index
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1461 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1462 if ($this->get_capability('SORT')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1463 $query = $this->options['skip_deleted'] ? 'UNDELETED' : '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1464 if ($search) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1465 $query = trim($query . ' UID ' . $search);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1466 }
5
3a5f959af5ae debugging aids, all commented out
Charlie Root
parents: 0
diff changeset
1467 #rcube::write_log('mail',"abouttosort $sort_field $query");
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1468 $index = $this->conn->sort($folder, $sort_field, $query, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1469 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1470
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1471 if (empty($index) || $index->is_error()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1472 $index = $this->conn->index($folder, $search ? $search : "1:*",
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1473 $sort_field, $this->options['skip_deleted'],
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1474 $search ? true : false, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1475 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1476 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1477
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1478 if ($sort_order != $index->get_parameters('ORDER')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1479 $index->revert();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1480 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1481
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1482 return $index;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1483 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1484
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1485 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1486 * Return index of threaded message UIDs
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1487 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1488 * @param string $folder Folder to get index from
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1489 * @param string $sort_field Sort column
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1490 * @param string $sort_order Sort order [ASC, DESC]
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1491 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1492 * @return rcube_result_thread Message UIDs
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1493 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1494 public function thread_index($folder='', $sort_field=NULL, $sort_order=NULL)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1495 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1496 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1497 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1498 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1499
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1500 // we have a saved search result, get index from there
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1501 if ($this->search_string && $this->search_threads && $folder == $this->folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1502 $threads = $this->search_set;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1503 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1504 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1505 // get all threads (default sort order)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1506 $threads = $this->threads($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1507 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1508
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1509 $this->set_sort_order($sort_field, $sort_order);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1510 $this->sort_threads($threads);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1511
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1512 return $threads;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1513 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1514
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1515 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1516 * Sort threaded result, using THREAD=REFS method if available.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1517 * If not, use any method and re-sort the result in THREAD=REFS way.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1518 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1519 * @param rcube_result_thread $threads Threads result set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1520 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1521 protected function sort_threads($threads)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1522 {
5
3a5f959af5ae debugging aids, all commented out
Charlie Root
parents: 0
diff changeset
1523 #rcube::write_log('mail','sort_threads '.count($threads)." ".$this->sort_field);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1524 if ($threads->is_empty()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1525 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1526 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1527 // THREAD=ORDEREDSUBJECT: sorting by sent date of root message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1528 // THREAD=REFERENCES: sorting by sent date of root message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1529 // THREAD=REFS: sorting by the most recent date in each thread
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1530
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1531 if ($this->threading != 'REFS' || ($this->sort_field && $this->sort_field != 'date')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1532 $sortby = $this->sort_field ? $this->sort_field : 'date';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1533 $index = $this->index($this->folder, $sortby, $this->sort_order, true, true);
5
3a5f959af5ae debugging aids, all commented out
Charlie Root
parents: 0
diff changeset
1534 #rcube::write_log('mail',"sort_threads $sortby".print_r($index,true));
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1535 if (!$index->is_empty()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1536 $threads->sort($index);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1537 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1538 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1539 else if ($this->sort_order != $threads->get_parameters('ORDER')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1540 $threads->revert();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1541 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1542 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1543
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1544 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1545 * Invoke search request to IMAP server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1546 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1547 * @param string $folder Folder name to search in
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1548 * @param string $search Search criteria
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1549 * @param string $charset Search charset
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1550 * @param string $sort_field Header field to sort by
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1551 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1552 * @return rcube_result_index Search result object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1553 * @todo: Search criteria should be provided in non-IMAP format, eg. array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1554 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1555 public function search($folder = '', $search = 'ALL', $charset = null, $sort_field = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1556 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1557 if (!$search) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1558 $search = 'ALL';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1559 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1560
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1561 if ((is_array($folder) && empty($folder)) || (!is_array($folder) && !strlen($folder))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1562 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1563 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1564
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1565 $plugin = $this->plugins->exec_hook('imap_search_before', array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1566 'folder' => $folder,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1567 'search' => $search,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1568 'charset' => $charset,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1569 'sort_field' => $sort_field,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1570 'threading' => $this->threading,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1571 ));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1572
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1573 $folder = $plugin['folder'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1574 $search = $plugin['search'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1575 $charset = $plugin['charset'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1576 $sort_field = $plugin['sort_field'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1577 $results = $plugin['result'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1578
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1579 // multi-folder search
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1580 if (!$results && is_array($folder) && count($folder) > 1 && $search != 'ALL') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1581 // connect IMAP to have all the required classes and settings loaded
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1582 $this->check_connection();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1583
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1584 // disable threading
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1585 $this->threading = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1586
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1587 $searcher = new rcube_imap_search($this->options, $this->conn);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1588
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1589 // set limit to not exceed the client's request timeout
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1590 $searcher->set_timelimit(60);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1591
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1592 // continue existing incomplete search
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1593 if (!empty($this->search_set) && $this->search_set->incomplete && $search == $this->search_string) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1594 $searcher->set_results($this->search_set);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1595 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1596
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1597 // execute the search
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1598 $results = $searcher->exec(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1599 $folder,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1600 $search,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1601 $charset ? $charset : $this->default_charset,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1602 $sort_field && $this->get_capability('SORT') ? $sort_field : null,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1603 $this->threading
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1604 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1605 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1606 else if (!$results) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1607 $folder = is_array($folder) ? $folder[0] : $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1608 $search = is_array($search) ? $search[$folder] : $search;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1609 $results = $this->search_index($folder, $search, $charset, $sort_field);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1610 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1611
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1612 $sorted = $this->threading || $this->search_sorted || $plugin['search_sorted'] ? true : false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1613
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1614 $this->set_search_set(array($search, $results, $charset, $sort_field, $sorted));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1615
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1616 return $results;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1617 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1618
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1619 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1620 * Direct (real and simple) SEARCH request (without result sorting and caching).
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1621 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1622 * @param string $mailbox Mailbox name to search in
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1623 * @param string $str Search string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1624 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1625 * @return rcube_result_index Search result (UIDs)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1626 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1627 public function search_once($folder = null, $str = 'ALL')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1628 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1629 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1630 return new rcube_result_index();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1631 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1632
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1633 if (!$str) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1634 $str = 'ALL';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1635 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1636
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1637 // multi-folder search
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1638 if (is_array($folder) && count($folder) > 1) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1639 $searcher = new rcube_imap_search($this->options, $this->conn);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1640 $index = $searcher->exec($folder, $str, $this->default_charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1641 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1642 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1643 $folder = is_array($folder) ? $folder[0] : $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1644 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1645 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1646 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1647 $index = $this->conn->search($folder, $str, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1648 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1649
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1650 return $index;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1651 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1652
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1653 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1654 * protected search method
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1655 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1656 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1657 * @param string $criteria Search criteria
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1658 * @param string $charset Charset
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1659 * @param string $sort_field Sorting field
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1660 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1661 * @return rcube_result_index|rcube_result_thread Search results (UIDs)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1662 * @see rcube_imap::search()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1663 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1664 protected function search_index($folder, $criteria='ALL', $charset=NULL, $sort_field=NULL)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1665 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1666 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1667 if ($this->threading) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1668 return new rcube_result_thread();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1669 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1670 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1671 return new rcube_result_index();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1672 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1673 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1674
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1675 if ($this->options['skip_deleted'] && !preg_match('/UNDELETED/', $criteria)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1676 $criteria = 'UNDELETED '.$criteria;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1677 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1678
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1679 // unset CHARSET if criteria string is ASCII, this way
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1680 // SEARCH won't be re-sent after "unsupported charset" response
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1681 if ($charset && $charset != 'US-ASCII' && is_ascii($criteria)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1682 $charset = 'US-ASCII';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1683 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1684
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1685 if ($this->threading) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1686 $threads = $this->conn->thread($folder, $this->threading, $criteria, true, $charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1687
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1688 // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1689 // but I've seen that Courier doesn't support UTF-8)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1690 if ($threads->is_error() && $charset && $charset != 'US-ASCII') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1691 $threads = $this->conn->thread($folder, $this->threading,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1692 self::convert_criteria($criteria, $charset), true, 'US-ASCII');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1693 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1694
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1695 return $threads;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1696 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1697
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1698 if ($sort_field && $this->get_capability('SORT')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1699 $charset = $charset ? $charset : $this->default_charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1700 $messages = $this->conn->sort($folder, $sort_field, $criteria, true, $charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1701
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1702 // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1703 // but I've seen Courier with disabled UTF-8 support)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1704 if ($messages->is_error() && $charset && $charset != 'US-ASCII') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1705 $messages = $this->conn->sort($folder, $sort_field,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1706 self::convert_criteria($criteria, $charset), true, 'US-ASCII');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1707 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1708
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1709 if (!$messages->is_error()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1710 $this->search_sorted = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1711 return $messages;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1712 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1713 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1714
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1715 $messages = $this->conn->search($folder,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1716 ($charset && $charset != 'US-ASCII' ? "CHARSET $charset " : '') . $criteria, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1717
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1718 // Error, try with US-ASCII (some servers may support only US-ASCII)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1719 if ($messages->is_error() && $charset && $charset != 'US-ASCII') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1720 $messages = $this->conn->search($folder,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1721 self::convert_criteria($criteria, $charset), true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1722 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1723
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1724 $this->search_sorted = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1725
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1726 return $messages;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1727 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1728
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1729 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1730 * Converts charset of search criteria string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1731 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1732 * @param string $str Search string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1733 * @param string $charset Original charset
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1734 * @param string $dest_charset Destination charset (default US-ASCII)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1735 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1736 * @return string Search string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1737 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1738 public static function convert_criteria($str, $charset, $dest_charset='US-ASCII')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1739 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1740 // convert strings to US_ASCII
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1741 if (preg_match_all('/\{([0-9]+)\}\r\n/', $str, $matches, PREG_OFFSET_CAPTURE)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1742 $last = 0; $res = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1743 foreach ($matches[1] as $m) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1744 $string_offset = $m[1] + strlen($m[0]) + 4; // {}\r\n
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1745 $string = substr($str, $string_offset - 1, $m[0]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1746 $string = rcube_charset::convert($string, $charset, $dest_charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1747
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1748 if ($string === false || !strlen($string)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1749 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1750 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1751
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1752 $res .= substr($str, $last, $m[1] - $last - 1) . rcube_imap_generic::escape($string);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1753 $last = $m[0] + $string_offset - 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1754 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1755
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1756 if ($last < strlen($str)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1757 $res .= substr($str, $last, strlen($str)-$last);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1758 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1759 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1760 // strings for conversion not found
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1761 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1762 $res = $str;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1763 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1764
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1765 return $res;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1766 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1767
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1768 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1769 * Refresh saved search set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1770 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1771 * @return array Current search set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1772 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1773 public function refresh_search()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1774 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1775 if (!empty($this->search_string)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1776 $this->search(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1777 is_object($this->search_set) ? $this->search_set->get_parameters('MAILBOX') : '',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1778 $this->search_string,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1779 $this->search_charset,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1780 $this->search_sort_field
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1781 );
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1782 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1783
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1784 return $this->get_search_set();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1785 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1786
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1787 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1788 * Flag certain result subsets as 'incomplete'.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1789 * For subsequent refresh_search() calls to only refresh the updated parts.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1790 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1791 protected function set_search_dirty($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1792 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1793 if ($this->search_set && is_a($this->search_set, 'rcube_result_multifolder')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1794 if ($subset = $this->search_set->get_set($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1795 $subset->incomplete = $this->search_set->incomplete = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1796 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1797 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1798 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1799
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1800 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1801 * Return message headers object of a specific message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1802 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1803 * @param int $id Message UID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1804 * @param string $folder Folder to read from
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1805 * @param bool $force True to skip cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1806 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1807 * @return rcube_message_header Message headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1808 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1809 public function get_message_headers($uid, $folder = null, $force = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1810 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1811 // decode combined UID-folder identifier
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1812 if (preg_match('/^\d+-.+/', $uid)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1813 list($uid, $folder) = explode('-', $uid, 2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1814 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1815
21
73124dd49283 More cleaning up php8 Warnings/deprecations,
Charlie Root
parents: 19
diff changeset
1816 if (empty($folder)) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1817 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1818 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1819
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1820 // get cached headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1821 if (!$force && $uid && ($mcache = $this->get_mcache_engine())) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1822 $headers = $mcache->get_message($folder, $uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1823 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1824 else if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1825 $headers = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1826 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1827 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1828 $headers = $this->conn->fetchHeader(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1829 $folder, $uid, true, true, $this->get_fetch_headers());
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1830
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1831 if (is_object($headers))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1832 $headers->folder = $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1833 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1834
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1835 return $headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1836 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1837
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1838 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1839 * Fetch message headers and body structure from the IMAP server and build
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1840 * an object structure.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1841 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1842 * @param int $uid Message UID to fetch
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1843 * @param string $folder Folder to read from
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1844 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1845 * @return object rcube_message_header Message data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1846 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1847 public function get_message($uid, $folder = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1848 {
21
73124dd49283 More cleaning up php8 Warnings/deprecations,
Charlie Root
parents: 19
diff changeset
1849 if (!empty($folder)) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1850 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1851 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1852
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1853 // decode combined UID-folder identifier
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1854 if (preg_match('/^\d+-.+/', $uid)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1855 list($uid, $folder) = explode('-', $uid, 2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1856 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1857
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1858 // Check internal cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1859 if (!empty($this->icache['message'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1860 if (($headers = $this->icache['message']) && $headers->uid == $uid) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1861 return $headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1862 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1863 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1864
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1865 $headers = $this->get_message_headers($uid, $folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1866
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1867 // message doesn't exist?
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1868 if (empty($headers)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1869 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1870 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1871
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1872 // structure might be cached
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1873 if (!empty($headers->structure)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1874 return $headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1875 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1876
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1877 $this->msg_uid = $uid;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1878
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1879 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1880 return $headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1881 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1882
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1883 if (empty($headers->bodystructure)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1884 $headers->bodystructure = $this->conn->getStructure($folder, $uid, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1885 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1886
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1887 $structure = $headers->bodystructure;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1888
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1889 if (empty($structure)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1890 return $headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1891 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1892
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1893 // set message charset from message headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1894 if ($headers->charset) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1895 $this->struct_charset = $headers->charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1896 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1897 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1898 $this->struct_charset = $this->structure_charset($structure);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1899 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1900
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1901 $headers->ctype = @strtolower($headers->ctype);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1902
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1903 // Here we can recognize malformed BODYSTRUCTURE and
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1904 // 1. [@TODO] parse the message in other way to create our own message structure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1905 // 2. or just show the raw message body.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1906 // Example of structure for malformed MIME message:
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1907 // ("text" "plain" NIL NIL NIL "7bit" 2154 70 NIL NIL NIL)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1908 if ($headers->ctype && !is_array($structure[0]) && $headers->ctype != 'text/plain'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1909 && strtolower($structure[0].'/'.$structure[1]) == 'text/plain'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1910 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1911 // A special known case "Content-type: text" (#1488968)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1912 if ($headers->ctype == 'text') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1913 $structure[1] = 'plain';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1914 $headers->ctype = 'text/plain';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1915 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1916 // we can handle single-part messages, by simple fix in structure (#1486898)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1917 else if (preg_match('/^(text|application)\/(.*)/', $headers->ctype, $m)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1918 $structure[0] = $m[1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1919 $structure[1] = $m[2];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1920 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1921 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1922 // Try to parse the message using rcube_mime_decode.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1923 // We need a better solution, it parses message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1924 // in memory, which wouldn't work for very big messages,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1925 // (it uses up to 10x more memory than the message size)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1926 // it's also buggy and not actively developed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1927 if ($headers->size && rcube_utils::mem_check($headers->size * 10)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1928 $raw_msg = $this->get_raw_body($uid);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1929 $struct = rcube_mime::parse_message($raw_msg);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1930 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1931 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1932 return $headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1933 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1934 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1935 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1936
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1937 if (empty($struct)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1938 $struct = $this->structure_part($structure, 0, '', $headers);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1939 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1940
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1941 // some workarounds on simple messages...
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1942 if (empty($struct->parts)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1943 // ...don't trust given content-type
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1944 if (!empty($headers->ctype)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1945 $struct->mime_id = '1';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1946 $struct->mimetype = strtolower($headers->ctype);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1947 list($struct->ctype_primary, $struct->ctype_secondary) = explode('/', $struct->mimetype);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1948 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1949
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1950 // ...and charset (there's a case described in #1488968 where invalid content-type
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1951 // results in invalid charset in BODYSTRUCTURE)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1952 if (!empty($headers->charset) && $headers->charset != $struct->ctype_parameters['charset']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1953 $struct->charset = $headers->charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1954 $struct->ctype_parameters['charset'] = $headers->charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1955 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1956 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1957
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1958 $headers->structure = $struct;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1959
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1960 return $this->icache['message'] = $headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1961 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1962
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1963 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1964 * Build message part object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1965 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1966 * @param array $part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1967 * @param int $count
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1968 * @param string $parent
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1969 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1970 protected function structure_part($part, $count = 0, $parent = '', $mime_headers = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1971 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1972 $struct = new rcube_message_part;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1973 $struct->mime_id = empty($parent) ? (string)$count : "$parent.$count";
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1974
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1975 // multipart
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1976 if (is_array($part[0])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1977 $struct->ctype_primary = 'multipart';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1978
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1979 /* RFC3501: BODYSTRUCTURE fields of multipart part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1980 part1 array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1981 part2 array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1982 part3 array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1983 ....
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1984 1. subtype
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1985 2. parameters (optional)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1986 3. description (optional)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1987 4. language (optional)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1988 5. location (optional)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1989 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1990
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1991 // find first non-array entry
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1992 for ($i=1; $i<count($part); $i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1993 if (!is_array($part[$i])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1994 $struct->ctype_secondary = strtolower($part[$i]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1995
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1996 // read content type parameters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1997 if (is_array($part[$i+1])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1998 $struct->ctype_parameters = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1999 for ($j=0; $j<count($part[$i+1]); $j+=2) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2000 $param = strtolower($part[$i+1][$j]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2001 $struct->ctype_parameters[$param] = $part[$i+1][$j+1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2002 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2003 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2004
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2005 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2006 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2007 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2008
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2009 $struct->mimetype = 'multipart/'.$struct->ctype_secondary;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2010
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2011 // build parts list for headers pre-fetching
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2012 for ($i=0; $i<count($part); $i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2013 if (!is_array($part[$i])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2014 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2015 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2016 // fetch message headers if message/rfc822
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2017 // or named part (could contain Content-Location header)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2018 if (!is_array($part[$i][0])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2019 $tmp_part_id = $struct->mime_id ? $struct->mime_id.'.'.($i+1) : $i+1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2020 if (strtolower($part[$i][0]) == 'message' && strtolower($part[$i][1]) == 'rfc822') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2021 $mime_part_headers[] = $tmp_part_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2022 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2023 else if (in_array('name', (array)$part[$i][2]) && empty($part[$i][3])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2024 $mime_part_headers[] = $tmp_part_id;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2025 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2026 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2027 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2028
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2029 // pre-fetch headers of all parts (in one command for better performance)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2030 // @TODO: we could do this before _structure_part() call, to fetch
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2031 // headers for parts on all levels
21
73124dd49283 More cleaning up php8 Warnings/deprecations,
Charlie Root
parents: 19
diff changeset
2032 if (!empty($mime_part_headers)) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2033 $mime_part_headers = $this->conn->fetchMIMEHeaders($this->folder,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2034 $this->msg_uid, $mime_part_headers);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2035 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2036
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2037 $struct->parts = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2038 for ($i=0, $count=0; $i<count($part); $i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2039 if (!is_array($part[$i])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2040 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2041 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2042 $tmp_part_id = $struct->mime_id ? $struct->mime_id.'.'.($i+1) : $i+1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2043 $struct->parts[] = $this->structure_part($part[$i], ++$count, $struct->mime_id,
21
73124dd49283 More cleaning up php8 Warnings/deprecations,
Charlie Root
parents: 19
diff changeset
2044 empty($mime_part_headers[$tmp_part_id]) ? null : $mime_part_headers[$tmp_part_id]) ;
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2045 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2046
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2047 return $struct;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2048 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2049
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2050 /* RFC3501: BODYSTRUCTURE fields of non-multipart part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2051 0. type
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2052 1. subtype
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2053 2. parameters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2054 3. id
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2055 4. description
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2056 5. encoding
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2057 6. size
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2058 -- text
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2059 7. lines
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2060 -- message/rfc822
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2061 7. envelope structure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2062 8. body structure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2063 9. lines
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2064 --
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2065 x. md5 (optional)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2066 x. disposition (optional)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2067 x. language (optional)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2068 x. location (optional)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2069 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2070
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2071 // regular part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2072 $struct->ctype_primary = strtolower($part[0]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2073 $struct->ctype_secondary = strtolower($part[1]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2074 $struct->mimetype = $struct->ctype_primary.'/'.$struct->ctype_secondary;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2075
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2076 // read content type parameters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2077 if (is_array($part[2])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2078 $struct->ctype_parameters = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2079 for ($i=0; $i<count($part[2]); $i+=2) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2080 $struct->ctype_parameters[strtolower($part[2][$i])] = $part[2][$i+1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2081 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2082
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2083 if (isset($struct->ctype_parameters['charset'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2084 $struct->charset = $struct->ctype_parameters['charset'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2085 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2086 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2087
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2088 // #1487700: workaround for lack of charset in malformed structure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2089 if (empty($struct->charset) && !empty($mime_headers) && $mime_headers->charset) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2090 $struct->charset = $mime_headers->charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2091 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2092
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2093 // read content encoding
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2094 if (!empty($part[5])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2095 $struct->encoding = strtolower($part[5]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2096 $struct->headers['content-transfer-encoding'] = $struct->encoding;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2097 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2098
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2099 // get part size
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2100 if (!empty($part[6])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2101 $struct->size = intval($part[6]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2102 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2103
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2104 // read part disposition
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2105 $di = 8;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2106 if ($struct->ctype_primary == 'text') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2107 $di += 1;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2108 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2109 else if ($struct->mimetype == 'message/rfc822') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2110 $di += 3;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2111 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2112
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2113 if (is_array($part[$di]) && count($part[$di]) == 2) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2114 $struct->disposition = strtolower($part[$di][0]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2115 if ($struct->disposition && $struct->disposition !== 'inline' && $struct->disposition !== 'attachment') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2116 // RFC2183, Section 2.8 - unrecognized type should be treated as "attachment"
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2117 $struct->disposition = 'attachment';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2118 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2119 if (is_array($part[$di][1])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2120 for ($n=0; $n<count($part[$di][1]); $n+=2) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2121 $struct->d_parameters[strtolower($part[$di][1][$n])] = $part[$di][1][$n+1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2122 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2123 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2124 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2125
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2126 // get message/rfc822's child-parts
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2127 if (is_array($part[8]) && $di != 8) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2128 $struct->parts = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2129 for ($i=0, $count=0; $i<count($part[8]); $i++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2130 if (!is_array($part[8][$i])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2131 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2132 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2133 $struct->parts[] = $this->structure_part($part[8][$i], ++$count, $struct->mime_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2134 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2135 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2136
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2137 // get part ID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2138 if (!empty($part[3])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2139 $struct->content_id = $part[3];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2140 $struct->headers['content-id'] = $part[3];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2141
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2142 if (empty($struct->disposition)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2143 $struct->disposition = 'inline';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2144 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2145 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2146
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2147 // fetch message headers if message/rfc822 or named part (could contain Content-Location header)
21
73124dd49283 More cleaning up php8 Warnings/deprecations,
Charlie Root
parents: 19
diff changeset
2148 if ($struct->ctype_primary == 'message' || (!empty($struct->ctype_parameters['name']) && !$struct->content_id)) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2149 if (empty($mime_headers)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2150 $mime_headers = $this->conn->fetchPartHeader(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2151 $this->folder, $this->msg_uid, true, $struct->mime_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2152 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2153
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2154 if (is_string($mime_headers)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2155 $struct->headers = rcube_mime::parse_headers($mime_headers) + $struct->headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2156 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2157 else if (is_object($mime_headers)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2158 $struct->headers = get_object_vars($mime_headers) + $struct->headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2159 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2160
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2161 // get real content-type of message/rfc822
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2162 if ($struct->mimetype == 'message/rfc822') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2163 // single-part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2164 if (!is_array($part[8][0])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2165 $struct->real_mimetype = strtolower($part[8][0] . '/' . $part[8][1]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2166 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2167 // multi-part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2168 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2169 for ($n=0; $n<count($part[8]); $n++) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2170 if (!is_array($part[8][$n])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2171 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2172 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2173 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2174 $struct->real_mimetype = 'multipart/' . strtolower($part[8][$n]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2175 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2176 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2177
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2178 if ($struct->ctype_primary == 'message' && empty($struct->parts)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2179 if (is_array($part[8]) && $di != 8) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2180 $struct->parts[] = $this->structure_part($part[8], ++$count, $struct->mime_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2181 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2182 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2183 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2184
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2185 // normalize filename property
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2186 $this->set_part_filename($struct, $mime_headers);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2187
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2188 return $struct;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2189 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2190
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2191 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2192 * Set attachment filename from message part structure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2193 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2194 * @param rcube_message_part $part Part object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2195 * @param string $headers Part's raw headers
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2196 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2197 protected function set_part_filename(&$part, $headers = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2198 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2199 if (!empty($part->d_parameters['filename'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2200 $filename_mime = $part->d_parameters['filename'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2201 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2202 else if (!empty($part->d_parameters['filename*'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2203 $filename_encoded = $part->d_parameters['filename*'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2204 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2205 else if (!empty($part->ctype_parameters['name*'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2206 $filename_encoded = $part->ctype_parameters['name*'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2207 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2208 // RFC2231 value continuations
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2209 // TODO: this should be rewrited to support RFC2231 4.1 combinations
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2210 else if (!empty($part->d_parameters['filename*0'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2211 $i = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2212 while (isset($part->d_parameters['filename*'.$i])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2213 $filename_mime .= $part->d_parameters['filename*'.$i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2214 $i++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2215 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2216 // some servers (eg. dovecot-1.x) have no support for parameter value continuations
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2217 // we must fetch and parse headers "manually"
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2218 if ($i<2) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2219 if (!$headers) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2220 $headers = $this->conn->fetchPartHeader(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2221 $this->folder, $this->msg_uid, true, $part->mime_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2222 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2223 $filename_mime = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2224 $i = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2225 while (preg_match('/filename\*'.$i.'\s*=\s*"*([^"\n;]+)[";]*/', $headers, $matches)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2226 $filename_mime .= $matches[1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2227 $i++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2228 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2229 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2230 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2231 else if (!empty($part->d_parameters['filename*0*'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2232 $i = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2233 while (isset($part->d_parameters['filename*'.$i.'*'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2234 $filename_encoded .= $part->d_parameters['filename*'.$i.'*'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2235 $i++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2236 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2237 if ($i<2) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2238 if (!$headers) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2239 $headers = $this->conn->fetchPartHeader(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2240 $this->folder, $this->msg_uid, true, $part->mime_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2241 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2242 $filename_encoded = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2243 $i = 0; $matches = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2244 while (preg_match('/filename\*'.$i.'\*\s*=\s*"*([^"\n;]+)[";]*/', $headers, $matches)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2245 $filename_encoded .= $matches[1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2246 $i++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2247 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2248 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2249 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2250 else if (!empty($part->ctype_parameters['name*0'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2251 $i = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2252 while (isset($part->ctype_parameters['name*'.$i])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2253 $filename_mime .= $part->ctype_parameters['name*'.$i];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2254 $i++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2255 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2256 if ($i<2) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2257 if (!$headers) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2258 $headers = $this->conn->fetchPartHeader(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2259 $this->folder, $this->msg_uid, true, $part->mime_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2260 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2261 $filename_mime = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2262 $i = 0; $matches = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2263 while (preg_match('/\s+name\*'.$i.'\s*=\s*"*([^"\n;]+)[";]*/', $headers, $matches)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2264 $filename_mime .= $matches[1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2265 $i++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2266 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2267 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2268 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2269 else if (!empty($part->ctype_parameters['name*0*'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2270 $i = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2271 while (isset($part->ctype_parameters['name*'.$i.'*'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2272 $filename_encoded .= $part->ctype_parameters['name*'.$i.'*'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2273 $i++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2274 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2275 if ($i<2) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2276 if (!$headers) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2277 $headers = $this->conn->fetchPartHeader(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2278 $this->folder, $this->msg_uid, true, $part->mime_id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2279 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2280 $filename_encoded = '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2281 $i = 0; $matches = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2282 while (preg_match('/\s+name\*'.$i.'\*\s*=\s*"*([^"\n;]+)[";]*/', $headers, $matches)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2283 $filename_encoded .= $matches[1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2284 $i++;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2285 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2286 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2287 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2288 // read 'name' after rfc2231 parameters as it may contains truncated filename (from Thunderbird)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2289 else if (!empty($part->ctype_parameters['name'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2290 $filename_mime = $part->ctype_parameters['name'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2291 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2292 // Content-Disposition
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2293 else if (!empty($part->headers['content-description'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2294 $filename_mime = $part->headers['content-description'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2295 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2296 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2297 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2298 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2299
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2300 // decode filename
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2301 if (!empty($filename_mime)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2302 if (!empty($part->charset)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2303 $charset = $part->charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2304 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2305 else if (!empty($this->struct_charset)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2306 $charset = $this->struct_charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2307 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2308 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2309 $charset = rcube_charset::detect($filename_mime, $this->default_charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2310 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2311
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2312 $part->filename = rcube_mime::decode_mime_string($filename_mime, $charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2313 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2314 else if (!empty($filename_encoded)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2315 // decode filename according to RFC 2231, Section 4
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2316 if (preg_match("/^([^']*)'[^']*'(.*)$/", $filename_encoded, $fmatches)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2317 $filename_charset = $fmatches[1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2318 $filename_encoded = $fmatches[2];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2319 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2320
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2321 $part->filename = rcube_charset::convert(urldecode($filename_encoded), $filename_charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2322 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2323 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2324
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2325 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2326 * Get charset name from message structure (first part)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2327 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2328 * @param array $structure Message structure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2329 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2330 * @return string Charset name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2331 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2332 protected function structure_charset($structure)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2333 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2334 while (is_array($structure)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2335 if (is_array($structure[2]) && $structure[2][0] == 'charset') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2336 return $structure[2][1];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2337 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2338 $structure = $structure[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2339 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2340 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2341
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2342
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2343 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2344 * Fetch message body of a specific message from the server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2345 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2346 * @param int Message UID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2347 * @param string Part number
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2348 * @param rcube_message_part Part object created by get_structure()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2349 * @param mixed True to print part, resource to write part contents in
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2350 * @param resource File pointer to save the message part
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2351 * @param boolean Disables charset conversion
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2352 * @param int Only read this number of bytes
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2353 * @param boolean Enables formatting of text/* parts bodies
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2354 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2355 * @return string Message/part body if not printed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2356 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2357 public function get_message_part($uid, $part = 1, $o_part = null, $print = null, $fp = null,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2358 $skip_charset_conv = false, $max_bytes = 0, $formatted = true)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2359 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2360 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2361 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2362 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2363
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2364 // get part data if not provided
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2365 if (!is_object($o_part)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2366 $structure = $this->conn->getStructure($this->folder, $uid, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2367 $part_data = rcube_imap_generic::getStructurePartData($structure, $part);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2368
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2369 $o_part = new rcube_message_part;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2370 $o_part->ctype_primary = $part_data['type'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2371 $o_part->encoding = $part_data['encoding'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2372 $o_part->charset = $part_data['charset'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2373 $o_part->size = $part_data['size'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2374 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2375
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2376 if ($o_part && $o_part->size) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2377 $formatted = $formatted && $o_part->ctype_primary == 'text';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2378 $body = $this->conn->handlePartBody($this->folder, $uid, true,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2379 $part ? $part : 'TEXT', $o_part->encoding, $print, $fp, $formatted, $max_bytes);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2380 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2381
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2382 if ($fp || $print) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2383 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2384 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2385
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2386 // convert charset (if text or message part)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2387 if ($body && preg_match('/^(text|message)$/', $o_part->ctype_primary)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2388 // Remove NULL characters if any (#1486189)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2389 if ($formatted && strpos($body, "\x00") !== false) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2390 $body = str_replace("\x00", '', $body);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2391 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2392
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2393 if (!$skip_charset_conv) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2394 if (!$o_part->charset || strtoupper($o_part->charset) == 'US-ASCII') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2395 // try to extract charset information from HTML meta tag (#1488125)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2396 if ($o_part->ctype_secondary == 'html' && preg_match('/<meta[^>]+charset=([a-z0-9-_]+)/i', $body, $m)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2397 $o_part->charset = strtoupper($m[1]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2398 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2399 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2400 $o_part->charset = $this->default_charset;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2401 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2402 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2403 $body = rcube_charset::convert($body, $o_part->charset);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2404 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2405 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2406
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2407 return $body;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2408 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2409
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2410 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2411 * Returns the whole message source as string (or saves to a file)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2412 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2413 * @param int $uid Message UID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2414 * @param resource $fp File pointer to save the message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2415 * @param string $part Optional message part ID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2416 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2417 * @return string Message source string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2418 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2419 public function get_raw_body($uid, $fp=null, $part = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2420 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2421 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2422 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2423 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2424
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2425 return $this->conn->handlePartBody($this->folder, $uid,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2426 true, $part, null, false, $fp);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2427 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2428
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2429 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2430 * Returns the message headers as string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2431 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2432 * @param int $uid Message UID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2433 * @param string $part Optional message part ID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2434 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2435 * @return string Message headers string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2436 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2437 public function get_raw_headers($uid, $part = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2438 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2439 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2440 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2441 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2442
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2443 return $this->conn->fetchPartHeader($this->folder, $uid, true, $part);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2444 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2445
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2446 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2447 * Sends the whole message source to stdout
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2448 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2449 * @param int $uid Message UID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2450 * @param bool $formatted Enables line-ending formatting
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2451 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2452 public function print_raw_body($uid, $formatted = true)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2453 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2454 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2455 return;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2456 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2457
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2458 $this->conn->handlePartBody($this->folder, $uid, true, null, null, true, null, $formatted);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2459 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2460
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2461 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2462 * Set message flag to one or several messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2463 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2464 * @param mixed $uids Message UIDs as array or comma-separated string, or '*'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2465 * @param string $flag Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2466 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2467 * @param boolean $skip_cache True to skip message cache clean up
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2468 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2469 * @return boolean Operation status
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2470 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2471 public function set_flag($uids, $flag, $folder=null, $skip_cache=false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2472 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2473 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2474 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2475 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2476
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2477 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2478 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2479 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2480
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2481 $flag = strtoupper($flag);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2482 list($uids, $all_mode) = $this->parse_uids($uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2483
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2484 if (strpos($flag, 'UN') === 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2485 $result = $this->conn->unflag($folder, $uids, substr($flag, 2));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2486 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2487 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2488 $result = $this->conn->flag($folder, $uids, $flag);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2489 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2490
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2491 if ($result && !$skip_cache) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2492 // reload message headers if cached
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2493 // update flags instead removing from cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2494 if ($mcache = $this->get_mcache_engine()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2495 $status = strpos($flag, 'UN') !== 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2496 $mflag = preg_replace('/^UN/', '', $flag);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2497 $mcache->change_flag($folder, $all_mode ? null : explode(',', $uids),
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2498 $mflag, $status);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2499 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2500
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2501 // clear cached counters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2502 if ($flag == 'SEEN' || $flag == 'UNSEEN') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2503 $this->clear_messagecount($folder, array('SEEN', 'UNSEEN'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2504 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2505 else if ($flag == 'DELETED' || $flag == 'UNDELETED') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2506 $this->clear_messagecount($folder, array('ALL', 'THREADS'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2507 if ($this->options['skip_deleted']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2508 // remove cached messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2509 $this->clear_message_cache($folder, $all_mode ? null : explode(',', $uids));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2510 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2511 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2512
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2513 $this->set_search_dirty($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2514 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2515
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2516 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2517 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2518
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2519 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2520 * Append a mail message (source) to a specific folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2521 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2522 * @param string $folder Target folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2523 * @param string|array $message The message source string or filename
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2524 * or array (of strings and file pointers)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2525 * @param string $headers Headers string if $message contains only the body
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2526 * @param boolean $is_file True if $message is a filename
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2527 * @param array $flags Message flags
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2528 * @param mixed $date Message internal date
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2529 * @param bool $binary Enables BINARY append
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2530 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2531 * @return int|bool Appended message UID or True on success, False on error
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2532 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2533 public function save_message($folder, &$message, $headers='', $is_file=false, $flags = array(), $date = null, $binary = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2534 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2535 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2536 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2537 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2538
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2539 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2540 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2541 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2542
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2543 // make sure folder exists
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2544 if (!$this->folder_exists($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2545 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2546 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2547
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2548 $date = $this->date_format($date);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2549
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2550 if ($is_file) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2551 $saved = $this->conn->appendFromFile($folder, $message, $headers, $flags, $date, $binary);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2552 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2553 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2554 $saved = $this->conn->append($folder, $message, $flags, $date, $binary);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2555 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2556
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2557 if ($saved) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2558 // increase messagecount of the target folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2559 $this->set_messagecount($folder, 'ALL', 1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2560
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2561 $this->plugins->exec_hook('message_saved', array(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2562 'folder' => $folder,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2563 'message' => $message,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2564 'headers' => $headers,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2565 'is_file' => $is_file,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2566 'flags' => $flags,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2567 'date' => $date,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2568 'binary' => $binary,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2569 'result' => $saved,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2570 ));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2571 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2572
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2573 return $saved;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2574 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2575
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2576 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2577 * Move a message from one folder to another
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2578 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2579 * @param mixed $uids Message UIDs as array or comma-separated string, or '*'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2580 * @param string $to_mbox Target folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2581 * @param string $from_mbox Source folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2582 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2583 * @return boolean True on success, False on error
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2584 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2585 public function move_message($uids, $to_mbox, $from_mbox='')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2586 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2587 if (!strlen($from_mbox)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2588 $from_mbox = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2589 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2590
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2591 if ($to_mbox === $from_mbox) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2592 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2593 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2594
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2595 list($uids, $all_mode) = $this->parse_uids($uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2596
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2597 // exit if no message uids are specified
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2598 if (empty($uids)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2599 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2600 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2601
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2602 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2603 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2604 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2605
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2606 $config = rcube::get_instance()->config;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2607 $to_trash = $to_mbox == $config->get('trash_mbox');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2608
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2609 // flag messages as read before moving them
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2610 if ($to_trash && $config->get('read_when_deleted')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2611 // don't flush cache (4th argument)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2612 $this->set_flag($uids, 'SEEN', $from_mbox, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2613 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2614
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2615 // move messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2616 $moved = $this->conn->move($uids, $from_mbox, $to_mbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2617
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2618 // when moving to Trash we make sure the folder exists
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2619 // as it's uncommon scenario we do this when MOVE fails, not before
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2620 if (!$moved && $to_trash && $this->get_response_code() == rcube_storage::TRYCREATE) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2621 if ($this->create_folder($to_mbox, true, 'trash')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2622 $moved = $this->conn->move($uids, $from_mbox, $to_mbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2623 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2624 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2625
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2626 if ($moved) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2627 $this->clear_messagecount($from_mbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2628 $this->clear_messagecount($to_mbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2629
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2630 $this->set_search_dirty($from_mbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2631 $this->set_search_dirty($to_mbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2632 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2633 // moving failed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2634 else if ($to_trash && $config->get('delete_always', false)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2635 $moved = $this->delete_message($uids, $from_mbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2636 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2637
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2638 if ($moved) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2639 // unset threads internal cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2640 unset($this->icache['threads']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2641
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2642 // remove message ids from search set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2643 if ($this->search_set && $from_mbox == $this->folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2644 // threads are too complicated to just remove messages from set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2645 if ($this->search_threads || $all_mode) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2646 $this->refresh_search();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2647 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2648 else if (!$this->search_set->incomplete) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2649 $this->search_set->filter(explode(',', $uids), $this->folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2650 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2651 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2652
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2653 // remove cached messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2654 // @TODO: do cache update instead of clearing it
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2655 $this->clear_message_cache($from_mbox, $all_mode ? null : explode(',', $uids));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2656 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2657
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2658 return $moved;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2659 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2660
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2661 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2662 * Copy a message from one folder to another
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2663 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2664 * @param mixed $uids Message UIDs as array or comma-separated string, or '*'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2665 * @param string $to_mbox Target folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2666 * @param string $from_mbox Source folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2667 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2668 * @return boolean True on success, False on error
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2669 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2670 public function copy_message($uids, $to_mbox, $from_mbox='')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2671 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2672 if (!strlen($from_mbox)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2673 $from_mbox = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2674 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2675
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2676 list($uids, $all_mode) = $this->parse_uids($uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2677
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2678 // exit if no message uids are specified
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2679 if (empty($uids)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2680 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2681 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2682
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2683 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2684 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2685 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2686
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2687 // copy messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2688 $copied = $this->conn->copy($uids, $from_mbox, $to_mbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2689
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2690 if ($copied) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2691 $this->clear_messagecount($to_mbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2692 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2693
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2694 return $copied;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2695 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2696
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2697 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2698 * Mark messages as deleted and expunge them
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2699 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2700 * @param mixed $uids Message UIDs as array or comma-separated string, or '*'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2701 * @param string $folder Source folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2702 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2703 * @return boolean True on success, False on error
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2704 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2705 public function delete_message($uids, $folder='')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2706 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2707 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2708 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2709 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2710
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2711 list($uids, $all_mode) = $this->parse_uids($uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2712
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2713 // exit if no message uids are specified
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2714 if (empty($uids)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2715 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2716 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2717
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2718 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2719 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2720 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2721
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2722 $deleted = $this->conn->flag($folder, $uids, 'DELETED');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2723
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2724 if ($deleted) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2725 // send expunge command in order to have the deleted message
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2726 // really deleted from the folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2727 $this->expunge_message($uids, $folder, false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2728 $this->clear_messagecount($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2729
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2730 // unset threads internal cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2731 unset($this->icache['threads']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2732
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2733 $this->set_search_dirty($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2734
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2735 // remove message ids from search set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2736 if ($this->search_set && $folder == $this->folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2737 // threads are too complicated to just remove messages from set
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2738 if ($this->search_threads || $all_mode) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2739 $this->refresh_search();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2740 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2741 else if (!$this->search_set->incomplete) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2742 $this->search_set->filter(explode(',', $uids));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2743 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2744 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2745
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2746 // remove cached messages
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2747 $this->clear_message_cache($folder, $all_mode ? null : explode(',', $uids));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2748 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2749
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2750 return $deleted;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2751 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2752
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2753 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2754 * Send IMAP expunge command and clear cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2755 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2756 * @param mixed $uids Message UIDs as array or comma-separated string, or '*'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2757 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2758 * @param boolean $clear_cache False if cache should not be cleared
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2759 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2760 * @return boolean True on success, False on failure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2761 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2762 public function expunge_message($uids, $folder = null, $clear_cache = true)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2763 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2764 if ($uids && $this->get_capability('UIDPLUS')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2765 list($uids, $all_mode) = $this->parse_uids($uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2766 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2767 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2768 $uids = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2769 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2770
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2771 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2772 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2773 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2774
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2775 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2776 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2777 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2778
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2779 // force folder selection and check if folder is writeable
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2780 // to prevent a situation when CLOSE is executed on closed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2781 // or EXPUNGE on read-only folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2782 $result = $this->conn->select($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2783 if (!$result) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2784 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2785 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2786
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2787 if (!$this->conn->data['READ-WRITE']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2788 $this->conn->setError(rcube_imap_generic::ERROR_READONLY, "Folder is read-only");
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2789 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2790 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2791
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2792 // CLOSE(+SELECT) should be faster than EXPUNGE
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2793 if (empty($uids) || $all_mode) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2794 $result = $this->conn->close();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2795 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2796 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2797 $result = $this->conn->expunge($folder, $uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2798 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2799
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2800 if ($result && $clear_cache) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2801 $this->clear_message_cache($folder, $all_mode ? null : explode(',', $uids));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2802 $this->clear_messagecount($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2803 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2804
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2805 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2806 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2807
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2808
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2809 /* --------------------------------
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2810 * folder management
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2811 * --------------------------------*/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2812
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2813 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2814 * Public method for listing subscribed folders.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2815 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2816 * @param string $root Optional root folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2817 * @param string $name Optional name pattern
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2818 * @param string $filter Optional filter
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2819 * @param string $rights Optional ACL requirements
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2820 * @param bool $skip_sort Enable to return unsorted list (for better performance)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2821 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2822 * @return array List of folders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2823 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2824 public function list_folders_subscribed($root='', $name='*', $filter=null, $rights=null, $skip_sort=false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2825 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2826 $cache_key = $root.':'.$name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2827 if (!empty($filter)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2828 $cache_key .= ':'.(is_string($filter) ? $filter : serialize($filter));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2829 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2830 $cache_key .= ':'.$rights;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2831 $cache_key = 'mailboxes.'.md5($cache_key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2832
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2833 // get cached folder list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2834 $a_mboxes = $this->get_cache($cache_key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2835 if (is_array($a_mboxes)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2836 return $a_mboxes;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2837 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2838
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2839 // Give plugins a chance to provide a list of folders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2840 $data = $this->plugins->exec_hook('storage_folders',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2841 array('root' => $root, 'name' => $name, 'filter' => $filter, 'mode' => 'LSUB'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2842
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2843 if (isset($data['folders'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2844 $a_mboxes = $data['folders'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2845 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2846 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2847 $a_mboxes = $this->list_folders_subscribed_direct($root, $name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2848 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2849
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2850 if (!is_array($a_mboxes)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2851 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2852 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2853
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2854 // filter folders list according to rights requirements
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2855 if ($rights && $this->get_capability('ACL')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2856 $a_mboxes = $this->filter_rights($a_mboxes, $rights);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2857 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2858
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2859 // INBOX should always be available
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2860 if (in_array_nocase($root . $name, array('*', '%', 'INBOX', 'INBOX*'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2861 && (!$filter || $filter == 'mail') && !in_array('INBOX', $a_mboxes)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2862 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2863 array_unshift($a_mboxes, 'INBOX');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2864 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2865
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2866 // sort folders (always sort for cache)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2867 if (!$skip_sort || $this->cache) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2868 $a_mboxes = $this->sort_folder_list($a_mboxes);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2869 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2870
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2871 // write folders list to cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2872 $this->update_cache($cache_key, $a_mboxes);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2873
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2874 return $a_mboxes;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2875 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2876
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2877 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2878 * Method for direct folders listing (LSUB)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2879 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2880 * @param string $root Optional root folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2881 * @param string $name Optional name pattern
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2882 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2883 * @return array List of subscribed folders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2884 * @see rcube_imap::list_folders_subscribed()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2885 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2886 public function list_folders_subscribed_direct($root='', $name='*')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2887 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2888 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2889 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2890 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2891
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2892 $config = rcube::get_instance()->config;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2893
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2894 // Server supports LIST-EXTENDED, we can use selection options
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2895 // #1486225: Some dovecot versions returns wrong result using LIST-EXTENDED
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2896 $list_extended = !$config->get('imap_force_lsub') && $this->get_capability('LIST-EXTENDED');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2897 if ($list_extended) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2898 // This will also set folder options, LSUB doesn't do that
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2899 $result = $this->conn->listMailboxes($root, $name,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2900 NULL, array('SUBSCRIBED'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2901 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2902 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2903 // retrieve list of folders from IMAP server using LSUB
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2904 $result = $this->conn->listSubscribed($root, $name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2905 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2906
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2907 if (!is_array($result)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2908 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2909 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2910
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2911 // #1486796: some server configurations doesn't return folders in all namespaces
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2912 if ($root == '' && $name == '*' && $config->get('imap_force_ns')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2913 $this->list_folders_update($result, ($list_extended ? 'ext-' : '') . 'subscribed');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2914 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2915
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2916 // Remove hidden folders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2917 if ($config->get('imap_skip_hidden_folders')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2918 $result = array_filter($result, function($v) { return $v[0] != '.'; });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2919 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2920
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2921 if ($list_extended) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2922 // unsubscribe non-existent folders, remove from the list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2923 if ($name == '*' && !empty($this->conn->data['LIST'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2924 foreach ($result as $idx => $folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2925 if (($opts = $this->conn->data['LIST'][$folder])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2926 && in_array_nocase('\\NonExistent', $opts)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2927 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2928 $this->conn->unsubscribe($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2929 unset($result[$idx]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2930 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2931 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2932 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2933 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2934 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2935 // unsubscribe non-existent folders, remove them from the list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2936 if (!empty($result) && $name == '*') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2937 $existing = $this->list_folders($root, $name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2938 $nonexisting = array_diff($result, $existing);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2939 $result = array_diff($result, $nonexisting);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2940
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2941 foreach ($nonexisting as $folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2942 $this->conn->unsubscribe($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2943 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2944 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2945 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2946
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2947 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2948 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2949
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2950 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2951 * Get a list of all folders available on the server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2952 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2953 * @param string $root IMAP root dir
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2954 * @param string $name Optional name pattern
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2955 * @param mixed $filter Optional filter
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2956 * @param string $rights Optional ACL requirements
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2957 * @param bool $skip_sort Enable to return unsorted list (for better performance)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2958 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2959 * @return array Indexed array with folder names
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2960 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2961 public function list_folders($root='', $name='*', $filter=null, $rights=null, $skip_sort=false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2962 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2963 $cache_key = $root.':'.$name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2964 if (!empty($filter)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2965 $cache_key .= ':'.(is_string($filter) ? $filter : serialize($filter));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2966 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2967 $cache_key .= ':'.$rights;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2968 $cache_key = 'mailboxes.list.'.md5($cache_key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2969
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2970 // get cached folder list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2971 $a_mboxes = $this->get_cache($cache_key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2972 if (is_array($a_mboxes)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2973 return $a_mboxes;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2974 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2975
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2976 // Give plugins a chance to provide a list of folders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2977 $data = $this->plugins->exec_hook('storage_folders',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2978 array('root' => $root, 'name' => $name, 'filter' => $filter, 'mode' => 'LIST'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2979
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2980 if (isset($data['folders'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2981 $a_mboxes = $data['folders'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2982 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2983 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2984 // retrieve list of folders from IMAP server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2985 $a_mboxes = $this->list_folders_direct($root, $name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2986 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2987
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2988 if (!is_array($a_mboxes)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2989 $a_mboxes = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2990 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2991
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2992 // INBOX should always be available
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2993 if (in_array_nocase($root . $name, array('*', '%', 'INBOX', 'INBOX*'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2994 && (!$filter || $filter == 'mail') && !in_array('INBOX', $a_mboxes)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2995 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2996 array_unshift($a_mboxes, 'INBOX');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2997 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2998
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2999 // cache folder attributes
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3000 if ($root == '' && $name == '*' && empty($filter) && !empty($this->conn->data)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3001 $this->update_cache('mailboxes.attributes', $this->conn->data['LIST']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3002 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3003
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3004 // filter folders list according to rights requirements
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3005 if ($rights && $this->get_capability('ACL')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3006 $a_mboxes = $this->filter_rights($a_mboxes, $rights);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3007 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3008
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3009 // filter folders and sort them
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3010 if (!$skip_sort) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3011 $a_mboxes = $this->sort_folder_list($a_mboxes);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3012 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3013
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3014 // write folders list to cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3015 $this->update_cache($cache_key, $a_mboxes);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3016
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3017 return $a_mboxes;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3018 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3019
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3020 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3021 * Method for direct folders listing (LIST)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3022 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3023 * @param string $root Optional root folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3024 * @param string $name Optional name pattern
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3025 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3026 * @return array List of folders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3027 * @see rcube_imap::list_folders()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3028 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3029 public function list_folders_direct($root='', $name='*')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3030 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3031 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3032 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3033 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3034
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3035 $result = $this->conn->listMailboxes($root, $name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3036
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3037 if (!is_array($result)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3038 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3039 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3040
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3041 $config = rcube::get_instance()->config;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3042
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3043 // #1486796: some server configurations doesn't return folders in all namespaces
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3044 if ($root == '' && $name == '*' && $config->get('imap_force_ns')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3045 $this->list_folders_update($result);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3046 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3047
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3048 // Remove hidden folders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3049 if ($config->get('imap_skip_hidden_folders')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3050 $result = array_filter($result, function($v) { return $v[0] != '.'; });
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3051 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3052
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3053 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3054 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3055
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3056 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3057 * Fix folders list by adding folders from other namespaces.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3058 * Needed on some servers eg. Courier IMAP
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3059 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3060 * @param array $result Reference to folders list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3061 * @param string $type Listing type (ext-subscribed, subscribed or all)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3062 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3063 protected function list_folders_update(&$result, $type = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3064 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3065 $namespace = $this->get_namespace();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3066 $search = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3067
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3068 // build list of namespace prefixes
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3069 foreach ((array)$namespace as $ns) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3070 if (is_array($ns)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3071 foreach ($ns as $ns_data) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3072 if (strlen($ns_data[0])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3073 $search[] = $ns_data[0];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3074 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3075 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3076 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3077 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3078
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3079 if (!empty($search)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3080 // go through all folders detecting namespace usage
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3081 foreach ($result as $folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3082 foreach ($search as $idx => $prefix) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3083 if (strpos($folder, $prefix) === 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3084 unset($search[$idx]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3085 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3086 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3087 if (empty($search)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3088 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3089 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3090 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3091
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3092 // get folders in hidden namespaces and add to the result
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3093 foreach ($search as $prefix) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3094 if ($type == 'ext-subscribed') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3095 $list = $this->conn->listMailboxes('', $prefix . '*', null, array('SUBSCRIBED'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3096 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3097 else if ($type == 'subscribed') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3098 $list = $this->conn->listSubscribed('', $prefix . '*');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3099 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3100 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3101 $list = $this->conn->listMailboxes('', $prefix . '*');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3102 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3103
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3104 if (!empty($list)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3105 $result = array_merge($result, $list);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3106 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3107 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3108 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3109 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3110
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3111 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3112 * Filter the given list of folders according to access rights
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3113 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3114 * For performance reasons we assume user has full rights
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3115 * on all personal folders.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3116 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3117 protected function filter_rights($a_folders, $rights)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3118 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3119 $regex = '/('.$rights.')/';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3120
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3121 foreach ($a_folders as $idx => $folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3122 if ($this->folder_namespace($folder) == 'personal') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3123 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3124 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3125
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3126 $myrights = join('', (array)$this->my_rights($folder));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3127
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3128 if ($myrights !== null && !preg_match($regex, $myrights)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3129 unset($a_folders[$idx]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3130 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3131 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3132
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3133 return $a_folders;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3134 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3135
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3136 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3137 * Get mailbox quota information
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3138 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3139 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3140 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3141 * @return mixed Quota info or False if not supported
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3142 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3143 public function get_quota($folder = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3144 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3145 if ($this->get_capability('QUOTA') && $this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3146 return $this->conn->getQuota($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3147 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3148
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3149 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3150 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3151
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3152 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3153 * Get folder size (size of all messages in a folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3154 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3155 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3156 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3157 * @return int Folder size in bytes, False on error
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3158 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3159 public function folder_size($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3160 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3161 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3162 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3163 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3164
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3165 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3166 return 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3167 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3168
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3169 // On Cyrus we can use special folder annotation, which should be much faster
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3170 if ($this->get_vendor() == 'cyrus') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3171 $idx = '/shared/vendor/cmu/cyrus-imapd/size';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3172 $result = $this->get_metadata($folder, $idx, array(), true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3173
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3174 if (!empty($result) && is_numeric($result[$folder][$idx])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3175 return $result[$folder][$idx];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3176 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3177 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3178
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3179 // @TODO: could we try to use QUOTA here?
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3180 $result = $this->conn->fetchHeaderIndex($folder, '1:*', 'SIZE', false);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3181
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3182 if (is_array($result)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3183 $result = array_sum($result);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3184 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3185
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3186 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3187 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3188
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3189 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3190 * Subscribe to a specific folder(s)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3191 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3192 * @param array $folders Folder name(s)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3193 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3194 * @return boolean True on success
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3195 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3196 public function subscribe($folders)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3197 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3198 // let this common function do the main work
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3199 return $this->change_subscription($folders, 'subscribe');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3200 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3201
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3202 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3203 * Unsubscribe folder(s)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3204 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3205 * @param array $a_mboxes Folder name(s)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3206 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3207 * @return boolean True on success
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3208 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3209 public function unsubscribe($folders)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3210 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3211 // let this common function do the main work
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3212 return $this->change_subscription($folders, 'unsubscribe');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3213 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3214
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3215 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3216 * Create a new folder on the server and register it in local cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3217 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3218 * @param string $folder New folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3219 * @param boolean $subscribe True if the new folder should be subscribed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3220 * @param string $type Optional folder type (junk, trash, drafts, sent, archive)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3221 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3222 * @return boolean True on success
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3223 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3224 public function create_folder($folder, $subscribe = false, $type = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3225 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3226 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3227 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3228 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3229
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3230 $result = $this->conn->createFolder($folder, $type ? array("\\" . ucfirst($type)) : null);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3231
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3232 // try to subscribe it
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3233 if ($result) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3234 // clear cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3235 $this->clear_cache('mailboxes', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3236
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3237 if ($subscribe) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3238 $this->subscribe($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3239 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3240 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3241
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3242 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3243 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3244
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3245 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3246 * Set a new name to an existing folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3247 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3248 * @param string $folder Folder to rename
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3249 * @param string $new_name New folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3250 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3251 * @return boolean True on success
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3252 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3253 public function rename_folder($folder, $new_name)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3254 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3255 if (!strlen($new_name)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3256 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3257 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3258
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3259 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3260 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3261 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3262
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3263 $delm = $this->get_hierarchy_delimiter();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3264
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3265 // get list of subscribed folders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3266 if ((strpos($folder, '%') === false) && (strpos($folder, '*') === false)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3267 $a_subscribed = $this->list_folders_subscribed('', $folder . $delm . '*');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3268 $subscribed = $this->folder_exists($folder, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3269 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3270 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3271 $a_subscribed = $this->list_folders_subscribed();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3272 $subscribed = in_array($folder, $a_subscribed);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3273 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3274
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3275 $result = $this->conn->renameFolder($folder, $new_name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3276
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3277 if ($result) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3278 // unsubscribe the old folder, subscribe the new one
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3279 if ($subscribed) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3280 $this->conn->unsubscribe($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3281 $this->conn->subscribe($new_name);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3282 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3283
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3284 // check if folder children are subscribed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3285 foreach ($a_subscribed as $c_subscribed) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3286 if (strpos($c_subscribed, $folder.$delm) === 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3287 $this->conn->unsubscribe($c_subscribed);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3288 $this->conn->subscribe(preg_replace('/^'.preg_quote($folder, '/').'/',
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3289 $new_name, $c_subscribed));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3290
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3291 // clear cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3292 $this->clear_message_cache($c_subscribed);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3293 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3294 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3295
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3296 // clear cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3297 $this->clear_message_cache($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3298 $this->clear_cache('mailboxes', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3299 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3300
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3301 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3302 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3303
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3304 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3305 * Remove folder (with subfolders) from the server
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3306 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3307 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3308 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3309 * @return boolean True on success, False on failure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3310 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3311 function delete_folder($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3312 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3313 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3314 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3315 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3316
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3317 $delm = $this->get_hierarchy_delimiter();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3318
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3319 // get list of sub-folders or all folders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3320 // if folder name contains special characters
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3321 $path = strspn($folder, '%*') > 0 ? ($folder . $delm) : '';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3322 $sub_mboxes = $this->list_folders('', $path . '*');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3323
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3324 // According to RFC3501 deleting a \Noselect folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3325 // with subfolders may fail. To workaround this we delete
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3326 // subfolders first (in reverse order) (#5466)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3327 if (!empty($sub_mboxes)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3328 foreach (array_reverse($sub_mboxes) as $mbox) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3329 if (strpos($mbox, $folder . $delm) === 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3330 if ($this->conn->deleteFolder($mbox)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3331 $this->conn->unsubscribe($mbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3332 $this->clear_message_cache($mbox);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3333 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3334 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3335 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3336 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3337
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3338 // delete the folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3339 if ($result = $this->conn->deleteFolder($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3340 // and unsubscribe it
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3341 $this->conn->unsubscribe($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3342 $this->clear_message_cache($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3343 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3344
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3345 $this->clear_cache('mailboxes', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3346
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3347 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3348 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3349
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3350 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3351 * Detect special folder associations stored in storage backend
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3352 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3353 public function get_special_folders($forced = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3354 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3355 $result = parent::get_special_folders();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3356 $rcube = rcube::get_instance();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3357
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3358 // Lock SPECIAL-USE after user preferences change (#4782)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3359 if ($rcube->config->get('lock_special_folders')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3360 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3361 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3362
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3363 if (isset($this->icache['special-use'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3364 return array_merge($result, $this->icache['special-use']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3365 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3366
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3367 if (!$forced || !$this->get_capability('SPECIAL-USE')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3368 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3369 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3370
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3371 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3372 return $result;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3373 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3374
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3375 $types = array_map(function($value) { return "\\" . ucfirst($value); }, rcube_storage::$folder_types);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3376 $special = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3377
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3378 // request \Subscribed flag in LIST response as performance improvement for folder_exists()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3379 $folders = $this->conn->listMailboxes('', '*', array('SUBSCRIBED'), array('SPECIAL-USE'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3380
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3381 if (!empty($folders)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3382 foreach ($folders as $folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3383 if ($flags = $this->conn->data['LIST'][$folder]) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3384 foreach ($types as $type) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3385 if (in_array($type, $flags)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3386 $type = strtolower(substr($type, 1));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3387 $special[$type] = $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3388 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3389 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3390 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3391 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3392 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3393
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3394 $this->icache['special-use'] = $special;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3395 unset($this->icache['special-folders']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3396
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3397 return array_merge($result, $special);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3398 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3399
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3400 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3401 * Set special folder associations stored in storage backend
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3402 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3403 public function set_special_folders($specials)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3404 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3405 if (!$this->get_capability('SPECIAL-USE') || !$this->get_capability('METADATA')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3406 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3407 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3408
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3409 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3410 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3411 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3412
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3413 $folders = $this->get_special_folders(true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3414 $old = (array) $this->icache['special-use'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3415
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3416 foreach ($specials as $type => $folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3417 if (in_array($type, rcube_storage::$folder_types)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3418 $old_folder = $old[$type];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3419 if ($old_folder !== $folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3420 // unset old-folder metadata
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3421 if ($old_folder !== null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3422 $this->delete_metadata($old_folder, array('/private/specialuse'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3423 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3424 // set new folder metadata
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3425 if ($folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3426 $this->set_metadata($folder, array('/private/specialuse' => "\\" . ucfirst($type)));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3427 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3428 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3429 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3430 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3431
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3432 $this->icache['special-use'] = $specials;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3433 unset($this->icache['special-folders']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3434
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3435 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3436 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3437
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3438 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3439 * Checks if folder exists and is subscribed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3440 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3441 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3442 * @param boolean $subscription Enable subscription checking
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3443 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3444 * @return boolean TRUE or FALSE
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3445 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3446 public function folder_exists($folder, $subscription = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3447 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3448 if ($folder == 'INBOX') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3449 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3450 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3451
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3452 $key = $subscription ? 'subscribed' : 'existing';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3453
22
303b85d5b561 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 21
diff changeset
3454 if (is_array($this->icache[$key]??null) && in_array($folder, $this->icache[$key])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3455 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3456 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3457
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3458 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3459 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3460 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3461
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3462 if ($subscription) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3463 // It's possible we already called LIST command, check LIST data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3464 if (!empty($this->conn->data['LIST']) && !empty($this->conn->data['LIST'][$folder])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3465 && in_array_nocase('\\Subscribed', $this->conn->data['LIST'][$folder])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3466 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3467 $a_folders = array($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3468 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3469 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3470 $a_folders = $this->conn->listSubscribed('', $folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3471 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3472 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3473 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3474 // It's possible we already called LIST command, check LIST data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3475 if (!empty($this->conn->data['LIST']) && isset($this->conn->data['LIST'][$folder])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3476 $a_folders = array($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3477 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3478 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3479 $a_folders = $this->conn->listMailboxes('', $folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3480 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3481 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3482
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3483 if (is_array($a_folders) && in_array($folder, $a_folders)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3484 $this->icache[$key][] = $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3485 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3486 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3487
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3488 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3489 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3490
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3491 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3492 * Returns the namespace where the folder is in
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3493 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3494 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3495 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3496 * @return string One of 'personal', 'other' or 'shared'
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3497 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3498 public function folder_namespace($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3499 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3500 if ($folder == 'INBOX') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3501 return 'personal';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3502 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3503
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3504 foreach ($this->namespace as $type => $namespace) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3505 if (is_array($namespace)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3506 foreach ($namespace as $ns) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3507 if ($len = strlen($ns[0])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3508 if (($len > 1 && $folder == substr($ns[0], 0, -1))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3509 || strpos($folder, $ns[0]) === 0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3510 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3511 return $type;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3512 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3513 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3514 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3515 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3516 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3517
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3518 return 'personal';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3519 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3520
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3521 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3522 * Modify folder name according to personal namespace prefix.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3523 * For output it removes prefix of the personal namespace if it's possible.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3524 * For input it adds the prefix. Use it before creating a folder in root
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3525 * of the folders tree.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3526 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3527 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3528 * @param string $mode Mode name (out/in)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3529 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3530 * @return string Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3531 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3532 public function mod_folder($folder, $mode = 'out')
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3533 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3534 $prefix = $this->namespace['prefix_' . $mode]; // see set_env()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3535
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3536 if ($prefix === null || $prefix === ''
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3537 || !($prefix_len = strlen($prefix)) || !strlen($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3538 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3539 return $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3540 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3541
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3542 // remove prefix for output
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3543 if ($mode == 'out') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3544 if (substr($folder, 0, $prefix_len) === $prefix) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3545 return substr($folder, $prefix_len);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3546 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3547
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3548 return $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3549 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3550
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3551 // add prefix for input (e.g. folder creation)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3552 return $prefix . $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3553 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3554
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3555 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3556 * Gets folder attributes from LIST response, e.g. \Noselect, \Noinferiors
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3557 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3558 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3559 * @param bool $force Set to True if attributes should be refreshed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3560 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3561 * @return array Options list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3562 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3563 public function folder_attributes($folder, $force=false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3564 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3565 // get attributes directly from LIST command
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3566 if (!empty($this->conn->data['LIST']) && is_array($this->conn->data['LIST'][$folder])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3567 $opts = $this->conn->data['LIST'][$folder];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3568 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3569 // get cached folder attributes
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3570 else if (!$force) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3571 $opts = $this->get_cache('mailboxes.attributes');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3572 $opts = $opts[$folder];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3573 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3574
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3575 if (!is_array($opts)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3576 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3577 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3578 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3579
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3580 $this->conn->listMailboxes('', $folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3581 $opts = $this->conn->data['LIST'][$folder];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3582 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3583
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3584 return is_array($opts) ? $opts : array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3585 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3586
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3587 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3588 * Gets connection (and current folder) data: UIDVALIDITY, EXISTS, RECENT,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3589 * PERMANENTFLAGS, UIDNEXT, UNSEEN
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3590 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3591 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3592 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3593 * @return array Data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3594 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3595 public function folder_data($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3596 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3597 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3598 $folder = $this->folder !== null ? $this->folder : 'INBOX';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3599 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3600
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3601 if ($this->conn->selected != $folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3602 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3603 return array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3604 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3605
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3606 if ($this->conn->select($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3607 $this->folder = $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3608 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3609 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3610 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3611 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3612 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3613
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3614 $data = $this->conn->data;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3615
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3616 // add (E)SEARCH result for ALL UNDELETED query
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3617 if (!empty($this->icache['undeleted_idx'])
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3618 && $this->icache['undeleted_idx']->get_parameters('MAILBOX') == $folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3619 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3620 $data['UNDELETED'] = $this->icache['undeleted_idx'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3621 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3622
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3623 return $data;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3624 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3625
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3626 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3627 * Returns extended information about the folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3628 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3629 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3630 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3631 * @return array Data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3632 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3633 public function folder_info($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3634 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3635 if ($this->icache['options'] && $this->icache['options']['name'] == $folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3636 return $this->icache['options'];
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3637 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3638
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3639 // get cached metadata
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3640 $cache_key = 'mailboxes.folder-info.' . $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3641 $cached = $this->get_cache($cache_key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3642
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3643 if (is_array($cached)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3644 return $cached;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3645 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3646
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3647 $acl = $this->get_capability('ACL');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3648 $namespace = $this->get_namespace();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3649 $options = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3650
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3651 // check if the folder is a namespace prefix
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3652 if (!empty($namespace)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3653 $mbox = $folder . $this->delimiter;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3654 foreach ($namespace as $ns) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3655 if (!empty($ns)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3656 foreach ($ns as $item) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3657 if ($item[0] === $mbox) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3658 $options['is_root'] = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3659 break 2;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3660 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3661 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3662 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3663 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3664 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3665 // check if the folder is other user virtual-root
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3666 if (!$options['is_root'] && !empty($namespace) && !empty($namespace['other'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3667 $parts = explode($this->delimiter, $folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3668 if (count($parts) == 2) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3669 $mbox = $parts[0] . $this->delimiter;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3670 foreach ($namespace['other'] as $item) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3671 if ($item[0] === $mbox) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3672 $options['is_root'] = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3673 break;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3674 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3675 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3676 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3677 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3678
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3679 $options['name'] = $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3680 $options['attributes'] = $this->folder_attributes($folder, true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3681 $options['namespace'] = $this->folder_namespace($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3682 $options['special'] = $this->is_special_folder($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3683
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3684 // Set 'noselect' flag
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3685 if (is_array($options['attributes'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3686 foreach ($options['attributes'] as $attrib) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3687 $attrib = strtolower($attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3688 if ($attrib == '\noselect' || $attrib == '\nonexistent') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3689 $options['noselect'] = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3690 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3691 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3692 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3693 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3694 $options['noselect'] = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3695 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3696
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3697 // Get folder rights (MYRIGHTS)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3698 if ($acl && ($rights = $this->my_rights($folder))) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3699 $options['rights'] = $rights;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3700 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3701
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3702 // Set 'norename' flag
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3703 if (!empty($options['rights'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3704 $options['norename'] = !in_array('x', $options['rights']) && !in_array('d', $options['rights']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3705
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3706 if (!$options['noselect']) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3707 $options['noselect'] = !in_array('r', $options['rights']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3708 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3709 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3710 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3711 $options['norename'] = $options['is_root'] || $options['namespace'] != 'personal';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3712 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3713
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3714 // update caches
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3715 $this->icache['options'] = $options;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3716 $this->update_cache($cache_key, $options);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3717
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3718 return $options;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3719 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3720
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3721 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3722 * Synchronizes messages cache.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3723 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3724 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3725 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3726 public function folder_sync($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3727 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3728 if ($mcache = $this->get_mcache_engine()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3729 $mcache->synchronize($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3730 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3731 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3732
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3733 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3734 * Get message header names for rcube_imap_generic::fetchHeader(s)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3735 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3736 * @return string Space-separated list of header names
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3737 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3738 protected function get_fetch_headers()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3739 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3740 if (!empty($this->options['fetch_headers'])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3741 $headers = explode(' ', $this->options['fetch_headers']);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3742 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3743 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3744 $headers = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3745 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3746
19
b6a96bdd6b29 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 17
diff changeset
3747 if ($this->messages_caching || !empty($this->options['all_headers'])) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3748 $headers = array_merge($headers, $this->all_headers);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3749 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3750
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3751 return $headers;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3752 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3753
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3754
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3755 /* -----------------------------------------
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3756 * ACL and METADATA/ANNOTATEMORE methods
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3757 * ----------------------------------------*/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3758
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3759 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3760 * Changes the ACL on the specified folder (SETACL)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3761 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3762 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3763 * @param string $user User name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3764 * @param string $acl ACL string
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3765 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3766 * @return boolean True on success, False on failure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3767 * @since 0.5-beta
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3768 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3769 public function set_acl($folder, $user, $acl)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3770 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3771 if (!$this->get_capability('ACL')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3772 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3773 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3774
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3775 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3776 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3777 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3778
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3779 $this->clear_cache('mailboxes.folder-info.' . $folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3780
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3781 return $this->conn->setACL($folder, $user, $acl);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3782 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3783
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3784 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3785 * Removes any <identifier,rights> pair for the
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3786 * specified user from the ACL for the specified
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3787 * folder (DELETEACL)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3788 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3789 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3790 * @param string $user User name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3791 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3792 * @return boolean True on success, False on failure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3793 * @since 0.5-beta
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3794 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3795 public function delete_acl($folder, $user)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3796 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3797 if (!$this->get_capability('ACL')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3798 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3799 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3800
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3801 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3802 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3803 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3804
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3805 return $this->conn->deleteACL($folder, $user);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3806 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3807
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3808 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3809 * Returns the access control list for folder (GETACL)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3810 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3811 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3812 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3813 * @return array User-rights array on success, NULL on error
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3814 * @since 0.5-beta
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3815 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3816 public function get_acl($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3817 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3818 if (!$this->get_capability('ACL')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3819 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3820 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3821
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3822 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3823 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3824 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3825
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3826 return $this->conn->getACL($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3827 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3828
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3829 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3830 * Returns information about what rights can be granted to the
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3831 * user (identifier) in the ACL for the folder (LISTRIGHTS)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3832 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3833 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3834 * @param string $user User name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3835 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3836 * @return array List of user rights
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3837 * @since 0.5-beta
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3838 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3839 public function list_rights($folder, $user)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3840 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3841 if (!$this->get_capability('ACL')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3842 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3843 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3844
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3845 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3846 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3847 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3848
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3849 return $this->conn->listRights($folder, $user);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3850 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3851
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3852 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3853 * Returns the set of rights that the current user has to
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3854 * folder (MYRIGHTS)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3855 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3856 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3857 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3858 * @return array MYRIGHTS response on success, NULL on error
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3859 * @since 0.5-beta
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3860 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3861 public function my_rights($folder)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3862 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3863 if (!$this->get_capability('ACL')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3864 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3865 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3866
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3867 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3868 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3869 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3870
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3871 return $this->conn->myRights($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3872 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3873
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3874 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3875 * Sets IMAP metadata/annotations (SETMETADATA/SETANNOTATION)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3876 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3877 * @param string $folder Folder name (empty for server metadata)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3878 * @param array $entries Entry-value array (use NULL value as NIL)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3879 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3880 * @return boolean True on success, False on failure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3881 * @since 0.5-beta
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3882 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3883 public function set_metadata($folder, $entries)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3884 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3885 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3886 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3887 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3888
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3889 $this->clear_cache('mailboxes.metadata.', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3890
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3891 if ($this->get_capability('METADATA') ||
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3892 (!strlen($folder) && $this->get_capability('METADATA-SERVER'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3893 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3894 return $this->conn->setMetadata($folder, $entries);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3895 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3896 else if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3897 foreach ((array)$entries as $entry => $value) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3898 list($ent, $attr) = $this->md2annotate($entry);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3899 $entries[$entry] = array($ent, $attr, $value);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3900 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3901 return $this->conn->setAnnotation($folder, $entries);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3902 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3903
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3904 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3905 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3906
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3907 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3908 * Unsets IMAP metadata/annotations (SETMETADATA/SETANNOTATION)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3909 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3910 * @param string $folder Folder name (empty for server metadata)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3911 * @param array $entries Entry names array
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3912 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3913 * @return boolean True on success, False on failure
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3914 * @since 0.5-beta
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3915 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3916 public function delete_metadata($folder, $entries)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3917 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3918 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3919 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3920 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3921
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3922 $this->clear_cache('mailboxes.metadata.', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3923
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3924 if ($this->get_capability('METADATA') ||
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3925 (!strlen($folder) && $this->get_capability('METADATA-SERVER'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3926 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3927 return $this->conn->deleteMetadata($folder, $entries);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3928 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3929 else if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3930 foreach ((array)$entries as $idx => $entry) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3931 list($ent, $attr) = $this->md2annotate($entry);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3932 $entries[$idx] = array($ent, $attr, NULL);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3933 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3934 return $this->conn->setAnnotation($folder, $entries);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3935 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3936
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3937 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3938 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3939
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3940 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3941 * Returns IMAP metadata/annotations (GETMETADATA/GETANNOTATION)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3942 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3943 * @param string $folder Folder name (empty for server metadata)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3944 * @param array $entries Entries
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3945 * @param array $options Command options (with MAXSIZE and DEPTH keys)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3946 * @param bool $force Disables cache use
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3947 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3948 * @return array Metadata entry-value hash array on success, NULL on error
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3949 * @since 0.5-beta
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3950 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3951 public function get_metadata($folder, $entries, $options = array(), $force = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3952 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3953 $entries = (array) $entries;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3954
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3955 if (!$force) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3956 // create cache key
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3957 // @TODO: this is the simplest solution, but we do the same with folders list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3958 // maybe we should store data per-entry and merge on request
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3959 sort($options);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3960 sort($entries);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3961 $cache_key = 'mailboxes.metadata.' . $folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3962 $cache_key .= '.' . md5(serialize($options).serialize($entries));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3963
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3964 // get cached data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3965 $cached_data = $this->get_cache($cache_key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3966
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3967 if (is_array($cached_data)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3968 return $cached_data;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3969 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3970 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3971
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3972 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3973 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3974 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3975
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3976 if ($this->get_capability('METADATA') ||
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3977 (!strlen($folder) && $this->get_capability('METADATA-SERVER'))
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3978 ) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3979 $res = $this->conn->getMetadata($folder, $entries, $options);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3980 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3981 else if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3982 $queries = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3983 $res = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3984
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3985 // Convert entry names
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3986 foreach ($entries as $entry) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3987 list($ent, $attr) = $this->md2annotate($entry);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3988 $queries[$attr][] = $ent;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3989 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3990
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3991 // @TODO: Honor MAXSIZE and DEPTH options
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3992 foreach ($queries as $attrib => $entry) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3993 $result = $this->conn->getAnnotation($folder, $entry, $attrib);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3994
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3995 // an error, invalidate any previous getAnnotation() results
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3996 if (!is_array($result)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3997 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3998 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3999 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4000 foreach ($result as $fldr => $data) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4001 $res[$fldr] = array_merge((array) $res[$fldr], $data);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4002 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4003 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4004 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4005 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4006
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4007 if (isset($res)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4008 if (!$force) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4009 $this->update_cache($cache_key, $res);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4010 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4011
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4012 return $res;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4013 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4014 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4015
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4016 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4017 * Converts the METADATA extension entry name into the correct
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4018 * entry-attrib names for older ANNOTATEMORE version.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4019 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4020 * @param string $entry Entry name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4021 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4022 * @return array Entry-attribute list, NULL if not supported (?)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4023 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4024 protected function md2annotate($entry)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4025 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4026 if (substr($entry, 0, 7) == '/shared') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4027 return array(substr($entry, 7), 'value.shared');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4028 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4029 else if (substr($entry, 0, 8) == '/private') {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4030 return array(substr($entry, 8), 'value.priv');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4031 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4032
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4033 // @TODO: log error
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4034 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4035
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4036
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4037 /* --------------------------------
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4038 * internal caching methods
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4039 * --------------------------------*/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4040
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4041 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4042 * Enable or disable indexes caching
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4043 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4044 * @param string $type Cache type (@see rcube::get_cache)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4045 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4046 public function set_caching($type)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4047 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4048 if ($type) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4049 $this->caching = $type;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4050 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4051 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4052 if ($this->cache) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4053 $this->cache->close();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4054 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4055 $this->cache = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4056 $this->caching = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4057 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4058 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4059
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4060 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4061 * Getter for IMAP cache object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4062 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4063 protected function get_cache_engine()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4064 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4065 if ($this->caching && !$this->cache) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4066 $rcube = rcube::get_instance();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4067 $ttl = $rcube->config->get('imap_cache_ttl', '10d');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4068 $this->cache = $rcube->get_cache('IMAP', $this->caching, $ttl);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4069 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4070
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4071 return $this->cache;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4072 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4073
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4074 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4075 * Returns cached value
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4076 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4077 * @param string $key Cache key
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4078 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4079 * @return mixed
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4080 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4081 public function get_cache($key)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4082 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4083 if ($cache = $this->get_cache_engine()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4084 return $cache->get($key);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4085 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4086 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4087
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4088 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4089 * Update cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4090 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4091 * @param string $key Cache key
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4092 * @param mixed $data Data
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4093 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4094 public function update_cache($key, $data)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4095 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4096 if ($cache = $this->get_cache_engine()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4097 $cache->set($key, $data);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4098 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4099 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4100
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4101 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4102 * Clears the cache.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4103 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4104 * @param string $key Cache key name or pattern
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4105 * @param boolean $prefix_mode Enable it to clear all keys starting
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4106 * with prefix specified in $key
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4107 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4108 public function clear_cache($key = null, $prefix_mode = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4109 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4110 if ($cache = $this->get_cache_engine()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4111 $cache->remove($key, $prefix_mode);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4112 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4113 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4114
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4115
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4116 /* --------------------------------
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4117 * message caching methods
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4118 * --------------------------------*/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4119
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4120 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4121 * Enable or disable messages caching
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4122 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4123 * @param boolean $set Flag
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4124 * @param int $mode Cache mode
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4125 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4126 public function set_messages_caching($set, $mode = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4127 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4128 if ($set) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4129 $this->messages_caching = true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4130
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4131 if ($mode && ($cache = $this->get_mcache_engine())) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4132 $cache->set_mode($mode);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4133 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4134 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4135 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4136 if ($this->mcache) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4137 $this->mcache->close();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4138 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4139 $this->mcache = null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4140 $this->messages_caching = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4141 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4142 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4143
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4144 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4145 * Getter for messages cache object
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4146 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4147 protected function get_mcache_engine()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4148 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4149 if ($this->messages_caching && !$this->mcache) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4150 $rcube = rcube::get_instance();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4151 if (($dbh = $rcube->get_dbh()) && ($userid = $rcube->get_user_id())) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4152 $ttl = $rcube->config->get('messages_cache_ttl', '10d');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4153 $threshold = $rcube->config->get('messages_cache_threshold', 50);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4154 $this->mcache = new rcube_imap_cache(
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4155 $dbh, $this, $userid, $this->options['skip_deleted'], $ttl, $threshold);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4156 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4157 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4158
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4159 return $this->mcache;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4160 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4161
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4162 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4163 * Clears the messages cache.
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4164 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4165 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4166 * @param array $uids Optional message UIDs to remove from cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4167 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4168 protected function clear_message_cache($folder = null, $uids = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4169 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4170 if ($mcache = $this->get_mcache_engine()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4171 $mcache->clear($folder, $uids);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4172 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4173 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4174
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4175 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4176 * Delete outdated cache entries
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4177 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4178 function cache_gc()
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4179 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4180 rcube_imap_cache::gc();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4181 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4182
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4183
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4184 /* --------------------------------
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4185 * protected methods
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4186 * --------------------------------*/
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4187
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4188 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4189 * Validate the given input and save to local properties
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4190 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4191 * @param string $sort_field Sort column
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4192 * @param string $sort_order Sort order
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4193 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4194 protected function set_sort_order($sort_field, $sort_order)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4195 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4196 if ($sort_field != null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4197 $this->sort_field = asciiwords($sort_field);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4198 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4199 if ($sort_order != null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4200 $this->sort_order = strtoupper($sort_order) == 'DESC' ? 'DESC' : 'ASC';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4201 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4202 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4203
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4204 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4205 * Sort folders first by default folders and then in alphabethical order
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4206 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4207 * @param array $a_folders Folders list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4208 * @param bool $skip_default Skip default folders handling
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4209 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4210 * @return array Sorted list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4211 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4212 public function sort_folder_list($a_folders, $skip_default = false)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4213 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4214 $specials = array_merge(array('INBOX'), array_values($this->get_special_folders()));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4215 $folders = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4216
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4217 // convert names to UTF-8
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4218 foreach ($a_folders as $folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4219 // for better performance skip encoding conversion
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4220 // if the string does not look like UTF7-IMAP
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4221 $folders[$folder] = strpos($folder, '&') === false ? $folder : rcube_charset::convert($folder, 'UTF7-IMAP');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4222 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4223
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4224 // sort folders
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4225 // asort($folders, SORT_LOCALE_STRING) is not properly sorting case sensitive names
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4226 uasort($folders, array($this, 'sort_folder_comparator'));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4227
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4228 $folders = array_keys($folders);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4229
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4230 if ($skip_default) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4231 return $folders;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4232 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4233
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4234 // force the type of folder name variable (#1485527)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4235 $folders = array_map('strval', $folders);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4236 $out = array();
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4237
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4238 // finally we must put special folders on top and rebuild the list
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4239 // to move their subfolders where they belong...
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4240 $specials = array_unique(array_intersect($specials, $folders));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4241 $folders = array_merge($specials, array_diff($folders, $specials));
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4242
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4243 $this->sort_folder_specials(null, $folders, $specials, $out);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4244
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4245 return $out;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4246 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4247
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4248 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4249 * Recursive function to put subfolders of special folders in place
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4250 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4251 protected function sort_folder_specials($folder, &$list, &$specials, &$out)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4252 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4253 foreach ($list as $key => $name) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4254 if ($folder === null || strpos($name, $folder.$this->delimiter) === 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4255 $out[] = $name;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4256 unset($list[$key]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4257
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4258 if (!empty($specials) && ($found = array_search($name, $specials)) !== false) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4259 unset($specials[$found]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4260 $this->sort_folder_specials($name, $list, $specials, $out);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4261 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4262 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4263 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4264
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4265 reset($list);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4266 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4267
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4268 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4269 * Callback for uasort() that implements correct
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4270 * locale-aware case-sensitive sorting
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4271 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4272 protected function sort_folder_comparator($str1, $str2)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4273 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4274 if ($this->sort_folder_collator === null) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4275 $this->sort_folder_collator = false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4276
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4277 // strcoll() does not work with UTF8 locale on Windows,
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4278 // use Collator from the intl extension
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4279 if (stripos(PHP_OS, 'win') === 0 && function_exists('collator_compare')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4280 $locale = $this->options['language'] ?: 'en_US';
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4281 $this->sort_folder_collator = collator_create($locale) ?: false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4282 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4283 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4284
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4285 $path1 = explode($this->delimiter, $str1);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4286 $path2 = explode($this->delimiter, $str2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4287
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4288 foreach ($path1 as $idx => $folder1) {
17
dd5ed6ef69c9 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 16
diff changeset
4289 $folder2 = $path2[$idx]??null;
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4290
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4291 if ($folder1 === $folder2) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4292 continue;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4293 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4294
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4295 if ($this->sort_folder_collator) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4296 return collator_compare($this->sort_folder_collator, $folder1, $folder2);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4297 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4298
17
dd5ed6ef69c9 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 16
diff changeset
4299 # HST: I believe null arg used to be arbitrarily 'less' than anything
dd5ed6ef69c9 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 16
diff changeset
4300 return ($folder2 ? strcoll($folder1, $folder2) : 1);
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4301 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4302 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4303
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4304 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4305 * Find UID of the specified message sequence ID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4306 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4307 * @param int $id Message (sequence) ID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4308 * @param string $folder Folder name
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4309 *
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4310 * @return int Message UID
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4311 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4312 public function id2uid($id, $folder = null)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4313 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4314 if (!strlen($folder)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4315 $folder = $this->folder;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4316 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4317
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4318 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4319 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4320 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4321
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4322 return $this->conn->ID2UID($folder, $id);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4323 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4324
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4325 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4326 * Subscribe/unsubscribe a list of folders and update local cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4327 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4328 protected function change_subscription($folders, $mode)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4329 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4330 $updated = 0;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4331 $folders = (array) $folders;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4332
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4333 if (!empty($folders)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4334 if (!$this->check_connection()) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4335 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4336 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4337
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4338 foreach ($folders as $folder) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4339 $updated += (int) $this->conn->{$mode}($folder);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4340 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4341 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4342
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4343 // clear cached folders list(s)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4344 if ($updated) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4345 $this->clear_cache('mailboxes', true);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4346 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4347
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4348 return $updated == count($folders);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4349 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4350
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4351 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4352 * Increde/decrese messagecount for a specific folder
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4353 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4354 protected function set_messagecount($folder, $mode, $increment)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4355 {
16
1866b439e6d3 Slowly cleaning up more php8 Warnings/deprecations
Charlie Root
parents: 15
diff changeset
4356 if (!is_numeric($increment) || !$this->caching) {
0
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4357 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4358 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4359
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4360 $mode = strtoupper($mode);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4361 $a_folder_cache = $this->get_cache('messagecount');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4362
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4363 if (!is_array($a_folder_cache[$folder]) || !isset($a_folder_cache[$folder][$mode])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4364 return false;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4365 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4366
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4367 // add incremental value to messagecount
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4368 $a_folder_cache[$folder][$mode] += $increment;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4369
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4370 // there's something wrong, delete from cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4371 if ($a_folder_cache[$folder][$mode] < 0) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4372 unset($a_folder_cache[$folder][$mode]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4373 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4374
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4375 // write back to cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4376 $this->update_cache('messagecount', $a_folder_cache);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4377
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4378 return true;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4379 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4380
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4381 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4382 * Remove messagecount of a specific folder from cache
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4383 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4384 protected function clear_messagecount($folder, $mode = array())
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4385 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4386 $a_folder_cache = $this->get_cache('messagecount');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4387
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4388 if (is_array($a_folder_cache[$folder])) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4389 if (!empty($mode)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4390 foreach ((array) $mode as $key) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4391 unset($a_folder_cache[$folder][$key]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4392 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4393 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4394 else {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4395 unset($a_folder_cache[$folder]);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4396 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4397 $this->update_cache('messagecount', $a_folder_cache);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4398 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4399 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4400
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4401 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4402 * Converts date string/object into IMAP date/time format
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4403 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4404 protected function date_format($date)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4405 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4406 if (empty($date)) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4407 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4408 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4409
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4410 if (!is_object($date) || !is_a($date, 'DateTime')) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4411 try {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4412 $timestamp = rcube_utils::strtotime($date);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4413 $date = new DateTime("@".$timestamp);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4414 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4415 catch (Exception $e) {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4416 return null;
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4417 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4418 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4419
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4420 return $date->format('d-M-Y H:i:s O');
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4421 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4422
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4423 /**
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4424 * This is our own debug handler for the IMAP connection
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4425 */
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4426 public function debug_handler(&$imap, $message)
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4427 {
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4428 rcube::write_log('imap', $message);
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4429 }
4681f974d28b vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4430 }