/
Connector.php
1456 lines (1340 loc) · 52.3 KB
/
Connector.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 2010-2016 Horde LLC (http://www.horde.org/)
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @package Core
*/
/**
* Registry connector for Horde backend.
*
* Provides the communication between the Horde Registry on the local machine
* and the ActiveSync Horde driver.
*
* @copyright 2010-2016 Horde LLC (http://www.horde.org/)
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @package Core
*/
class Horde_Core_ActiveSync_Connector
{
/**
* Horde registry
*
* @var Horde_Registry
*/
protected $_registry;
/**
* The logger
*
* @var Horde_Log_Logger
*/
protected $_logger;
/**
* Cache the GAL to avoid hitting the contacts API multiple times.
*
* @var string
*/
protected $_gal;
/**
* Cache results of capability queries
*
* @var array
*/
protected $_capabilities = array();
/**
* Cache list of folders
*
* @var array
*/
protected $_folderCache = array();
/**
* Const'r
*
* @param array $params Configuration parameters. Requires:
* - registry: An instance of Horde_Registry
*
* @return Horde_ActiveSync_Driver_Horde_Connector_Registry
* @throws InvalidArgumentException
*/
public function __construct($params = array())
{
if (empty($params['registry'])) {
throw new InvalidArgumentException('Missing required Horde_Registry object.');
}
$this->_registry = $params['registry'];
}
/**
* Set a logger for this object.
*
* @var Horde_Log_Logger $logger The logger.
*/
public function setLogger($logger)
{
$this->_logger = $logger;
}
/**
* Get a list of events from horde's calendar api
*
* @param integer $startstamp The start of time period.
* @param integer $endstamp The end of time period
* @param string $calendar The calendar id. If null, uses multiplexed.
* @since 2.12.0
*
* @return array
*/
public function calendar_listUids($startstamp, $endstamp, $calendar)
{
try {
return $this->_registry->calendar->listUids($calendar, $startstamp, $endstamp);
} catch (Exception $e) {
return array();
}
}
/**
* Export the specified event as an ActiveSync message
*
* @param string $uid The calendar id.
* @param array $options Options to pass to the backend exporter.
* - protocolversion: (float) The EAS version to support
* DEFAULT: 2.5
* - bodyprefs: (array) A BODYPREFERENCE array.
* DEFAULT: none (No body prefs enforced).
* - truncation: (integer) Truncate event body to this length
* DEFAULT: none (No truncation).
*
* @param string $calendar The calendar id. If null, uses multiplexed.
* @since 2.12.0
*
* @return Horde_ActiveSync_Message_Appointment The requested event.
*/
public function calendar_export($uid, array $options = array(), $calendar = null)
{
$calendar = empty($calendar) ? null : array($calendar);
return $this->_registry->calendar->export($uid, 'activesync', $options, $calendar);
}
/**
* Import an event into the user's default calendar.
*
* @param Horde_ActiveSync_Message_Appointment $content The event content
* @param string $calendar The calendar id.
* @since 2.12.0
*
* @return string The event's UID.
*/
public function calendar_import(
Horde_ActiveSync_Message_Appointment $content, $calendar = null)
{
return $this->_registry->calendar->import(
$content, 'activesync', $calendar);
}
/**
* Version of calendar_import capable of returning an array of values.
* Needed for EAS 16 support in order to deal with the fact that
* attachment actions are handled within the Message object.
*
* @param Horde_ActiveSync_Message_Appointment $content The event content
* @param string $calendar The calendar id.
*
* @return array
* @since 2.27.0
* @todo Remove for H6 and make calendar_import return this structure.
*/
public function calendar_import16(
Horde_ActiveSync_Message_Appointment $content, $calendar = null)
{
$result = $this->_registry->calendar->import(
$content, 'activesync', $calendar, true);
if (!is_array($result)) {
$result = array(
'uid' => $result,
'atchash' => false
);
}
return $result;
}
/**
* Import a Horde_Icalendar_vEvent into a user's calendar. Used for creating
* events from meeting invitations.
*
* @param Horde_Icalendar_vEvent $vEvent The event data.
*
* @return string The event's UID.
*/
public function calendar_import_vevent(Horde_Icalendar_vEvent $vEvent)
{
return $this->_registry->calendar->import($vEvent, 'text/calendar');
}
/**
* Import an event response into a user's calendar. Used for updating
* attendee information from a meeting response.
*
* @param Horde_Icalendar_vEvent $vEvent The event data.
* @param string $attendee The attendee.
*/
public function calendar_import_attendee(Horde_Icalendar_vEvent $vEvent,
$attendee)
{
if ($this->_registry->hasMethod('calendar/updateAttendee')) {
// If the mail interface (i.e., IMP) provides a mime driver for
// iTips, check if we are allowed to autoupdate. If we have no
// configuration, err on the side of caution and DO NOT auto import.
$config = $GLOBALS['injector']
->getInstance('Horde_Core_Factory_MimeViewer')
->getViewerConfig('text/calendar', $this->_registry->hasInterface('mail'));
if ($config[1]['driver'] == 'Itip' && !empty($config[1]['auto_update_eventreply'])) {
if (is_array($config[1]['auto_update_eventreply'])) {
$adr = new Horde_Mail_Rfc822_Address($attendee);
$have_match = false;
foreach ($config[1]['auto_update_eventreply'] as $val) {
if ($adr->matchDomain($val)) {
$have_match = true;
break;
}
}
if (!$have_match) {
return;
}
}
try {
$this->_registry->calendar->updateAttendee($vEvent, $attendee);
} catch (Horde_Exception $e) {
$this->_logger->err($e->getMessage());
}
}
}
}
/**
* Replace the event with new data
*
* @param string $uid The UID of the event to replace.
* @param Horde_ActiveSync_Message_Appointment $content
* The new event.
* @param string $calendar The calendar id. @since 2.12.0
*
* @return null|array May return an array of 'uid' and 'atchash' or null.
*/
public function calendar_replace($uid, Horde_ActiveSync_Message_Appointment $content, $calendar = null)
{
return $this->_registry->calendar->replace($uid, $content, 'activesync', $calendar);
}
/**
* Delete an event from Horde's calendar storage
*
* @param string $uid The UID of the event to delete
* @param string $calendar The calendar id. @since 2.12.0 @deprecated (Not used).
* @param string $instanceid The instanceid if this is a EAS 16.0 instance.
* @since 2.23.0
*/
public function calendar_delete($uid, $calendar = null, $instanceid = null)
{
if ($instanceid) {
$instanceid = new Horde_Date($instanceid, 'UTC');
}
$this->_registry->calendar->delete($uid, $instanceid, null);
}
/**
* Return the timestamp for the last time $action was performed.
*
* @param string $uid The UID of the event we are interested in.
* @param string $action The action we are interested in (add, modify...).
* @param string $calendar The calendar id, if not using multiplexed data.
*
* @return integer
*/
public function calendar_getActionTimestamp($uid, $action, $calendar = null)
{
return $this->_registry->calendar->getActionTimestamp(
$uid, $action, $calendar, $this->hasFeature('modseq', 'calendar'));
}
/**
* Move a calendar event.
*
* @param string $uid The event UID.
* @param string $source The source calendar's id.
* @param string $target The target calendar's id.
*
* @return string|boolean The UID if successfully moved otherwise false.
* @since 2.15.0
*/
public function calendar_move($uid, $source, $target)
{
if (!$this->_registry->hasMethod('move', $this->_registry->hasInterface('calendar'))) {
return false;
}
try {
$this->_registry->calendar->move($uid, $source, $target);
} catch (Horde_Exception $e) {
return false;
}
return $uid;
}
/**
* Get a list of all contacts a user can see
*
* @param string $source The source to list. If null, use multiplex.
* @since 2.12.0
*
* @return array An array of contact UIDs
*/
public function contacts_listUids($source = null)
{
return $this->_registry->contacts->listUids($source);
}
/**
* Export the specified contact from Horde's contacts storage
*
* @param string $uid The contact's UID
* @param array $options Exporter options:
* - protocolversion: (float) The EAS version to support
* DEFAULT: 2.5
* - bodyprefs: (array) A BODYPREFERENCE array.
* DEFAULT: none (No body prefs enforced).
* - truncation: (integer) Truncate event body to this length
* DEFAULT: none (No truncation).
* - device: (Horde_ActiveSync_Device) The device object.
*
* @return Horde_ActiveSync_Message_Contact The contact object.
*/
public function contacts_export($uid, array $options = array())
{
return $this->_registry->contacts->export($uid, 'activesync', null, null, $options);
}
/**
* Import the provided contact data into Horde's contacts storage
*
* @param Horde_ActiveSync_Message_Contact $content The contact data
* @param string $addressbook The addessbook id.
* @since 2.12.0
*
* @return mixed string|boolean The new UID or false on failure.
*/
public function contacts_import(Horde_ActiveSync_Message_Contact $content, $addressbook = null)
{
return $this->_registry->contacts->import($content, 'activesync', $addressbook);
}
/**
* Replace the specified contact with the data provided.
*
* @param string $uid The UID of the contact to replace
* @param string $content The contact data
*/
public function contacts_replace($uid, $content)
{
$this->_registry->contacts->replace($uid, $content, 'activesync');
}
/**
* Delete the specified contact
*
* @param string|array $uid The UID(s) of the contact(s) to remove.
*
* @return boolean
*/
public function contacts_delete($uid)
{
return $this->_registry->contacts->delete($uid);
}
/**
* Get the timestamp of the most recent occurance of $action for the
* specifed contact
*
* @param string $uid The UID of the contact to search.
* @param string $action The action to lookup.
* @param string $addressbook The addressbook id, if not using multiplex.
*
* @return integer
*/
public function contacts_getActionTimestamp($uid, $action, $addressbook = null)
{
return $this->_registry->contacts->getActionTimestamp(
$uid, $action, $addressbook, $this->hasFeature('modseq', 'contacts'));
}
/**
* Returns the favouriteRecipients data for RI requests.
*
* @param integer $max The maximum number of recipients to return.
*
* @return array An array of email addresses.
*/
public function getRecipientCache($max = 100)
{
if (!$this->_registry->hasInterface('mail') ||
!$this->_registry->hasInterface('contacts')) {
return array();
}
$cache = $GLOBALS['injector']->getInstance('Horde_Cache');
$cache_key = 'HCASC:' . $this->_registry->getAuth() . ':' . $max;
if (!$cache->exists($cache_key, 3600)) {
$results = $this->_registry->mail->favouriteRecipients($max);
$cache->set($cache_key, json_encode($results));
} else {
$results = json_decode($cache->get($cache_key, 3600), true);
}
return $results;
}
/**
* Search the contacts store.
*
* @param string $query The search string.
* @param array $options Additional options:
* - pictures: (boolean) Include photos in results.
* DEFAULT: false (Do not include photos).
* - recipient_cache_search: (boolean) If true, this is a RI cache search,
* should only search the 'email' field and only return a small subset
* of fields.
*
* @return array The search results.
*/
public function contacts_search($query, array $options = array())
{
if ((!$gal = $this->contacts_getGal()) && empty($options['recipient_cache_search'])) {
return array();
}
if (!empty($options['recipient_cache_search'])) {
$sources = array_keys($this->_registry->contacts->sources(false, true));
$return_fields = array('name', 'alias', 'email');
foreach ($sources as $source) {
$fields[$source] = array('email');
}
} else {
$sources = array($gal);
$fields = array();
$return_fields = array('name', 'alias', 'email', 'firstname', 'lastname',
'company', 'homePhone', 'workPhone', 'cellPhone', 'title',
'office');
}
if (!empty($options['pictures'])) {
$return_fields[$gal][] = 'photo';
}
$opts = array(
'matchBegin' => true,
'forceSource' => true,
'sources' => $sources,
'returnFields' => $return_fields,
'fields' => $fields
);
return $this->_registry->contacts->search($query, $opts);
}
/**
* Resolve a recipient
*
* @param string $query The search string. Ususally an email address.
* @param array $opts Any additional options:
* - maxcerts: (integer) The maximum number of certificates to return
* as provided by the client.
* - maxambiguous: (integer) The maximum number of ambiguous results. If
* set to zero, we MUST have an exact match.
* - starttime: (Horde_Date) The start time for the availability window if
* requesting AVAILABILITY.
* - endtime: (Horde_Date) The end of the availability window if
* requesting AVAILABILITY.
* - maxsize: (integer) The maximum size of any pictures.
* DEFAULT: 0 (No limit).
* - maxpictures: (integer) The maximum count of images to return.
* DEFAULT: - (No limit).
* - pictures: (boolean) Return pictures.
*
* @return array The search results, keyed by the $query.
*/
public function resolveRecipient($query, array $opts = array())
{
if (!empty($opts['starttime'])) {
try {
return array($query => $this->_registry->calendar->lookupFreeBusy($query, true));
} catch (Horde_Exception $e) {
return false; // ?
}
}
$gal = $this->contacts_getGal();
$sources = array_keys($this->_registry->contacts->sources(false, true));
if (!in_array($gal, $sources)) {
$sources[] = $gal;
}
foreach ($sources as $source) {
$fields[$source] = array('name', 'email', 'alias', 'smimePublicKey');
if (!empty($opts['pictures'])) {
$fields[$source]['photo'];
}
}
$options = array(
'matchBegin' => true,
'sources' => $sources,
'fields' => $fields
);
if (isset($opts['maxAmbiguous']) && $opts['maxAmbiguous'] == 0) {
$options['customStrict'] = array('email', 'name', 'alias');
}
return $this->_registry->contacts->search($query, $options);
}
/**
* Get the GAL source uid.
*
* @return string | boolean The address book id of the GAL, or false if
* not available.
*/
public function contacts_getGal()
{
if (empty($this->_gal)) {
$this->_gal = $this->_registry->contacts->getGalUid();
}
return $this->_gal;
}
/**
* Browse VFS backend.
*
* @param string $path The path to browse/fetch. This should be in UNC
* format with the "server" portion specifying
* backend name. e.g., \\file\mike\file.txt or
* \\sql\mike\file.txt
*
* @return array An array of data arrays with the following structure:
* linkid: (string) The UNC path for this resource.
* name: (string) The display name of the resource.
* content-length: (integer) The byte size of the resource (if a file).
* modified: (Horde_Date) The modification time of the resource, if
* available.
* create: (Horde_Date) The creation time of the resource, if
* available.
* is_folder: (boolean) True if the resource is a folder.
* data: (Horde_Stream) The data, if resource is a file.
* content-type: (string) The MIME type of the file resource, if
* available.
* @since 2.12.0
*/
public function files_browse($path)
{
if (!$app = $this->_registry->hasInterface('files')) {
return false;
}
// Save for later.
$original_path = $path;
// Normalize
$path = str_replace('\\', '/', $path);
// Get the "server" name.
$regex = '=^//([a-zA-Z0-9-]+)/(.*)=';
if (preg_match($regex, $path, $results) === false) {
return false;
}
$backend = $app . '/' . $results[1];
$path = $backend . '//' . $results[2];
try {
$results = $this->_registry->files->browse($path);
} catch (Horde_Exception $e) {
throw new Horde_ActiveSync_Exception($e);
}
$files = array();
// An explicit file requested?
if (!empty($results['data'])) {
$data = new Horde_Stream();
$data->add($results['data']);
$files[] = array(
'linkid' => $original_path,
'name' => $results['name'],
'content-length' => $results['contentlength'],
'modified' => new Horde_Date($results['mtime']),
'created' => new Horde_Date($results['mtime']), // No creation date?
'is_folder' => false,
'data' => $data);
} else {
foreach ($results as $id => $result) {
$file = array('name' => $result['name']);
$file['is_folder'] = $result['browseable'];
$file['modified'] = new Horde_Date($result['modified']);
$file['created'] = clone $file['modified'];
$file['linkid'] = str_replace($backend, '', $id);
if (!empty($result['contentlength'])) {
$file['content-length'] = $result['contentlength'];
}
$files[] = $file;
}
}
return $files;
}
/**
* List all tasks in the user's default tasklist.
*
* @param string $tasklist The tasklist to check. If null, use multiplexed.
*
* @return array An array of task uids.
*/
public function tasks_listUids($tasklist = null)
{
return $this->_registry->tasks->listUids($tasklist);
}
/**
* Export a single task from the backend.
*
* @param string $uid The task uid
* @param array $options Options to pass to the backend exporter.
*
* @return Horde_ActiveSync_Message_Task The task message object
*/
public function tasks_export($uid, array $options = array())
{
return $this->_registry->tasks->export($uid, 'activesync', $options);
}
/**
* Import a single task into the backend.
*
* @param Horde_ActiveSync_Message_Task $message The task message object
* @param string $tasklist The tasklist id. @since 2.12.0
*
* @return string The newly added task's uid.
*/
public function tasks_import(Horde_ActiveSync_Message_Task $message, $tasklist = null)
{
return $this->_registry->tasks->import($message, 'activesync', $tasklist);
}
/**
* Replace an existing task with the provided task.
*
* @param string $uid The existing tasks's uid
* @param Horde_ActiveSync_Message_Task $message The task object
*/
public function tasks_replace($uid, Horde_ActiveSync_Message_Task $message)
{
$this->_registry->tasks->replace($uid, $message, 'activesync');
}
/**
* Delete a task from the backend.
*
* @param string $id The task's uid
*/
public function tasks_delete($id)
{
$this->_registry->tasks->delete($id);
}
/**
* Return the timestamp or modseq for the last time $action was performed.
*
* @param string $uid The UID of the task we are interested in.
* @param string $action The action we are interested in (add, modify...)
* @param string $tasklike The tasklist, if not using multiplexed data.
*
* @return integer
*/
public function tasks_getActionTimestamp($uid, $action, $tasklist = null)
{
return $this->_registry->tasks->getActionTimestamp(
$uid, $action, $tasklist, $this->hasFeature('modseq', 'tasks'));
}
/**
* List notepads.
*
* @return array
* @since 5.1
* @deprecated - @todo was never used, remove in H6.
*/
public function notes_listNotepads()
{
return $this->_registry->notes->listNotepads();
}
/**
* List all notes in the user's default notepad.
*
* @param string $notepad The notepad id to list. If null, use multiplexed.
* @since 2.12.0
*
* @return array An array of note uids.
* @since 5.1
*/
public function notes_listUids($notepad = null)
{
return $this->_registry->notes->listUids($notepad);
}
/**
* Export a single note from the backend.
*
* @param string $uid The note uid
* @param array $options Options to pass to the backend exporter.
*
* @return Horde_ActiveSync_Message_Note The note message object
* @since 5.1
*/
public function notes_export($uid, array $options = array())
{
return $this->_registry->notes->export($uid, 'activesync', $options);
}
/**
* Importa a single note into the backend.
*
* @param Horde_ActiveSync_Message_Note $message The note message object
* @param string $notebook The notebook id.
* @since 2.12.0
*
* @return string The newly added notes's uid.
* @since 5.1
*/
public function notes_import(Horde_ActiveSync_Message_Note $message, $notebook = null)
{
return $this->_registry->notes->import($message, 'activesync', $notebook);
}
/**
* Replace an existing task with the provided task.
*
* @param string $uid The existing tasks's uid
* @param Horde_ActiveSync_Message_Note $message The task object
* @since 5.1
*/
public function notes_replace($uid, Horde_ActiveSync_Message_Note $message)
{
$this->_registry->notes->replace($uid, $message, 'activesync');
}
/**
* Delete a note from the backend.
*
* @param string $id The task's uid
* @since 5.1
*/
public function notes_delete($id)
{
$this->_registry->notes->delete($id);
}
/**
* Return the timestamp for the last time $action was performed.
*
* @param string $uid The UID of the task we are interested in.
* @param string $action The action we are interested in (add, modify...)
* @param string $notepad The notepad to use, if not using multiplex.
*
* @return integer
* @since 5.1
*/
public function notes_getActionTimestamp($uid, $action, $notepad = null)
{
return $this->_registry->notes->getActionTimestamp(
$uid, $action, $notepad, $this->hasFeature('modseq', 'notes'));
}
/**
* Return all active api interfaces.
*
* @return array An array of interface names.
*/
public function horde_listApis()
{
$apis = $this->_registry->horde->listAPIs();
// Note support not added until 5.1. Need to check the feature.
// @TODO: H6, add this check to all apps. BC break to check it now,
// since we didn't have this feature earlier.
if ($key = array_search('notes', $apis)) {
if (!$this->hasFeature('activesync', 'notes')) {
unset($apis[$key]);
}
}
$inactive = $this->_registry->listApps(array('inactive'));
$active_apis = array();
foreach ($apis as $api) {
if (!$this->_registry->isInactive($this->_registry->hasInterface($api))) {
$active_apis[] = $api;
}
}
return $active_apis;
}
/**
* Return if the backend collection has the requested feature.
*
* @param string $feature The requested feature.
* @param string $collection The requested collection id.
*
* @return boolean
* @since 2.6.0
*/
public function hasFeature($feature, $collection)
{
if (empty($this->_capabilities[$collection]) || !array_key_exists($feature, $this->_capabilities[$collection])) {
$this->_capabilities[$collection][$feature] =
$this->_registry->hasFeature($feature, $this->_getAppFromCollectionId($collection));
}
return $this->_capabilities[$collection][$feature];
}
/**
* Return the highest modification sequence value for the specified
* collection
*
* @return integer The modseq value.
* @since 2.6.0
*/
public function getHighestModSeq($collection, $id = null)
{
return $this->_registry->{$this->_getInterfaceFromCollectionId($collection)}->getHighestModSeq($id);
}
/**
* Convert a collection id to a horde app name.
*
* @param string $collection The collection id e.g., @Notes@.
*
* @return string The horde application name e.g., nag.
*/
protected function _getAppFromCollectionId($collection)
{
return $this->_registry->hasInterface($this->_getInterfaceFromCollectionId($collection));
}
/**
* Normalize the collection ids to interface names.
*
* @param string $collection The collection id e.g., @Notes@
*
* @return string The Horde interface name e.g., notes
*/
protected function _getInterfaceFromCollectionId($collection)
{
return Horde_String::lower(str_replace('@', '', $collection));
}
/**
* Obtain a user's preference setting.
*
* @param string $app The Horde application providing the setting.
* @param string $pref The name of the preference setting.
*
* @return mixed The preference value
* @deprecated (unused)
*/
public function horde_getPref($app, $pref)
{
return $this->_registry->horde->getPreference($app, $pref);
}
/**
* Obtain the name of the Horde application that provides the specified api
* interface.
*
* @param string $api The interface name
*
* @return string The application name.
*/
public function horde_hasInterface($api)
{
return $this->_registry->hasInterface($api);
}
/**
* Wrapper around Horde_Registry::hasMethod.
*
* @param string $api The API to check.
* @param string $method The method name.
*
* @return boolean
*/
public function horde_hasMethod($method, $api)
{
return $this->_registry->hasMethod($method, $this->_registry->hasInterface($api));
}
/**
* Return the currently set vacation message details.
*
* @return array|boolean The vacation rule properties or false if
* interface unavailable.
*/
public function filters_getVacation()
{
if ($this->horde_hasInterface('filter')) {
return $this->_registry->filter->getVacation();
} else {
return false;
}
}
/**
* Set vacation message properties.
*
* @param array $setting The vacation details.
*
* @throws Horde_Exception
*/
public function filters_setVacation(array $setting)
{
if (!$this->horde_hasInterface('filter')) {
throw new Horde_Exception('Filter interface unavailable.');
}
if ($setting['oofstate'] != Horde_ActiveSync_Request_Settings::OOF_STATE_DISABLED) {
// Currently the filter/ API only supports a single configuration.
// So, first check "external" rules and if none found, send the
// internal rules.
foreach ($setting['oofmsgs'] as $msg) {
if ($msg['appliesto'] == Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOEXTERNALKNOWN ||
$msg['appliesto'] == Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOEXTERNALUNKNOWN) {
$vacation = array(
'reason' => $msg['replymessage'],
'subject' => Horde_Core_Translation::t('Out Of Office')
);
break;
}
if ($msg['appliesto'] == Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOINTERNAL) {
$vacation = array(
'reason' => $msg['replymessage'],
'subject' => Horde_Core_Translation::t('Out Of Office')
);
}
}
if (!empty($setting['starttime'])) {
$vacation['start'] = $setting['starttime']->timestamp();
}
if (!empty($setting['endtime'])) {
$vacation['end'] = $setting['endtime']->timestamp();
}
$this->_registry->filter->setVacation($vacation);
} else {
$this->_registry->filter->disableVacation();
}
}
/**
* Return a Maillog entry for the specified Message-ID.
*
* @param string $mid The Message-ID of the message.
*
* @return Horde_History_Log|false The history log or false if not found.
*/
public function mail_getMaillog($mid)
{
if ($this->_registry->hasMethod('getMaillog', $this->_registry->hasInterface('mail'))) {
try {
return $this->_registry->mail->getMaillog($mid);
} catch (Horde_Exception $e) {
$this->_logger->err($e->getMessage());
}
}
return false;
}
/**
* Log a forward/reply action to the maillog.
*
* @param string $action The action to log. One of: 'forward', 'reply',
* 'reply_all'.
* @param string $mid The Message-ID to log.
* @param string $recipients The recipients the mail was forwarded to.
*/
public function mail_logMaillog($action, $mid, $recipients = null)
{
if (!empty($recipients)) {
$recipients = array('recipients' => $recipients);
}
if ($this->_registry->hasMethod('logMaillog', $this->_registry->hasInterface('mail'))) {
try {
$this->_registry->mail->logMaillog($action, $mid, $recipients);
} catch (Horde_Exception $e) {
$this->_logger->err($e->getMessage());
}
}
}
public function mail_logRecipient($action, $recipients, $message_id)
{
if ($this->_registry->hasMethod('logRecipient', $this->_registry->hasInterface('mail'))) {
try {
$this->_registry->mail->logRecipient($action, $recipients, $message_id);
} catch (Horde_Exception $e) {
$this->_logger->err($e->getMessage());
}