Repository navigation
Expand file tree
/
Copy pathclass.meetingrequest.php
More file actions
5076 lines (4361 loc) · 196 KB
/
Copy pathclass.meetingrequest.php
File metadata and controls
5076 lines (4361 loc) · 196 KB
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
/*
* SPDX-License-Identifier: AGPL-3.0-only
* SPDX-FileCopyrightText: Copyright 2005-2016 Zarafa Deutschland GmbH
* SPDX-FileCopyrightText: Copyright 2020-2025 grommunio GmbH
*/
class Meetingrequest {
/*
* NOTE
*
* This class is designed to modify and update meeting request properties
* and to search for linked appointments in the calendar. It does not
* - set standard properties like subject or location
* - commit property changes through savechanges() (except in accept() and decline())
*
* To set all the other properties, just handle the item as any other appointment
* item. You aren't even required to set those properties before or after using
* this class. If you update properties before REsending a meeting request (ie with
* a time change) you MUST first call updateMeetingRequest() so the internal counters
* can be updated. You can then submit the message any way you like.
*
*/
/*
* How to use
* ----------
*
* Sending a meeting request:
* - Create appointment item as normal, but as 'tentative'
* (this is the state of the item when the receiving user has received but
* not accepted the item)
* - Set recipients as normally in e-mails
* - Create Meetingrequest class instance
* - Call checkCalendarWriteAccess(), to check for write permissions on calendar folder
* - Call setMeetingRequest(), this turns on all the meeting request properties in the
* calendar item
* - Call sendMeetingRequest(), this sends a copy of the item with some extra properties
*
* Updating a meeting request:
* - Create Meetingrequest class instance
* - Call checkCalendarWriteAccess(), to check for write permissions on calendar folder
* - Call updateMeetingRequest(), this updates the counters
* - Call checkSignificantChanges(), this will check for significant changes and if needed will clear the
* existing recipient responses
* - Call sendMeetingRequest()
*
* Clicking on a an e-mail:
* - Create Meetingrequest class instance
* - Check isMeetingRequest(), if true:
* - Check isLocalOrganiser(), if true then ignore the message
* - Check isInCalendar(), if not call doAccept(true, false, false). This adds the item in your
* calendar as tentative without sending a response
* - Show Accept, Tentative, Decline buttons
* - When the user presses Accept, Tentative or Decline, call doAccept(false, true, true),
* doAccept(true, true, true) or doDecline(true) respectively to really accept or decline and
* send the response. This will remove the request from your inbox.
* - Check isMeetingRequestResponse, if true:
* - Check isLocalOrganiser(), if not true then ignore the message
* - Call processMeetingRequestResponse()
* This will update the trackstatus of all recipients, and set the item to 'busy'
* when all the recipients have accepted.
* - Check isMeetingCancellation(), if true:
* - Check isLocalOrganiser(), if true then ignore the message
* - Check isInCalendar(), if not, then ignore
* Call processMeetingCancellation()
* - Show 'Remove From Calendar' button to user
* - When userpresses button, call doRemoveFromCalendar(), which removes the item from your
* calendar and deletes the message
* - Check isMeetingForwardNotification(), if true:
* - Call processMeetingForwardNotification()
* This adds the attendees an attendee forwarded the meeting to.
*
* Cancelling a meeting request:
* - Call doCancelInvitation, which will send cancellation mails to attendees and will remove
* meeting object from calendar
*
* Forwarding a meeting request:
* - Call forwardMeetingRequest(), which sends the meeting to further attendees in the name
* of the organizer and notifies the organizer
*/
// All properties for a recipient that are interesting
public $recipprops = [
PR_ENTRYID,
PR_DISPLAY_NAME,
PR_EMAIL_ADDRESS,
PR_RECIPIENT_ENTRYID,
PR_RECIPIENT_TYPE,
PR_SEND_INTERNET_ENCODING,
PR_SEND_RICH_INFO,
PR_RECIPIENT_DISPLAY_NAME,
PR_ADDRTYPE,
PR_DISPLAY_TYPE,
PR_DISPLAY_TYPE_EX,
PR_RECIPIENT_TRACKSTATUS,
PR_RECIPIENT_TRACKSTATUS_TIME,
PR_RECIPIENT_FLAGS,
PR_ROWID,
PR_OBJECT_TYPE,
PR_SEARCH_KEY,
PR_SMTP_ADDRESS,
];
/**
* Indication whether the setting of resources in a Meeting Request is success (false) or if it
* has failed (integer).
*
* @var null|false|int
*
* @psalm-var 1|3|4|false|null
*/
public $errorSetResource;
public $proptags;
private false|string $meetingTimeInfo;
private $mti_html;
/**
* @var null|bool
*/
private $includesResources;
private $nonAcceptingResources;
private $recipientDisplayname;
// the address book of the session, opened once per request
private mixed $addressBook = null;
// SMTP addresses by address book entryid, looked up once per request
private array $smtpAddresses = [];
// response prepared by createResponse() and sent once the meeting is stored
private mixed $pendingResponse = null;
/**
* Constructor.
*
* Takes a store and a message. The message is an appointment item
* that should be converted into a meeting request or an incoming
* e-mail message that is a meeting request.
*
* The $session variable is optional, but required if the following features
* are to be used:
*
* - Sending meeting requests for meetings that are not in your own store
* - Sending meeting requests to resources, resource availability checking and resource freebusy updates
*
* $removeRequestOnResponse is opt-in; leaving the request mail alone is the
* default.
*
* @param mixed $store
* @param mixed $message
* @param mixed $session
* @param mixed $enableDirectBooking
* @param mixed $removeRequestOnResponse
*/
public function __construct(private $store, public $message, private $session = false, private $enableDirectBooking = true, private $removeRequestOnResponse = false) {
// This variable string saves time information for the MR.
$this->meetingTimeInfo = false;
$properties = [];
$properties['goid'] = 'PT_BINARY:PSETID_Meeting:0x3';
$properties['goid2'] = 'PT_BINARY:PSETID_Meeting:0x23';
$properties['type'] = 'PT_STRING8:PSETID_Meeting:0x24';
$properties['meetingrecurring'] = 'PT_BOOLEAN:PSETID_Meeting:0x5';
$properties['unknown2'] = 'PT_BOOLEAN:PSETID_Meeting:0xa';
$properties['attendee_critical_change'] = 'PT_SYSTIME:PSETID_Meeting:0x1';
$properties['owner_critical_change'] = 'PT_SYSTIME:PSETID_Meeting:0x1a';
$properties['meetingstatus'] = 'PT_LONG:PSETID_Appointment:' . PidLidAppointmentStateFlags;
$properties['responsestatus'] = 'PT_LONG:PSETID_Appointment:0x8218';
$properties['unknown6'] = 'PT_LONG:PSETID_Meeting:0x4';
$properties['replytime'] = 'PT_SYSTIME:PSETID_Appointment:0x8220';
$properties['usetnef'] = 'PT_BOOLEAN:PSETID_Common:0x8582';
$properties['recurrence_data'] = 'PT_BINARY:PSETID_Appointment:' . PidLidAppointmentRecur;
$properties['reminderminutes'] = 'PT_LONG:PSETID_Common:' . PidLidReminderDelta;
$properties['reminderset'] = 'PT_BOOLEAN:PSETID_Common:' . PidLidReminderSet;
$properties['sendasical'] = 'PT_BOOLEAN:PSETID_Appointment:0x8200';
$properties['updatecounter'] = 'PT_LONG:PSETID_Appointment:' . PidLidAppointmentSequence; // AppointmentSequenceNumber
$properties['unknown7'] = 'PT_LONG:PSETID_Appointment:0x8202';
$properties['last_updatecounter'] = 'PT_LONG:PSETID_Appointment:0x8203'; // AppointmentLastSequence
$properties['busystatus'] = 'PT_LONG:PSETID_Appointment:' . PidLidBusyStatus;
$properties['intendedbusystatus'] = 'PT_LONG:PSETID_Appointment:' . PidLidIntendedBusyStatus;
$properties['start'] = 'PT_SYSTIME:PSETID_Appointment:' . PidLidAppointmentStartWhole;
$properties['responselocation'] = 'PT_STRING8:PSETID_Meeting:0x2';
$properties['location'] = 'PT_STRING8:PSETID_Appointment:' . PidLidLocation;
$properties['requestsent'] = 'PT_BOOLEAN:PSETID_Appointment:0x8229'; // PidLidFInvited, MeetingRequestWasSent
$properties['startdate'] = 'PT_SYSTIME:PSETID_Appointment:' . PidLidAppointmentStartWhole;
$properties['duedate'] = 'PT_SYSTIME:PSETID_Appointment:' . PidLidAppointmentEndWhole;
$properties['flagdueby'] = 'PT_SYSTIME:PSETID_Common:' . PidLidReminderSignalTime;
$properties['commonstart'] = 'PT_SYSTIME:PSETID_Common:0x8516';
$properties['commonend'] = 'PT_SYSTIME:PSETID_Common:0x8517';
$properties['recurring'] = 'PT_BOOLEAN:PSETID_Appointment:' . PidLidRecurring;
$properties['clipstart'] = 'PT_SYSTIME:PSETID_Appointment:' . PidLidClipStart;
$properties['clipend'] = 'PT_SYSTIME:PSETID_Appointment:' . PidLidClipEnd;
$properties['start_recur_date'] = 'PT_LONG:PSETID_Meeting:0xD'; // StartRecurTime
$properties['start_recur_time'] = 'PT_LONG:PSETID_Meeting:0xE'; // StartRecurTime
$properties['end_recur_date'] = 'PT_LONG:PSETID_Meeting:0xF'; // EndRecurDate
$properties['end_recur_time'] = 'PT_LONG:PSETID_Meeting:0x10'; // EndRecurTime
$properties['is_exception'] = 'PT_BOOLEAN:PSETID_Meeting:0xA'; // LID_IS_EXCEPTION
$properties['apptreplyname'] = 'PT_STRING8:PSETID_Appointment:0x8230';
// Propose new time properties
$properties['proposed_start_whole'] = 'PT_SYSTIME:PSETID_Appointment:' . PidLidAppointmentProposedStartWhole;
$properties['proposed_end_whole'] = 'PT_SYSTIME:PSETID_Appointment:' . PidLidAppointmentProposedEndWhole;
$properties['proposed_duration'] = 'PT_LONG:PSETID_Appointment:0x8256';
$properties['counter_proposal'] = 'PT_BOOLEAN:PSETID_Appointment:' . PidLidAppointmentCounterProposal;
$properties['recurring_pattern'] = 'PT_STRING8:PSETID_Appointment:' . PidLidRecurrencePattern;
$properties['basedate'] = 'PT_SYSTIME:PSETID_Appointment:' . PidLidExceptionReplaceTime;
$properties['meetingtype'] = 'PT_LONG:PSETID_Meeting:0x26';
$properties['timezone_data'] = 'PT_BINARY:PSETID_Appointment:' . PidLidTimeZoneStruct;
$properties['timezone'] = 'PT_STRING8:PSETID_Appointment:' . PidLidTimeZoneDescription;
$properties['categories'] = 'PT_MV_STRING8:PS_PUBLIC_STRINGS:Keywords';
$properties['private'] = 'PT_BOOLEAN:PSETID_Common:' . PidLidPrivate;
$properties['alldayevent'] = 'PT_BOOLEAN:PSETID_Appointment:' . PidLidAppointmentSubType;
$properties['toattendeesstring'] = 'PT_STRING8:PSETID_Appointment:0x823B';
$properties['ccattendeesstring'] = 'PT_STRING8:PSETID_Appointment:0x823C';
$properties['allattendeesstring'] = 'PT_STRING8:PSETID_Appointment:0x8238';
$properties['auxiliary_flags'] = 'PT_LONG:PSETID_Appointment:0x8207';
$properties['forward_instance'] = 'PT_BOOLEAN:PSETID_Appointment:0x820A';
$properties['tzdefstart'] = 'PT_BINARY:PSETID_Appointment:0x825E';
$properties['forward_notification_recipients'] = 'PT_BINARY:PSETID_Appointment:0x8261';
$this->proptags = getPropIdsFromStrings($this->store, $properties);
}
/**
* Sets the direct booking property. This is an alternative to the setting of the direct booking
* property through the constructor. However, setting it in the constructor is preferred.
*
* @param bool $directBookingSetting
*/
public function setDirectBooking($directBookingSetting): void {
$this->enableDirectBooking = $directBookingSetting;
}
/**
* Returns TRUE if the message pointed to is an incoming meeting request and should
* therefore be replied to with doAccept or doDecline().
*
* @param false|string $messageClass message class to use for checking
*
* @return bool returns true if this is a meeting request else false
*/
public function isMeetingRequest(false|string $messageClass = false): bool {
if ($messageClass === false) {
$messageClass = mapi_getprops($this->message, [PR_MESSAGE_CLASS])[PR_MESSAGE_CLASS] ?? false;
}
return $messageClass !== false && stripos($messageClass, 'ipm.schedule.meeting.request') === 0;
}
/**
* Returns TRUE if the message pointed to is a returning meeting request response.
*
* @param false|string $messageClass message class to use for checking
*
* @return bool returns true if this is a meeting request else false
*/
public function isMeetingRequestResponse(false|string $messageClass = false): bool {
if ($messageClass === false) {
$messageClass = mapi_getprops($this->message, [PR_MESSAGE_CLASS])[PR_MESSAGE_CLASS] ?? false;
}
return $messageClass !== false && stripos($messageClass, 'ipm.schedule.meeting.resp') === 0;
}
/**
* Returns TRUE if the message pointed to is a cancellation request.
*
* @param false|string $messageClass message class to use for checking
*
* @return bool returns true if this is a meeting request else false
*/
public function isMeetingCancellation(false|string $messageClass = false): bool {
if ($messageClass === false) {
$messageClass = mapi_getprops($this->message, [PR_MESSAGE_CLASS])[PR_MESSAGE_CLASS] ?? false;
}
return $messageClass !== false && stripos($messageClass, 'ipm.schedule.meeting.canceled') === 0;
}
/**
* Returns TRUE if the message pointed to is a meeting forward notification.
*
* @param false|string $messageClass message class to use for checking
*
* @return bool returns true if this is a meeting forward notification else false
*/
public function isMeetingForwardNotification(false|string $messageClass = false): bool {
if ($messageClass === false) {
$messageClass = mapi_getprops($this->message, [PR_MESSAGE_CLASS])[PR_MESSAGE_CLASS] ?? false;
}
return $messageClass !== false && stripos($messageClass, 'ipm.schedule.meeting.notification.forward') === 0;
}
/**
* Function is used to get the last update counter of meeting request.
*
* @return false|int false when last_updatecounter not found else return last_updatecounter
*/
public function getLastUpdateCounter(): false|int {
$calendarItemProps = mapi_getprops($this->message, [$this->proptags['last_updatecounter']]);
return $calendarItemProps[$this->proptags['last_updatecounter']] ?? false;
}
/**
* Process an incoming meeting request response. This updates the appointment
* in your calendar to show whether the user has accepted or declined.
*/
public function processMeetingRequestResponse(): void {
if (!$this->isMeetingRequestResponse()) {
return;
}
if (!$this->isLocalOrganiser()) {
return;
}
// Get information we need from the response message
$messageprops = mapi_getprops($this->message, [
$this->proptags['goid'],
$this->proptags['goid2'],
PR_OWNER_APPT_ID,
PR_SENT_REPRESENTING_EMAIL_ADDRESS,
PR_SENT_REPRESENTING_NAME,
PR_SENT_REPRESENTING_ADDRTYPE,
PR_SENT_REPRESENTING_ENTRYID,
PR_SENT_REPRESENTING_SEARCH_KEY,
PR_MESSAGE_DELIVERY_TIME,
PR_MESSAGE_CLASS,
PR_PROCESSED,
PR_RCVD_REPRESENTING_ENTRYID,
$this->proptags['proposed_start_whole'],
$this->proptags['proposed_end_whole'],
$this->proptags['proposed_duration'],
$this->proptags['counter_proposal'],
$this->proptags['attendee_critical_change'],
]);
$goid2 = $messageprops[$this->proptags['goid2']];
if (!isset($goid2) || !isset($messageprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS])) {
return;
}
// Find basedate in GlobalID(0x3), this can be a response for an occurrence
$basedate = $this->getBasedateFromGlobalID($messageprops[$this->proptags['goid']]);
$userStore = $this->store;
// check if delegate is processing the response
if (isset($messageprops[PR_RCVD_REPRESENTING_ENTRYID])) {
$delegatorStore = $this->getDelegatorStore($messageprops[PR_RCVD_REPRESENTING_ENTRYID], [PR_IPM_APPOINTMENT_ENTRYID]);
if (!empty($delegatorStore['store'])) {
$userStore = $delegatorStore['store'];
}
}
// check for calendar access
$this->ensureCalendarWriteAccess($userStore);
$calendarItem = $this->getCorrespondentCalendarItem(true);
// Open the calendar items, and update all the recipients of the calendar item that match
// the email address of the response.
if ($calendarItem !== false) {
$this->processResponse($userStore, $calendarItem, $basedate, $messageprops);
}
}
/**
* Process every incoming MeetingRequest response.This updates the appointment
* in your calendar to show whether the user has accepted or declined.
*
* @param resource $store contains the userStore in which the meeting is created
* @param mixed $calendarItem resource of the calendar item for which this response has arrived
* @param false|int $basedate if present the create an exception
* @param array $messageprops contains message properties
*/
public function processResponse(mixed $store, mixed $calendarItem, mixed $basedate, array $messageprops): ?false {
$senderentryid = $messageprops[PR_SENT_REPRESENTING_ENTRYID];
$messageclass = $messageprops[PR_MESSAGE_CLASS];
$deliverytime = $messageprops[PR_MESSAGE_DELIVERY_TIME];
$recurringItem = false;
// Open the calendar item, find the sender in the recipient table and update all the recipients of the calendar item that match
// the email address of the response.
$calendarItemProps = mapi_getprops($calendarItem, [$this->proptags['recurring'], PR_STORE_ENTRYID, PR_PARENT_ENTRYID, PR_ENTRYID, $this->proptags['updatecounter']]);
// check if meeting response is already processed
if (isset($messageprops[PR_PROCESSED]) && $messageprops[PR_PROCESSED] === true) {
// meeting is already processed
return null;
}
mapi_setprops($this->message, [PR_PROCESSED => true]);
mapi_savechanges($this->message);
// if meeting is updated in organizer's calendar then we don't need to process
// old response
if ($this->isMeetingUpdated($basedate)) {
return null;
}
// If basedate is found, then create/modify exception msg and do processing
if (!empty($basedate) && !empty($calendarItemProps[$this->proptags['recurring']])) {
$attach = $this->saveResponseException($store, $calendarItem, $basedate);
if ($attach) {
$recurringItem = $calendarItem;
$calendarItem = mapi_attach_openobj($attach, MAPI_MODIFY);
}
else {
return false;
}
}
$this->updateResponseRecipients($calendarItem, $messageprops, $senderentryid, $messageclass, $deliverytime);
// TODO: Update counter proposal number property on message
/*
If it is the first time this attendee has proposed a new date/time, increment the value of the PidLidAppointmentProposalNumber property on the organizer's meeting object, by 0x00000001. If this property did not previously exist on the organizer's meeting object, it MUST be set with a value of 0x00000001.
*/
// If this is a counter proposal, set the counter proposal indicator boolean
if (isset($messageprops[$this->proptags['counter_proposal']])) {
$props = [$this->proptags['counter_proposal'] => (bool) $messageprops[$this->proptags['counter_proposal']]];
mapi_setprops($calendarItem, $props);
}
mapi_savechanges($calendarItem);
if (isset($attach) && $recurringItem !== false) {
mapi_savechanges($attach);
mapi_savechanges($recurringItem);
}
return null;
}
private function saveResponseException(mixed $store, mixed $calendarItem, mixed $basedate): mixed {
$recurr = new Recurrence($store, $calendarItem);
// Copy properties from meeting request
$exception_props = mapi_getprops($this->message, [
PR_OWNER_APPT_ID,
$this->proptags['proposed_start_whole'],
$this->proptags['proposed_end_whole'],
$this->proptags['proposed_duration'],
$this->proptags['counter_proposal'],
]);
// Create/modify exception
if ($recurr->isException($basedate)) {
$recurr->modifyException($exception_props, $basedate);
}
else {
// When we are creating an exception we need copy recipients from main recurring item
$recips = $this->getMessageRecipients($calendarItem);
// Retrieve actual start/due dates from calendar item.
$exception_props[$this->proptags['startdate']] = $recurr->getOccurrenceStart($basedate);
$exception_props[$this->proptags['duedate']] = $recurr->getOccurrenceEnd($basedate);
$recurr->createException($exception_props, $basedate, false, $recips);
}
mapi_savechanges($calendarItem);
return $recurr->getExceptionAttachment($basedate);
}
private function updateResponseRecipients(mixed $calendarItem, array $messageprops, mixed $senderentryid, mixed $messageclass, mixed $deliverytime): void {
// Get the recipients of the calendar item
$recipients = $this->getMessageRecipients($calendarItem);
// FIXME we should look at the updatecounter property and compare it
// to the counter in the recipient to see if this update is actually
// newer than the status in the calendar item
$found = false;
foreach ($recipients as $recipient) {
// external recipients might not have entryid
if (!isset($recipient[PR_ENTRYID]) &&
$recipient[PR_EMAIL_ADDRESS] == $messageprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS]) {
$recipient[PR_ENTRYID] = $senderentryid;
}
if (isset($recipient[PR_ENTRYID]) && $this->compareABEntryIDs($recipient[PR_ENTRYID], $senderentryid)) {
$found = true;
/*
* If value of attendee_critical_change on meeting response mail is less than PR_RECIPIENT_TRACKSTATUS_TIME
* on the corresponding recipientRow of meeting then we ignore this response mail.
*/
if (isset($recipient[PR_RECIPIENT_TRACKSTATUS_TIME]) && ($messageprops[$this->proptags['attendee_critical_change']] < $recipient[PR_RECIPIENT_TRACKSTATUS_TIME])) {
continue;
}
$recipient = $this->getResponseRecipientProperties($recipient, $messageprops, $messageclass);
// Update the recipient information
mapi_message_modifyrecipients($calendarItem, MODRECIP_REMOVE, [$recipient]);
mapi_message_modifyrecipients($calendarItem, MODRECIP_ADD, [$recipient]);
}
}
// If the recipient was not found in the original calendar item,
// then add the recpient as a new optional recipient
if (!$found) {
$recipient = $this->getNewResponseRecipient($messageprops, $messageclass, $deliverytime);
mapi_message_modifyrecipients($calendarItem, MODRECIP_ADD, [$recipient]);
}
}
private function getResponseRecipientProperties(array $recipient, array $messageprops, mixed $messageclass): array {
// The email address matches, update the row
$recipient[PR_RECIPIENT_TRACKSTATUS] = $this->getTrackStatus($messageclass);
if (isset($messageprops[$this->proptags['attendee_critical_change']])) {
$recipient[PR_RECIPIENT_TRACKSTATUS_TIME] = $messageprops[$this->proptags['attendee_critical_change']];
}
// If this is a counter proposal, set the proposal properties in the recipient row
if (isset($messageprops[$this->proptags['counter_proposal']]) && $messageprops[$this->proptags['counter_proposal']]) {
$recipient[PR_RECIPIENT_PROPOSEDSTARTTIME] = $messageprops[$this->proptags['proposed_start_whole']];
$recipient[PR_RECIPIENT_PROPOSEDENDTIME] = $messageprops[$this->proptags['proposed_end_whole']];
$recipient[PR_RECIPIENT_PROPOSED] = $messageprops[$this->proptags['counter_proposal']];
}
return $recipient;
}
private function getNewResponseRecipient(array $messageprops, mixed $messageclass, mixed $deliverytime): array {
$recipient = [];
$recipient[PR_ENTRYID] = $messageprops[PR_SENT_REPRESENTING_ENTRYID];
$recipient[PR_EMAIL_ADDRESS] = $messageprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS];
$recipient[PR_DISPLAY_NAME] = $messageprops[PR_SENT_REPRESENTING_NAME];
$recipient[PR_ADDRTYPE] = $messageprops[PR_SENT_REPRESENTING_ADDRTYPE];
$recipient[PR_RECIPIENT_TYPE] = MAPI_CC;
$recipient[PR_SEARCH_KEY] = $messageprops[PR_SENT_REPRESENTING_SEARCH_KEY];
$recipient[PR_RECIPIENT_TRACKSTATUS] = $this->getTrackStatus($messageclass);
$recipient[PR_RECIPIENT_TRACKSTATUS_TIME] = $deliverytime;
// If this is a counter proposal, set the proposal properties in the recipient row
if (isset($messageprops[$this->proptags['counter_proposal']])) {
$recipient[PR_RECIPIENT_PROPOSEDSTARTTIME] = $messageprops[$this->proptags['proposed_start_whole']];
$recipient[PR_RECIPIENT_PROPOSEDENDTIME] = $messageprops[$this->proptags['proposed_end_whole']];
$recipient[PR_RECIPIENT_PROPOSED] = $messageprops[$this->proptags['counter_proposal']];
}
return $recipient;
}
/**
* Process an incoming meeting request cancellation. This updates the
* appointment in your calendar to show that the meeting has been cancelled.
*/
public function processMeetingCancellation(): void {
if (!$this->isMeetingCancellation()) {
return;
}
if ($this->isLocalOrganiser()) {
return;
}
if (!$this->isInCalendar()) {
return;
}
$listProperties = $this->proptags;
$listProperties['subject'] = PR_SUBJECT;
$listProperties['sent_representing_name'] = PR_SENT_REPRESENTING_NAME;
$listProperties['sent_representing_address_type'] = PR_SENT_REPRESENTING_ADDRTYPE;
$listProperties['sent_representing_email_address'] = PR_SENT_REPRESENTING_EMAIL_ADDRESS;
$listProperties['sent_representing_entryid'] = PR_SENT_REPRESENTING_ENTRYID;
$listProperties['sent_representing_search_key'] = PR_SENT_REPRESENTING_SEARCH_KEY;
$listProperties['rcvd_representing_name'] = PR_RCVD_REPRESENTING_NAME;
$listProperties['rcvd_representing_address_type'] = PR_RCVD_REPRESENTING_ADDRTYPE;
$listProperties['rcvd_representing_email_address'] = PR_RCVD_REPRESENTING_EMAIL_ADDRESS;
$listProperties['rcvd_representing_entryid'] = PR_RCVD_REPRESENTING_ENTRYID;
$listProperties['rcvd_representing_search_key'] = PR_RCVD_REPRESENTING_SEARCH_KEY;
$messageProps = mapi_getprops($this->message, $listProperties);
$goid = $messageProps[$this->proptags['goid']]; // GlobalID (0x3)
if (!isset($goid)) {
return;
}
$store = $this->store;
// get delegator store, if delegate is processing this cancellation
if (isset($messageProps[PR_RCVD_REPRESENTING_ENTRYID])) {
$delegatorStore = $this->getDelegatorStore($messageProps[PR_RCVD_REPRESENTING_ENTRYID], [PR_IPM_APPOINTMENT_ENTRYID]);
if (!empty($delegatorStore['store'])) {
$store = $delegatorStore['store'];
}
}
// check for calendar access
$this->ensureCalendarWriteAccess($store);
$calendarItem = $this->getCorrespondentCalendarItem(true);
$basedate = $this->getBasedateFromGlobalID($goid);
if ($calendarItem !== false) {
// if basedate is provided and we could not find the item then it could be that we are processing
// an exception so get the exception and process it
if (!empty($basedate)) {
$calendarItemProps = mapi_getprops($calendarItem, [$this->proptags['recurring']]);
if ($calendarItemProps[$this->proptags['recurring']] === true) {
$recurr = new Recurrence($store, $calendarItem);
// Set message class
$messageProps[PR_MESSAGE_CLASS] = 'IPM.Appointment';
if ($recurr->isException($basedate)) {
$recurr->modifyException($messageProps, $basedate);
}
else {
$recurr->createException($messageProps, $basedate);
}
}
}
else {
// set the properties of the cancellation object
mapi_setprops($calendarItem, $messageProps);
}
mapi_savechanges($calendarItem);
}
}
/**
* Process an incoming meeting forward notification (MS-OXOCAL v22.1 §3.1.4.10.2). This adds
* the attendees the meeting was forwarded to as optional attendees of the meeting in
* the organizer's calendar.
*
* @return bool true if attendees were added
*/
public function processMeetingForwardNotification(): bool {
if (!$this->isMeetingForwardNotification()) {
return false;
}
$messageprops = mapi_getprops($this->message, [
$this->proptags['goid'],
$this->proptags['forward_notification_recipients'],
PR_PARENT_ENTRYID,
PR_PROCESSED,
PR_RCVD_REPRESENTING_ENTRYID,
]);
if (!$this->isForwardNotificationToProcess($messageprops)) {
return false;
}
$calendarItem = $this->getCorrespondentCalendarItem(true);
if ($calendarItem === false) {
return false;
}
$calendarItemProps = mapi_getprops($calendarItem, [$this->proptags['responsestatus'], $this->proptags['recurring']]);
if (($calendarItemProps[$this->proptags['responsestatus']] ?? null) !== olResponseOrganized) {
return false;
}
$store = $this->resolveDelegateStoreAndCalendar($messageprops)['store'];
$this->ensureCalendarWriteAccess($store);
$basedate = $this->getBasedateFromGlobalID($messageprops[$this->proptags['goid']]);
$recurringItem = false;
$attach = false;
if (!empty($basedate) && !empty($calendarItemProps[$this->proptags['recurring']])) {
$attach = $this->getForwardedOccurrenceAttachment($store, $calendarItem, $basedate);
if (!$attach) {
return false;
}
$recurringItem = $calendarItem;
$calendarItem = mapi_attach_openobj($attach, MAPI_MODIFY);
}
$added = $this->addForwardedAttendees($calendarItem, $recurringItem, $attach, $messageprops);
$this->setProcessed();
return $added;
}
/**
* Whether a meeting forward notification is still to be processed: not once it was,
* not without the meeting's GlobalObjectId, and not the forwarder's own copy.
*/
private function isForwardNotificationToProcess(array $messageprops): bool {
if (!empty($messageprops[PR_PROCESSED]) || empty($messageprops[$this->proptags['goid']])) {
return false;
}
// the copy in the forwarder's own mailbox is not processed
foreach ([PR_IPM_SENTMAIL_ENTRYID, PR_IPM_OUTBOX_ENTRYID] as $folder) {
if (compareEntryIds($this->getBaseEntryID($folder), $messageprops[PR_PARENT_ENTRYID] ?? false)) {
return false;
}
}
return true;
}
/**
* The exception attachment of the occurrence a meeting was forwarded for, created when
* the occurrence has none yet. False when there is nothing to add the attendees to; a
* deleted occurrence and a day without one are marked processed.
*
* @param mixed $store store of the calendar item
* @param mixed $calendarItem the series in the organizer's calendar
* @param int $basedate basedate of the forwarded occurrence
*/
private function getForwardedOccurrenceAttachment(mixed $store, mixed $calendarItem, int $basedate): mixed {
$recurr = new Recurrence($store, $calendarItem);
// a deleted occurrence is never brought back
if ($recurr->isDeleteException($basedate)) {
$this->setProcessed();
return false;
}
if (!$recurr->isException($basedate)) {
$exception_props = [
$this->proptags['startdate'] => $recurr->getOccurrenceStart($basedate),
$this->proptags['duedate'] => $recurr->getOccurrenceEnd($basedate),
];
// fails when the series has no occurrence on that day
if (!$recurr->createException($exception_props, $basedate, false, $this->getMessageRecipients($calendarItem))) {
$this->setProcessed();
return false;
}
mapi_savechanges($calendarItem);
}
return $recurr->getExceptionAttachment($basedate);
}
/**
* Adds the attendees a meeting forward notification lists to the meeting or the
* occurrence, as far as they are not attendees yet.
*
* @param mixed $calendarItem the meeting, or the exception of the occurrence
* @param mixed $recurringItem the series when an occurrence is updated, else false
* @param mixed $attach the exception attachment of the occurrence, else false
* @param array $messageprops properties of the meeting forward notification
*
* @return bool true if attendees were added
*/
private function addForwardedAttendees(mixed $calendarItem, mixed $recurringItem, mixed $attach, array $messageprops): bool {
$existing = $this->getMessageRecipients($calendarItem);
$seriesRecipients = [];
// an exception without recipients of its own has those of the series
if ($recurringItem !== false && empty($existing)) {
$existing = $seriesRecipients = $this->getMessageRecipients($recurringItem);
}
$added = [];
foreach ($this->getNewForwardRecipients($existing, $this->getForwardRecipientRows($messageprops)) as $recip) {
$added[] = $this->resolveForwardRecipient($recip);
}
if (!empty($added)) {
mapi_message_modifyrecipients($calendarItem, MODRECIP_ADD, array_merge($seriesRecipients, $added));
mapi_savechanges($calendarItem);
if ($attach !== false && $recurringItem !== false) {
mapi_savechanges($attach);
mapi_savechanges($recurringItem);
}
}
return !empty($added);
}
/**
* Returns true if the corresponding calendar items exists in the celendar folder for this
* meeting request/response/cancellation.
*/
public function isInCalendar(): bool {
// @TODO check for deleted exceptions
return $this->getCorrespondentCalendarItem(false) !== false;
}
/**
* Accepts the meeting request by moving the item to the calendar
* and sending a confirmation message back to the sender. If $tentative
* is TRUE, then the item is accepted tentatively. After accepting, you
* can't use this class instance any more. The message is closed. If you
* specify TRUE for 'move', then the item is actually moved (from your
* inbox probably) to the calendar. If you don't, it is copied into
* your calendar.
*
* @param bool $tentative true if user as tentative accepted the meeting
* @param bool $sendresponse true if a response has to be sent to organizer
* @param bool $move true if the meeting request should be moved to the deleted items after processing
* @param mixed $newProposedStartTime contains starttime if user has proposed other time
* @param mixed $newProposedEndTime contains endtime if user has proposed other time
* @param false|int $basedate start of day of occurrence for which user has accepted the recurrent meeting
* @param bool $isImported true to indicate that MR is imported from .ics or .vcs file else it false.
*
* @return bool|string $entryid entryid of item which created/updated in calendar
*/
public function doAccept(bool $tentative, bool $sendresponse, bool $move, mixed $newProposedStartTime = false, mixed $newProposedEndTime = false, mixed $body = false, mixed $userAction = false, mixed $store = false, mixed $basedate = false, bool $isImported = false): bool|string {
if ($this->isLocalOrganiser()) {
return false;
}
// Remove any previous calendar items with this goid and appt id
$messageprops = mapi_getprops($this->message, [PR_ENTRYID, PR_PARENT_ENTRYID,
PR_MESSAGE_CLASS, $this->proptags['goid'], $this->proptags['updatecounter'],
PR_PROCESSED, PR_RCVD_REPRESENTING_ENTRYID, PR_SENDER_ENTRYID,
PR_SENT_REPRESENTING_ENTRYID, PR_RECEIVED_BY_ENTRYID]);
// do not process meeting requests in sent items folder
if ($this->isInSentItems($messageprops)) {
return false;
}
['store' => $store, 'calFolder' => $calFolder] = $this->resolveDelegateStoreAndCalendar($messageprops);
// check for calendar access
$this->ensureCalendarWriteAccess($store);
if ($this->isMeetingRequest($messageprops[PR_MESSAGE_CLASS]) && !$this->isRequestToProcess($messageprops, $userAction)) {
return false;
}
// Retrieve basedate from globalID, if it is not received as argument
if (empty($basedate)) {
$basedate = $this->getBasedateFromGlobalID($messageprops[$this->proptags['goid']]);
}
// set counter proposal properties in calendar item when proposing new time
$proposeNewTimeProps = $this->getCounterProposalProperties($newProposedStartTime, $newProposedEndTime);
// While sender is receiver then we have to process the meeting request as per the intended busy status
// instead of tentative, and accept the same as per the intended busystatus.
try {
if ($this->isSentToSelf($messageprops)) {
$entryid = $this->accept(false, $sendresponse, $move, $proposeNewTimeProps, $body, true, $store, $calFolder, $basedate);
}
else {
$entryid = $this->accept($tentative, $sendresponse, $move, $proposeNewTimeProps, $body, $userAction, $store, $calFolder, $basedate);
}
}
finally {
// accept() clears this once it has sent; anything left means it threw
$this->discardPendingResponse();
}
// Opt-in; by default the request mail stays in the inbox.
if ($this->removeRequestOnResponse && $entryid && $userAction && !$this->isMeetingRequest($messageprops[PR_MESSAGE_CLASS])) {
$this->removeRequestFromInbox($basedate);
}
// if we have first time processed this meeting then set PR_PROCESSED property
$this->setRequestProcessed($messageprops, $userAction, $isImported);
return $entryid;
}
private function isInSentItems(array $messageprops): bool {
$sentItemsEntryid = $this->getDefaultSentmailEntryID();
return isset($messageprops[PR_PARENT_ENTRYID]) &&
$sentItemsEntryid !== false &&
$sentItemsEntryid == $messageprops[PR_PARENT_ENTRYID];
}
/**
* Whether a meeting request is still to be processed: not an out of date one, and not
* one that is opened automatically after it or its calendar item was processed.
*
* @param array $messageprops properties of the meeting request
* @param mixed $userAction false when the request is processed automatically on opening
*/
private function isRequestToProcess(array $messageprops, mixed $userAction): bool {
// if meeting is out dated then don't process it
if ($this->isMeetingOutOfDate()) {
return false;
}
/*
* if this function is called automatically with meeting request object then there will be
* two possibilitites
* 1) meeting request is opened first time, in this case make a tentative appointment in
* recipient's calendar
* 2) after this every subsequent request to open meeting request will not do any processing
*/
if ($userAction !== false) {
return true;
}
if (isset($messageprops[PR_PROCESSED]) && $messageprops[PR_PROCESSED] === true) {
// if meeting request is already processed then don't do anything
return false;
}
// if correspondent calendar item is already processed then don't do anything
$calendarItem = $this->getCorrespondentCalendarItem();
if ($calendarItem) {
$calendarItemProps = mapi_getprops($calendarItem, [PR_PROCESSED]);
if (isset($calendarItemProps[PR_PROCESSED]) && $calendarItemProps[PR_PROCESSED] === true) {
// mark meeting-request mail as processed as well
mapi_setprops($this->message, [PR_PROCESSED => true]);
mapi_savechanges($this->message);
return false;
}
}
return true;
}
/**
* The counter proposal of an attendee who proposes another time, nothing without one.
*/
private function getCounterProposalProperties(mixed $newProposedStartTime, mixed $newProposedEndTime): array {
$proposeNewTimeProps = [];
if ($newProposedStartTime && $newProposedEndTime) {
$proposeNewTimeProps[$this->proptags['proposed_start_whole']] = $newProposedStartTime;
$proposeNewTimeProps[$this->proptags['proposed_end_whole']] = $newProposedEndTime;
$proposeNewTimeProps[$this->proptags['proposed_duration']] = round($newProposedEndTime - $newProposedStartTime) / 60;
$proposeNewTimeProps[$this->proptags['counter_proposal']] = true;
}
return $proposeNewTimeProps;
}
/**
* Whether the user received the message from themselves.
*/
private function isSentToSelf(array $messageprops): bool {
$senderEntryId = $messageprops[PR_SENT_REPRESENTING_ENTRYID] ?? $messageprops[PR_SENDER_ENTRYID];
return isset($messageprops[PR_RECEIVED_BY_ENTRYID]) && compareEntryIds($senderEntryId, $messageprops[PR_RECEIVED_BY_ENTRYID]);
}
/**
* Marks a meeting request as processed once it was processed automatically for the
* first time; an imported one is not marked, nor one that is already.
*
* @param array $messageprops properties of the message
* @param mixed $userAction false when the request is processed automatically on opening
* @param bool $isImported true for a request imported from an .ics or .vcs file
*/
private function setRequestProcessed(array $messageprops, mixed $userAction, bool $isImported): void {
if ($this->isMeetingRequest($messageprops[PR_MESSAGE_CLASS]) && $userAction === false && $isImported === false) {
if (!isset($messageprops[PR_PROCESSED]) || $messageprops[PR_PROCESSED] != true) {
// set processed flag
$this->setProcessed();
}
}
}
/**
* @param (float|mixed|true)[] $proposeNewTimeProps
* @param resource $calFolder
*
* @psalm-param array<float|mixed|true> $proposeNewTimeProps
*/
public function accept(bool $tentative, bool $sendresponse, bool $move, array $proposeNewTimeProps, mixed $body, bool $userAction, mixed $store, mixed $calFolder, mixed $basedate = false): mixed {
$messageprops = mapi_getprops($this->message);
$isDelegate = $this->isMessageFromDelegate($messageprops);
if ($sendresponse) {
// The response is built from the request, which the move below
// copies and removes, so it is prepared now. It only goes out once
// the calendar item exists: a failure in between must not leave the
// organizer with an acceptance of a meeting the attendee never got.
$this->pendingResponse = $this->createResponse($tentative ? olResponseTentative : olResponseAccepted, $proposeNewTimeProps, $body, $store, $basedate, $calFolder, true);
}
if (!$this->isMeetingRequest($messageprops[PR_MESSAGE_CLASS])) {
$entryid = $this->acceptCalendarResponse($messageprops, $tentative, $proposeNewTimeProps, $store, $basedate);
}
elseif (!empty($messageprops[$this->proptags['recurring']]) && $basedate === false) {
$entryid = $this->acceptRecurringRequest($messageprops, $tentative, $move, $userAction, $store, $calFolder, $isDelegate);
}
else {
$entryid = $this->acceptSingleRequest($messageprops, $tentative, $move, $proposeNewTimeProps, $userAction, $store, $calFolder, $basedate, $isDelegate);
}
$this->submitPendingResponse($entryid);
return $entryid;
}
/**
* Sends the response prepared by createResponse(), unless nothing was
* stored: an acceptance of a meeting that does not exist would be a lie.
*/
private function submitPendingResponse(mixed $entryid): void {
$message = $this->pendingResponse;
$this->pendingResponse = null;
if ($message === null) {
return;
}
if (empty($entryid)) {
$this->deleteOutgoingMessage($message);
return;
}
mapi_message_submitmessage($message);