-
Notifications
You must be signed in to change notification settings - Fork 33
/
Base.php
4081 lines (3653 loc) · 145 KB
/
Base.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Copyright 2008-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2008-2017 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/
/**
* An abstracted API interface to IMAP backends supporting the IMAP4rev1
* protocol (RFC 3501).
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2008-2017 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*
* @property-read Horde_Imap_Client_Base_Alert $alerts_ob
The alert reporting object (@since 2.26.0)
* @property-read Horde_Imap_Client_Data_Capability $capability
* A capability object. (@since 2.24.0)
* @property-read Horde_Imap_Client_Data_SearchCharset $search_charset
* A search charset object. (@since 2.24.0)
* @property-read Horde_Imap_Client_Url $url The URL object for the current
* connection parameters (@since 2.24.0)
*/
abstract class Horde_Imap_Client_Base
implements Serializable, SplObserver
{
/** Serialized version. */
const VERSION = 3;
/** Cache names for miscellaneous data. */
const CACHE_MODSEQ = '_m';
const CACHE_SEARCH = '_s';
/* @since 2.9.0 */
const CACHE_SEARCHID = '_i';
/** Cache names used exclusively within this class. @since 2.11.0 */
const CACHE_DOWNGRADED = 'HICdg';
/**
* The list of fetch fields that can be cached, and their cache names.
*
* @var array
*/
public $cacheFields = array(
Horde_Imap_Client::FETCH_ENVELOPE => 'HICenv',
Horde_Imap_Client::FETCH_FLAGS => 'HICflags',
Horde_Imap_Client::FETCH_HEADERS => 'HIChdrs',
Horde_Imap_Client::FETCH_IMAPDATE => 'HICdate',
Horde_Imap_Client::FETCH_SIZE => 'HICsize',
Horde_Imap_Client::FETCH_STRUCTURE => 'HICstruct'
);
/**
* Has the internal configuration changed?
*
* @var boolean
*/
public $changed = false;
/**
* Horde_Imap_Client is optimized for short (i.e. 1 seconds) scripts. It
* makes heavy use of mailbox caching to save on server accesses. This
* property should be set to false for long-running scripts, or else
* status() data may not reflect the current state of the mailbox on the
* server.
*
* @since 2.14.0
*
* @var boolean
*/
public $statuscache = true;
/**
* Alerts reporting object.
*
* @var Horde_Imap_Client_Base_Alerts
*/
protected $_alerts;
/**
* The Horde_Imap_Client_Cache object.
*
* @var Horde_Imap_Client_Cache
*/
protected $_cache = null;
/**
* Connection to the IMAP server.
*
* @var Horde\Socket\Client
*/
protected $_connection = null;
/**
* The debug object.
*
* @var Horde_Imap_Client_Base_Debug
*/
protected $_debug = null;
/**
* The default ports to use for a connection.
* First element is non-secure, second is SSL.
*
* @var array
*/
protected $_defaultPorts = array();
/**
* The fetch data object type to return.
*
* @var string
*/
protected $_fetchDataClass = 'Horde_Imap_Client_Data_Fetch';
/**
* Cached server data.
*
* @var array
*/
protected $_init;
/**
* Is there an active authenticated connection to the IMAP Server?
*
* @var boolean
*/
protected $_isAuthenticated = false;
/**
* The current mailbox selection mode.
*
* @var integer
*/
protected $_mode = 0;
/**
* Hash containing connection parameters.
* This hash never changes.
*
* @var array
*/
protected $_params = array();
/**
* The currently selected mailbox.
*
* @var Horde_Imap_Client_Mailbox
*/
protected $_selected = null;
/**
* Temp array (destroyed at end of process).
*
* @var array
*/
protected $_temp = array();
/**
* Constructor.
*
* @param array $params Configuration parameters:
* <pre>
* - cache: (array) If set, caches data from fetch(), search(), and
* thread() calls. Requires the horde/Cache package to be
* installed. The array can contain the following keys (see
* Horde_Imap_Client_Cache for default values):
* - backend: [REQUIRED (or cacheob)] (Horde_Imap_Client_Cache_Backend)
* Backend cache driver [@since 2.9.0].
* - fetch_ignore: (array) A list of mailboxes to ignore when storing
* fetch data.
* - fields: (array) The fetch criteria to cache. If not defined, all
* cacheable data is cached. The following is a list of
* criteria that can be cached:
* - Horde_Imap_Client::FETCH_ENVELOPE
* - Horde_Imap_Client::FETCH_FLAGS
* Only if server supports CONDSTORE extension
* - Horde_Imap_Client::FETCH_HEADERS
* Only for queries that specifically request caching
* - Horde_Imap_Client::FETCH_IMAPDATE
* - Horde_Imap_Client::FETCH_SIZE
* - Horde_Imap_Client::FETCH_STRUCTURE
* - capability_ignore: (array) A list of IMAP capabilites to ignore, even
* if they are supported on the server.
* DEFAULT: No supported capabilities are ignored.
* - comparator: (string) The search comparator to use instead of the
* default server comparator. See setComparator() for
* format.
* DEFAULT: Use the server default
* - context: (array) Any context parameters passed to
* stream_create_context(). @since 2.27.0
* - debug: (string) If set, will output debug information to the stream
* provided. The value can be any PHP supported wrapper that can
* be opened via PHP's fopen() function.
* DEFAULT: No debug output
* - hostspec: (string) The hostname or IP address of the server.
* DEFAULT: 'localhost'
* - id: (array) Send ID information to the server (only if server
* supports the ID extension). An array with the keys as the fields
* to send and the values being the associated values. See RFC 2971
* [3.3] for a list of standard field values.
* DEFAULT: No info sent to server
* - lang: (array) A list of languages (in priority order) to be used to
* display human readable messages.
* DEFAULT: Messages output in IMAP server default language
* - password: (mixed) The user password. Either a string or a
* Horde_Imap_Client_Base_Password object [@since 2.14.0].
* - port: (integer) The server port to which we will connect.
* DEFAULT: 143 (imap or imap w/TLS) or 993 (imaps)
* - secure: (string) Use SSL or TLS to connect. Values:
* - false (No encryption)
* - 'ssl' (Auto-detect SSL version)
* - 'sslv2' (Force SSL version 3)
* - 'sslv3' (Force SSL version 2)
* - 'tls' (TLS; started via protocol-level negotation over
* unencrypted channel; RECOMMENDED way of initiating secure
* connection)
* - 'tlsv1' (TLS direct version 1.x connection to server) [@since
* 2.16.0]
* - true (TLS if available/necessary) [@since 2.15.0]
* DEFAULT: false
* - timeout: (integer) Connection timeout, in seconds.
* DEFAULT: 30 seconds
* - username: (string) [REQUIRED] The username.
* - authusername (string) The username used for SASL authentication.
* If specified this is the user name whose password is used
* (e.g. administrator).
* Only valid for RFC 2595/4616 - PLAIN SASL mechanism.
* DEFAULT: the same value provided in the username parameter.
* </pre>
*/
public function __construct(array $params = array())
{
if (!isset($params['username'])) {
throw new InvalidArgumentException('Horde_Imap_Client requires a username.');
}
$this->_setInit();
// Default values.
$params = array_merge(array(
'context' => array(),
'hostspec' => 'localhost',
'secure' => false,
'timeout' => 30
), array_filter($params));
if (!isset($params['port']) && strpos($params['hostspec'], 'unix://') !== 0) {
$params['port'] = (!empty($params['secure']) && in_array($params['secure'], array('ssl', 'sslv2', 'sslv3'), true))
? $this->_defaultPorts[1]
: $this->_defaultPorts[0];
}
if (empty($params['cache'])) {
$params['cache'] = array('fields' => array());
} elseif (empty($params['cache']['fields'])) {
$params['cache']['fields'] = $this->cacheFields;
} else {
$params['cache']['fields'] = array_flip($params['cache']['fields']);
}
if (empty($params['cache']['fetch_ignore'])) {
$params['cache']['fetch_ignore'] = array();
}
$this->_params = $params;
if (isset($params['password'])) {
$this->setParam('password', $params['password']);
}
$this->changed = true;
$this->_initOb();
}
/**
* Get encryption key.
*
* @deprecated Pass callable into 'password' parameter instead.
*
* @return string The encryption key.
*/
protected function _getEncryptKey()
{
if (is_callable($ekey = $this->getParam('encryptKey'))) {
return call_user_func($ekey);
}
throw new InvalidArgumentException('encryptKey parameter is not a valid callback.');
}
/**
* Do initialization tasks.
*/
protected function _initOb()
{
register_shutdown_function(array($this, 'shutdown'));
$this->_alerts = new Horde_Imap_Client_Base_Alerts();
// @todo: Remove (BC)
$this->_alerts->attach($this);
$this->_debug = ($debug = $this->getParam('debug'))
? new Horde_Imap_Client_Base_Debug($debug)
: new Horde_Support_Stub();
// @todo: Remove (BC purposes)
if (isset($this->_init['capability']) &&
!is_object($this->_init['capability'])) {
$this->_setInit('capability');
}
foreach (array('capability', 'search_charset') as $val) {
if (isset($this->_init[$val])) {
$this->_init[$val]->attach($this);
}
}
}
/**
* Shutdown actions.
*/
public function shutdown()
{
try {
$this->logout();
} catch (Horde_Imap_Client_Exception $e) {
}
}
/**
* This object can not be cloned.
*/
public function __clone()
{
throw new LogicException('Object cannot be cloned.');
}
/**
*/
public function update(SplSubject $subject)
{
if (($subject instanceof Horde_Imap_Client_Data_Capability) ||
($subject instanceof Horde_Imap_Client_Data_SearchCharset)) {
$this->changed = true;
}
/* @todo: BC - remove */
if ($subject instanceof Horde_Imap_Client_Base_Alerts) {
$this->_temp['alerts'][] = $subject->getLast()->alert;
}
}
/**
*/
public function serialize()
{
return serialize(array(
'i' => $this->_init,
'p' => $this->_params,
'v' => self::VERSION
));
}
/**
*/
public function unserialize($data)
{
$data = @unserialize($data);
if (!is_array($data) ||
!isset($data['v']) ||
($data['v'] != self::VERSION)) {
throw new Exception('Cache version change');
}
$this->_init = $data['i'];
$this->_params = $data['p'];
$this->_initOb();
}
/**
*/
public function __get($name)
{
switch ($name) {
case 'alerts_ob':
return $this->_alerts;
case 'capability':
return $this->_capability();
case 'search_charset':
if (!isset($this->_init['search_charset'])) {
$this->_init['search_charset'] = new Horde_Imap_Client_Data_SearchCharset();
$this->_init['search_charset']->attach($this);
}
$this->_init['search_charset']->setBaseOb($this);
return $this->_init['search_charset'];
case 'url':
$url = new Horde_Imap_Client_Url();
$url->hostspec = $this->getParam('hostspec');
$url->port = $this->getParam('port');
$url->protocol = 'imap';
return $url;
}
}
/**
* Set an initialization value.
*
* @param string $key The initialization key. If null, resets all keys.
* @param mixed $val The cached value. If null, removes the key.
*/
public function _setInit($key = null, $val = null)
{
if (is_null($key)) {
$this->_init = array();
} elseif (is_null($val)) {
unset($this->_init[$key]);
} else {
switch ($key) {
case 'capability':
if ($ci = $this->getParam('capability_ignore')) {
$ignored = array();
foreach ($ci as $val2) {
$c = explode('=', $val2);
if ($val->query($c[0], isset($c[1]) ? $c[1] : null)) {
$ignored[] = $val2;
$val->remove($c[0], isset($c[1]) ? $c[1] : null);
}
}
if ($this->_debug->debug && !empty($ignored)) {
$this->_debug->info(sprintf(
'CONFIG: IGNORING these IMAP capabilities: %s',
implode(', ', $ignored)
));
}
}
$val->attach($this);
break;
}
/* Nothing has changed. */
if (isset($this->_init[$key]) && ($this->_init[$key] === $val)) {
return;
}
$this->_init[$key] = $val;
}
$this->changed = true;
}
/**
* Initialize the Horde_Imap_Client_Cache object, if necessary.
*
* @param boolean $current If true, we are going to update the currently
* selected mailbox. Add an additional check to
* see if caching is available in current
* mailbox.
*
* @return boolean Returns true if caching is enabled.
*/
protected function _initCache($current = false)
{
$c = $this->getParam('cache');
if (empty($c['fields'])) {
return false;
}
if (is_null($this->_cache)) {
if (isset($c['backend'])) {
$backend = $c['backend'];
} elseif (isset($c['cacheob'])) {
/* Deprecated */
$backend = new Horde_Imap_Client_Cache_Backend_Cache($c);
} else {
return false;
}
$this->_cache = new Horde_Imap_Client_Cache(array(
'backend' => $backend,
'baseob' => $this,
'debug' => $this->_debug
));
}
return $current
/* If UIDs are labeled as not sticky, don't cache since UIDs will
* change on every access. */
? !($this->_mailboxOb()->getStatus(Horde_Imap_Client::STATUS_UIDNOTSTICKY))
: true;
}
/**
* Returns a value from the internal params array.
*
* @param string $key The param key.
*
* @return mixed The param value, or null if not found.
*/
public function getParam($key)
{
/* Passwords may be stored encrypted. */
switch ($key) {
case 'password':
if (isset($this->_params[$key]) &&
($this->_params[$key] instanceof Horde_Imap_Client_Base_Password)) {
return $this->_params[$key]->getPassword();
}
// DEPRECATED
if (!empty($this->_params['_passencrypt'])) {
try {
$secret = new Horde_Secret();
return $secret->read($this->_getEncryptKey(), $this->_params['password']);
} catch (Exception $e) {
return null;
}
}
break;
}
return isset($this->_params[$key])
? $this->_params[$key]
: null;
}
/**
* Sets a configuration parameter value.
*
* @param string $key The param key.
* @param mixed $val The param value.
*/
public function setParam($key, $val)
{
switch ($key) {
case 'password':
if ($val instanceof Horde_Imap_Client_Base_Password) {
break;
}
// DEPRECATED: Encrypt password.
try {
$encrypt_key = $this->_getEncryptKey();
if (strlen($encrypt_key)) {
$secret = new Horde_Secret();
$val = $secret->write($encrypt_key, $val);
$this->_params['_passencrypt'] = true;
}
} catch (Exception $e) {}
break;
}
$this->_params[$key] = $val;
$this->changed = true;
}
/**
* Returns the Horde_Imap_Client_Cache object used, if available.
*
* @return mixed Either the cache object or null.
*/
public function getCache()
{
$this->_initCache();
return $this->_cache;
}
/**
* Returns the correct IDs object for use with this driver.
*
* @param mixed $ids Either self::ALL, self::SEARCH_RES, self::LARGEST,
* Horde_Imap_Client_Ids object, array, or sequence
* string.
* @param boolean $sequence Are $ids message sequence numbers?
*
* @return Horde_Imap_Client_Ids The IDs object.
*/
public function getIdsOb($ids = null, $sequence = false)
{
return new Horde_Imap_Client_Ids($ids, $sequence);
}
/**
* Returns whether the IMAP server supports the given capability
* (See RFC 3501 [6.1.1]).
*
* @deprecated Use $capability property instead.
*
* @param string $capability The capability string to query.
*
* @return mixed True if the server supports the queried capability,
* false if it doesn't, or an array if the capability can
* contain multiple values.
*/
public function queryCapability($capability)
{
try {
$c = $this->_capability();
return ($out = $c->getParams($capability))
? $out
: $c->query($capability);
} catch (Horde_Imap_Client_Exception $e) {
return false;
}
}
/**
* Get CAPABILITY information from the IMAP server.
*
* @deprecated Use $capability property instead.
*
* @return array The capability array.
*
* @throws Horde_Imap_Client_Exception
*/
public function capability()
{
return $this->_capability()->toArray();
}
/**
* Query server capability.
*
* Required because internal code can't call capability via magic method
* directly - it may not exist yet, the creation code may call capability
* recursively, and __get() doesn't allow recursive calls to the same
* property (chicken/egg issue).
*
* @return mixed The capability object if no arguments provided. If
* arguments are provided, they are passed to the query()
* method and this value is returned.
* @throws Horde_Imap_Client_Exception
*/
protected function _capability()
{
if (!isset($this->_init['capability'])) {
$this->_initCapability();
}
return ($args = func_num_args())
? $this->_init['capability']->query(func_get_arg(0), ($args > 1) ? func_get_arg(1) : null)
: $this->_init['capability'];
}
/**
* Retrieve capability information from the IMAP server.
*
* @throws Horde_Imap_Client_Exception
*/
abstract protected function _initCapability();
/**
* Send a NOOP command (RFC 3501 [6.1.2]).
*
* @throws Horde_Imap_Client_Exception
*/
public function noop()
{
if (!$this->_connection) {
// NOOP can be called in the unauthenticated state.
$this->_connect();
}
$this->_noop();
}
/**
* Send a NOOP command.
*
* @throws Horde_Imap_Client_Exception
*/
abstract protected function _noop();
/**
* Get the NAMESPACE information from the IMAP server (RFC 2342).
*
* @param array $additional If the server supports namespaces, any
* additional namespaces to add to the
* namespace list that are not broadcast by
* the server. The namespaces must be UTF-8
* strings.
* @param array $opts Additional options:
* - ob_return: (boolean) If true, returns a
* Horde_Imap_Client_Namespace_List object instead of an
* array.
*
* @return mixed A Horde_Imap_Client_Namespace_List object if
* 'ob_return', is true. Otherwise, an array of namespace
* objects (@deprecated) with the name as the key (UTF-8)
* and the following values:
* <pre>
* - delimiter: (string) The namespace delimiter.
* - hidden: (boolean) Is this a hidden namespace?
* - name: (string) The namespace name (UTF-8).
* - translation: (string) Returns the translated name of the namespace
* (UTF-8). Requires RFC 5255 and a previous call to
* setLanguage().
* - type: (integer) The namespace type. Either:
* - Horde_Imap_Client::NS_PERSONAL
* - Horde_Imap_Client::NS_OTHER
* - Horde_Imap_Client::NS_SHARED
* </pre>
*
* @throws Horde_Imap_Client_Exception
*/
public function getNamespaces(
array $additional = array(), array $opts = array()
)
{
$additional = array_map('strval', $additional);
$sig = hash(
'md5',
json_encode($additional) . intval(empty($opts['ob_return']))
);
if (isset($this->_init['namespace'][$sig])) {
$ns = $this->_init['namespace'][$sig];
} else {
$this->login();
$ns = $this->_getNamespaces();
/* Skip namespaces if we have already auto-detected them. Also,
* hidden namespaces cannot be empty. */
$to_process = array_diff(array_filter($additional, 'strlen'), array_map('strlen', iterator_to_array($ns)));
if (!empty($to_process)) {
foreach ($this->listMailboxes($to_process, Horde_Imap_Client::MBOX_ALL, array('delimiter' => true)) as $key => $val) {
$ob = new Horde_Imap_Client_Data_Namespace();
$ob->delimiter = $val['delimiter'];
$ob->hidden = true;
$ob->name = $key;
$ob->type = $ob::NS_SHARED;
$ns[$val] = $ob;
}
}
if (!count($ns)) {
/* This accurately determines the namespace information of the
* base namespace if the NAMESPACE command is not supported.
* See: RFC 3501 [6.3.8] */
$mbox = $this->listMailboxes('', Horde_Imap_Client::MBOX_ALL, array('delimiter' => true));
$first = reset($mbox);
$ob = new Horde_Imap_Client_Data_Namespace();
$ob->delimiter = $first['delimiter'];
$ns[''] = $ob;
}
$this->_init['namespace'][$sig] = $ns;
$this->_setInit('namespace', $this->_init['namespace']);
}
if (!empty($opts['ob_return'])) {
return $ns;
}
/* @todo Remove for 3.0 */
$out = array();
foreach ($ns as $key => $val) {
$out[$key] = array(
'delimiter' => $val->delimiter,
'hidden' => $val->hidden,
'name' => $val->name,
'translation' => $val->translation,
'type' => $val->type
);
}
return $out;
}
/**
* Get the NAMESPACE information from the IMAP server.
*
* @return Horde_Imap_Client_Namespace_List Namespace list object.
*
* @throws Horde_Imap_Client_Exception
*/
abstract protected function _getNamespaces();
/**
* Display if connection to the server has been secured via TLS or SSL.
*
* @return boolean True if the IMAP connection is secured.
*/
public function isSecureConnection()
{
return ($this->_connection && $this->_connection->secure);
}
/**
* Connect to the remote server.
*
* @throws Horde_Imap_Client_Exception
*/
abstract protected function _connect();
/**
* Return a list of alerts that MUST be presented to the user (RFC 3501
* [7.1]).
*
* @deprecated Add an observer to the $alerts_ob property instead.
*
* @return array An array of alert messages.
*/
public function alerts()
{
$alerts = isset($this->_temp['alerts'])
? $this->_temp['alerts']
: array();
unset($this->_temp['alerts']);
return $alerts;
}
/**
* Login to the IMAP server.
*
* @throws Horde_Imap_Client_Exception
*/
public function login()
{
if (!$this->_isAuthenticated && $this->_login()) {
if ($this->getParam('id')) {
try {
$this->sendID();
/* ID is queued - force sending the queued command. */
$this->_sendCmd($this->_pipeline());
} catch (Horde_Imap_Client_Exception_NoSupportExtension $e) {
// Ignore if server doesn't support ID extension.
}
}
if ($this->getParam('comparator')) {
try {
$this->setComparator();
} catch (Horde_Imap_Client_Exception_NoSupportExtension $e) {
// Ignore if server doesn't support I18NLEVEL=2
}
}
}
$this->_isAuthenticated = true;
}
/**
* Login to the IMAP server.
*
* @return boolean Return true if global login tasks should be run.
*
* @throws Horde_Imap_Client_Exception
*/
abstract protected function _login();
/**
* Logout from the IMAP server (see RFC 3501 [6.1.3]).
*/
public function logout()
{
if ($this->_isAuthenticated && $this->_connection->connected) {
$this->_logout();
$this->_connection->close();
}
$this->_connection = $this->_selected = null;
$this->_isAuthenticated = false;
$this->_mode = 0;
}
/**
* Logout from the IMAP server (see RFC 3501 [6.1.3]).
*/
abstract protected function _logout();
/**
* Send ID information to the IMAP server (RFC 2971).
*
* @param array $info Overrides the value of the 'id' param and sends
* this information instead.
*
* @throws Horde_Imap_Client_Exception
* @throws Horde_Imap_Client_Exception_NoSupportExtension
*/
public function sendID($info = null)
{
if (!$this->_capability('ID')) {
throw new Horde_Imap_Client_Exception_NoSupportExtension('ID');
}
$this->_sendID(is_null($info) ? ($this->getParam('id') ?: array()) : $info);
}
/**
* Send ID information to the IMAP server (RFC 2971).
*
* @param array $info The information to send to the server.
*
* @throws Horde_Imap_Client_Exception
*/
abstract protected function _sendID($info);
/**
* Return ID information from the IMAP server (RFC 2971).
*
* @return array An array of information returned, with the keys as the
* 'field' and the values as the 'value'.
*
* @throws Horde_Imap_Client_Exception
* @throws Horde_Imap_Client_Exception_NoSupportExtension
*/
public function getID()
{
if (!$this->_capability('ID')) {
throw new Horde_Imap_Client_Exception_NoSupportExtension('ID');
}
return $this->_getID();
}
/**
* Return ID information from the IMAP server (RFC 2971).
*
* @return array An array of information returned, with the keys as the
* 'field' and the values as the 'value'.
*
* @throws Horde_Imap_Client_Exception
*/
abstract protected function _getID();
/**
* Sets the preferred language for server response messages (RFC 5255).
*
* @param array $langs Overrides the value of the 'lang' param and sends
* this list of preferred languages instead. The
* special string 'i-default' can be used to restore
* the language to the server default.
*
* @return string The language accepted by the server, or null if the
* default language is used.
*
* @throws Horde_Imap_Client_Exception
*/
public function setLanguage($langs = null)
{
$lang = null;
if ($this->_capability('LANGUAGE')) {
$lang = is_null($langs)
? $this->getParam('lang')
: $langs;
}
return is_null($lang)
? null
: $this->_setLanguage($lang);
}
/**
* Sets the preferred language for server response messages (RFC 5255).
*
* @param array $langs The preferred list of languages.
*
* @return string The language accepted by the server, or null if the
* default language is used.
*
* @throws Horde_Imap_Client_Exception
*/
abstract protected function _setLanguage($langs);
/**
* Gets the preferred language for server response messages (RFC 5255).
*
* @param array $list If true, return the list of available languages.
*
* @return mixed If $list is true, the list of languages available on the
* server (may be empty). If false, the language used by
* the server, or null if the default language is used.
*
* @throws Horde_Imap_Client_Exception
*/
public function getLanguage($list = false)
{
if (!$this->_capability('LANGUAGE')) {
return $list ? array() : null;
}