Issues (203)

class.taskrequest.php (83 issues)

1
<?php
2
3
/*
4
 * SPDX-License-Identifier: AGPL-3.0-only
5
 * SPDX-FileCopyrightText: Copyright 2005-2016 Zarafa Deutschland GmbH
6
 * SPDX-FileCopyrightText: Copyright 2020-2024 grommunio GmbH
7
 */
8
9
/*
10
* In general
11
*
12
* This class never actually modifies a task item unless we receive a task request update. This means
13
* that setting all the properties to make the task item itself behave like a task request is up to the
14
* caller.
15
*
16
* The only exception to this is the generation of the TaskGlobalObjId, the unique identifier identifying
17
* this task request to both the organizer and the assignee. The globalobjectid is generated when the
18
* task request is sent via sendTaskRequest.
19
*/
20
21
/* The TaskMode value is only used for the IPM.TaskRequest items.
22
 * It must 0 (tdmtNothing) on IPM.Task items.
23
 *
24
 * It is used to indicate the type of change that is being
25
 * carried in the IPM.TaskRequest item (although this information seems
26
 * redundant due to that information already being available in PR_MESSAGE_CLASS).
27
 */
28
define('tdmtNothing', 0);			// Value in IPM.Task items
29
define('tdmtTaskReq', 1);			// Assigner -> Assignee
30
define('tdmtTaskAcc', 2);			// Assignee -> Assigner
31
define('tdmtTaskDec', 3);			// Assignee -> Assigner
32
define('tdmtTaskUpd', 4);			// Assignee -> Assigner
33
define('tdmtTaskSELF', 5);			// Assigner -> Assigner (?)
34
35
/* The TaskHistory is used to show the last action on the task
36
 * on both the assigner and the assignee's side.
37
 *
38
 * It is used in combination with 'task_assigned_time' and 'tasklastdelegate'
39
 * or 'tasklastuser' to show the information at the top of the task request in
40
 * the format 'Accepted by <user> on 01-01-2010 11:00'.
41
 */
42
define('thNone', 0);
43
define('thAccepted', 1);			// Set by assignee
44
define('thDeclined', 2);			// Set by assignee
45
define('thUpdated', 3);				// Set by assignee
46
define('thDueDateChanged', 4);
47
define('thAssigned', 5);			// Set by assigner
48
49
/* The TaskState value is used to differentiate the version of a task
50
 * in the assigner's folder and the version in the
51
 * assignee's folder. The buttons shown depend on this and
52
 * the 'taskaccepted' boolean (for the assignee)
53
 */
54
define('tdsNOM', 0);		// Got a response to a deleted task, and re-created the task for the assigner
55
define('tdsOWNNEW', 1);		// Not assigned
56
define('tdsOWN', 2);		// Assignee version
57
define('tdsACC', 3);		// Assigner version
58
define('tdsDEC', 4);		// Assigner version, but assignee declined
59
60
/* The TaskAcceptanceState is used for the assigner to indicate state */
61
define('olTaskNotDelegated', 0);
62
define('olTaskDelegationUnknown', 1); // After sending req
63
define('olTaskDelegationAccepted', 2); // After receiving accept
64
define('olTaskDelegationDeclined', 3); // After receiving decline
65
66
/* The task ownership indicates the role of the current user relative to the task. */
67
define('olNewTask', 0);
68
define('olDelegatedTask', 1);	// Task has been assigned
69
define('olOwnTask', 2);			// Task owned
70
71
/* taskmultrecips indicates whether the task request sent or received has multiple assignees or not. */
72
define('tmrNone', 0);
73
define('tmrSent', 1);		// Task has been sent to multiple assignee
74
define('tmrReceived', 2);	// Task Request received has multiple assignee
75
76
// Task icon index.
77
define('ICON_TASK_ASSIGNEE', 0x00000502);
78
define('ICON_TASK_DECLINE', 0x00000506);
79
define('ICON_TASK_ASSIGNER', 0x00000503);
80
81
class TaskRequest {
82
	private $props;
83
84
	/**
85
	 * @var string
86
	 */
87
	private $taskCommentsInfo;
88
89
	// All recipient properties
90
	public $recipProps = [
91
		PR_ENTRYID,
92
		PR_DISPLAY_NAME,
93
		PR_EMAIL_ADDRESS,
94
		PR_RECIPIENT_ENTRYID,
95
		PR_RECIPIENT_TYPE,
96
		PR_SEND_INTERNET_ENCODING,
97
		PR_SEND_RICH_INFO,
98
		PR_RECIPIENT_DISPLAY_NAME,
99
		PR_ADDRTYPE,
100
		PR_DISPLAY_TYPE,
101
		PR_RECIPIENT_TRACKSTATUS,
102
		PR_RECIPIENT_TRACKSTATUS_TIME,
103
		PR_RECIPIENT_FLAGS,
104
		PR_ROWID,
105
		PR_SEARCH_KEY,
106
	];
107
108
	/**
109
	 * Constructor.
110
	 *
111
	 * Constructs a TaskRequest object for the specified message. This can be either the task request
112
	 * message itself (in the inbox) or the task in the tasks folder, depending on the action to be performed.
113
	 *
114
	 * As a general rule, the object message passed is the object 'in view' when the user performs one of the
115
	 * actions in this class.
116
	 *
117
	 * @param resource $store   MAPI Store in which $message resides. This is also the store where the tasks folder is assumed to be in
118
	 * @param resource $message MAPI Message to which the task request refers (can be an email or a task)
119
	 * @param resource $session MAPI Session which is used to open tasks folders for delegated task requests or responses
120
	 */
121
	public function __construct(private $store, private $message, private $session) {
122
		$this->taskCommentsInfo = '';
123
124
		$properties = [];
125
		$properties["owner"] = "PT_STRING8:PSETID_Task:0x811f";
126
		$properties["updatecount"] = "PT_LONG:PSETID_Task:0x8112";
127
		$properties["taskstate"] = "PT_LONG:PSETID_Task:0x8113";
128
		$properties["taskmultrecips"] = "PT_LONG:PSETID_Task:0x8120";
129
		$properties["taskupdates"] = "PT_BOOLEAN:PSETID_Task:0x811b";
130
		$properties["tasksoc"] = "PT_BOOLEAN:PSETID_Task:0x8119";
131
		$properties["taskhistory"] = "PT_LONG:PSETID_Task:0x811a";
132
		$properties["taskmode"] = "PT_LONG:PSETID_Common:0x8518";
133
		$properties["task_goid"] = "PT_BINARY:PSETID_Common:0x8519";
134
		$properties["complete"] = "PT_BOOLEAN:PSETID_Common:" . PidLidTaskComplete;
135
		$properties["task_assigned_time"] = "PT_SYSTIME:PSETID_Task:0x8115";
136
		$properties["taskfcreator"] = "PT_BOOLEAN:PSETID_Task:0x0x811e";
137
		$properties["tasklastuser"] = "PT_STRING8:PSETID_Task:0x8122";
138
		$properties["tasklastdelegate"] = "PT_STRING8:PSETID_Task:0x8125";
139
		$properties["taskaccepted"] = "PT_BOOLEAN:PSETID_Task:0x8108";
140
		$properties["task_acceptance_state"] = "PT_LONG:PSETID_Task:0x812a";
141
		$properties["ownership"] = "PT_LONG:PSETID_Task:0x8129";
142
143
		$properties["complete"] = "PT_BOOLEAN:PSETID_Task:" . PidLidTaskComplete;
144
		$properties["datecompleted"] = "PT_SYSTIME:PSETID_Task:" . PidLidTaskDateCompleted;
145
		$properties["recurring"] = "PT_BOOLEAN:PSETID_Task:0x8126";
146
		$properties["startdate"] = "PT_SYSTIME:PSETID_Task:" . PidLidTaskStartDate;
147
		$properties["duedate"] = "PT_SYSTIME:PSETID_Task:" . PidLidTaskDueDate;
148
		$properties["status"] = "PT_LONG:PSETID_Task:" . PidLidTaskStatus;
149
		$properties["percent_complete"] = "PT_DOUBLE:PSETID_Task:" . PidLidPercentComplete;
150
		$properties["totalwork"] = "PT_LONG:PSETID_Task:0x8111";
151
		$properties["actualwork"] = "PT_LONG:PSETID_Task:0x8110";
152
		$properties["categories"] = "PT_MV_STRING8:PS_PUBLIC_STRINGS:Keywords";
153
		$properties["companies"] = "PT_MV_STRING8:PSETID_Common:0x8539";
154
		$properties["mileage"] = "PT_STRING8:PSETID_Common:0x8534";
155
		$properties["billinginformation"] = "PT_STRING8:PSETID_Common:0x8535";
156
157
		$this->props = getPropIdsFromStrings($this->store, $properties);
158
	}
159
160
	// General functions
161
162
	/**
163
	 * Returns TRUE if the message pointed to is an incoming task request and should
164
	 * therefore be replied to with doAccept or doDecline().
165
	 *
166
	 * @param mixed $messageClass message class to use for checking
167
	 *
168
	 * @return bool true if this is a task request else false
169
	 */
170
	public function isTaskRequest($messageClass = false) {
171
		if ($messageClass === false) {
172
			$props = mapi_getprops($this->message, [PR_MESSAGE_CLASS]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

172
			$props = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [PR_MESSAGE_CLASS]);
Loading history...
173
			$messageClass = $props[PR_MESSAGE_CLASS] ?? false;
174
		}
175
176
		if ($messageClass !== false && $messageClass === "IPM.TaskRequest") {
177
			return true;
178
		}
179
180
		return false;
181
	}
182
183
	/**
184
	 * Returns TRUE if the message pointed to is a returning task request response.
185
	 *
186
	 * @param mixed $messageClass message class to use for checking
187
	 *
188
	 * @return bool true if this is a task request else false
189
	 */
190
	public function isTaskRequestResponse($messageClass = false) {
191
		if ($messageClass === false) {
192
			$props = mapi_getprops($this->message, [PR_MESSAGE_CLASS]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

192
			$props = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [PR_MESSAGE_CLASS]);
Loading history...
193
			$messageClass = $props[PR_MESSAGE_CLASS] ?? false;
194
		}
195
196
		if ($messageClass !== false && str_starts_with((string) $messageClass, "IPM.TaskRequest.")) {
197
			return true;
198
		}
199
200
		return false;
201
	}
202
203
	/**
204
	 * Returns TRUE if the message pointed to is an incoming task request/response.
205
	 *
206
	 * @param array $props The MAPI properties to check message is an incoming task request/response
207
	 *
208
	 * @return bool true if this is an incoming task request/response else false
209
	 */
210
	public function isReceivedItem($props) {
211
		return $props[PR_MESSAGE_TO_ME] ?? false;
212
	}
213
214
	/**
215
	 * Gets the task associated with an IPM.TaskRequest message.
216
	 *
217
	 * If the task does not exist yet, it is created, using the attachment object in the
218
	 * task request item.
219
	 *
220
	 * @param bool $create true - try create task in user's task folder if task does not exist
221
	 *                     false - find the associated task in user's task folder
222
	 *
223
	 * @return bool|resource associated task of task request else false
224
	 */
225
	public function getAssociatedTask($create) {
226
		$props = mapi_getprops($this->message, [PR_MESSAGE_CLASS, $this->props['task_goid']]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

226
		$props = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [PR_MESSAGE_CLASS, $this->props['task_goid']]);
Loading history...
227
228
		if ($props[PR_MESSAGE_CLASS] == "IPM.Task") {
229
			// Message itself is task, so return that
230
			return $this->message;
231
		}
232
233
		$taskFolder = $this->getDefaultTasksFolder();
234
		$goid = $props[$this->props['task_goid']];
235
236
		// Find the task by looking for the task_goid
237
		$restriction = [
238
			RES_PROPERTY,
239
			[
240
				RELOP => RELOP_EQ,
241
				ULPROPTAG => $this->props['task_goid'],
242
				VALUE => $goid,
243
			],
244
		];
245
246
		$contents = mapi_folder_getcontentstable($taskFolder);
0 ignored issues
show
It seems like $taskFolder can also be of type false; however, parameter $fld of mapi_folder_getcontentstable() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

246
		$contents = mapi_folder_getcontentstable(/** @scrutinizer ignore-type */ $taskFolder);
Loading history...
247
248
		$rows = mapi_table_queryallrows($contents, [PR_ENTRYID], $restriction);
249
250
		if (empty($rows)) {
251
			// None found, create one if possible
252
			if (!$create) {
253
				return false;
254
			}
255
256
			$task = mapi_folder_createmessage($taskFolder);
0 ignored issues
show
It seems like $taskFolder can also be of type false; however, parameter $fld of mapi_folder_createmessage() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

256
			$task = mapi_folder_createmessage(/** @scrutinizer ignore-type */ $taskFolder);
Loading history...
257
258
			$sub = $this->getEmbeddedTask();
259
			mapi_copyto($sub, [], [$this->props['categories']], $task);
0 ignored issues
show
$sub of type boolean|resource is incompatible with the type resource expected by parameter $src of mapi_copyto(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

259
			mapi_copyto(/** @scrutinizer ignore-type */ $sub, [], [$this->props['categories']], $task);
Loading history...
260
261
			$senderProps = [
262
				PR_SENT_REPRESENTING_NAME,
263
				PR_SENT_REPRESENTING_EMAIL_ADDRESS,
264
				PR_SENT_REPRESENTING_ENTRYID,
265
				PR_SENT_REPRESENTING_ADDRTYPE,
266
				PR_SENT_REPRESENTING_SEARCH_KEY,
267
				PR_SENDER_NAME,
268
				PR_SENDER_EMAIL_ADDRESS,
269
				PR_SENDER_ENTRYID,
270
				PR_SENDER_ADDRTYPE,
271
				PR_SENDER_SEARCH_KEY, ];
272
273
			// Copy sender information from the e-mail
274
			$props = mapi_getprops($this->message, $senderProps);
275
			$props[PR_MESSAGE_CLASS] = 'IPM.Task';
276
			mapi_setprops($task, $props);
277
		}
278
		else {
279
			// If there are multiple, just use the first
280
			$entryid = $rows[0][PR_ENTRYID];
281
282
			$store = $this->getTaskFolderStore();
283
			$task = mapi_msgstore_openentry($store, $entryid);
0 ignored issues
show
It seems like $store can also be of type false and resource; however, parameter $store of mapi_msgstore_openentry() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

283
			$task = mapi_msgstore_openentry(/** @scrutinizer ignore-type */ $store, $entryid);
Loading history...
284
		}
285
286
		return $task;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $task returns the type resource which is incompatible with the documented return type boolean|resource.
Loading history...
287
	}
288
289
	/**
290
	 * Function which checks that if we have received a task request/response
291
	 * for an already updated task in task folder.
292
	 *
293
	 * @return bool true if task request is updated later
294
	 */
295
	public function isTaskRequestUpdated() {
296
		$props = mapi_getprops($this->message, [PR_MESSAGE_CLASS, $this->props['task_goid'], $this->props['updatecount']]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

296
		$props = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [PR_MESSAGE_CLASS, $this->props['task_goid'], $this->props['updatecount']]);
Loading history...
297
		$result = false;
298
		$associatedTask = $this->getAssociatedTask(false);
299
		if ($this->isTaskRequest($props[PR_MESSAGE_CLASS])) {
300
			if ($associatedTask) {
0 ignored issues
show
$associatedTask is of type resource, thus it always evaluated to false.
Loading history...
301
				return true;
302
			}
303
			$folder = $this->getDefaultTasksFolder();
304
			$goid = $props[$this->props['task_goid']];
305
306
			// Find the task by looking for the task_goid
307
			$restriction = [
308
				RES_PROPERTY,
309
				[
310
					RELOP => RELOP_EQ,
311
					ULPROPTAG => $this->props['task_goid'],
312
					VALUE => $goid,
313
				],
314
			];
315
316
			$table = mapi_folder_getcontentstable($folder, MAPI_DEFERRED_ERRORS | SHOW_SOFT_DELETES);
0 ignored issues
show
It seems like $folder can also be of type false; however, parameter $fld of mapi_folder_getcontentstable() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

316
			$table = mapi_folder_getcontentstable(/** @scrutinizer ignore-type */ $folder, MAPI_DEFERRED_ERRORS | SHOW_SOFT_DELETES);
Loading history...
317
			$softDeletedItems = mapi_table_queryallrows($table, [PR_ENTRYID], $restriction);
318
			if (!empty($softDeletedItems)) {
319
				return true;
320
			}
321
		}
322
323
		if ($associatedTask !== false) {
0 ignored issues
show
The condition $associatedTask !== false is always true.
Loading history...
324
			$taskItemProps = mapi_getprops($associatedTask, [$this->props['updatecount']]);
325
			/*
326
			 * if(message_counter < task_counter) task object is newer then task response (task is updated)
327
			 * if(message_counter >= task_counter) task is not updated, do normal processing
328
			 */
329
			if (isset($taskItemProps[$this->props['updatecount']], $props[$this->props['updatecount']])) {
330
				if ($props[$this->props['updatecount']] < $taskItemProps[$this->props['updatecount']]) {
331
					$result = true;
332
				}
333
			}
334
		}
335
336
		return $result;
337
	}
338
339
	// Organizer functions (called by the organizer)
340
341
	/**
342
	 * Processes a task request response, which can be any of the following:
343
	 * - Task accept (task history is marked as accepted)
344
	 * - Task decline (task history is marked as declined)
345
	 * - Task update (updates completion %, etc).
346
	 *
347
	 * @return true
348
	 */
349
	public function processTaskResponse(): bool {
350
		$messageProps = mapi_getprops($this->message, [PR_PROCESSED, $this->props["taskupdates"], PR_MESSAGE_TO_ME]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

350
		$messageProps = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [PR_PROCESSED, $this->props["taskupdates"], PR_MESSAGE_TO_ME]);
Loading history...
351
		if (isset($messageProps[PR_PROCESSED]) && $messageProps[PR_PROCESSED]) {
352
			return true;
353
		}
354
		mapi_setprops($this->message, [PR_PROCESSED => true]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_setprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

354
		mapi_setprops(/** @scrutinizer ignore-type */ $this->message, [PR_PROCESSED => true]);
Loading history...
355
		mapi_savechanges($this->message);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_savechanges(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

355
		mapi_savechanges(/** @scrutinizer ignore-type */ $this->message);
Loading history...
356
357
		// Get the embedded task information.
358
		$sub = $this->getEmbeddedTask();
359
		// OL saves the task related properties in the embedded message
360
		$subProps = mapi_getprops($sub, [$this->props["taskupdates"]]);
0 ignored issues
show
$sub of type boolean|resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

360
		$subProps = mapi_getprops(/** @scrutinizer ignore-type */ $sub, [$this->props["taskupdates"]]);
Loading history...
361
362
		// If task is updated in task folder then we don't need to process
363
		// old response
364
		if ($this->isTaskRequestUpdated()) {
365
			return true;
366
		}
367
368
		$isReceivedItem = $this->isReceivedItem($messageProps);
369
370
		$taskHistory = 0;
371
		$taskState = 0;
372
		$taskAcceptanceState = 0;
373
		$taskOwner = 0;
374
		$isCreateAssociatedTask = false;
375
		$isAllowUpdateAssociatedTask = $subProps[$this->props["taskupdates"]];
376
		$props = mapi_getprops($this->message, [PR_MESSAGE_CLASS]);
377
378
		// Set correct taskmode and taskhistory depending on response type
379
		switch ($props[PR_MESSAGE_CLASS]) {
380
			case 'IPM.TaskRequest.Accept':
381
				$taskHistory = thAccepted;
382
				$taskState = $isReceivedItem ? tdsACC : tdsOWN;
383
				$taskOwner = $isReceivedItem ? olDelegatedTask : olOwnTask;
384
				$taskAcceptanceState = $isReceivedItem ? olTaskDelegationAccepted : olTaskNotDelegated;
385
				break;
386
387
			case 'IPM.TaskRequest.Decline':
388
				$isCreateAssociatedTask = $isReceivedItem;
389
				$isAllowUpdateAssociatedTask = $isReceivedItem;
390
				$taskHistory = thDeclined;
391
				$taskState = $isReceivedItem ? tdsDEC : tdsACC;
392
				$taskOwner = $isReceivedItem ? olOwnTask : olDelegatedTask;
393
				$taskAcceptanceState = $isReceivedItem ? olTaskDelegationDeclined : olTaskDelegationUnknown;
394
				break;
395
396
			case 'IPM.TaskRequest.Update':
397
			case 'IPM.TaskRequest.Complete':
398
				$taskHistory = thUpdated;
399
				$taskState = $isReceivedItem ? tdsACC : tdsOWN;
400
				$taskAcceptanceState = olTaskNotDelegated;
401
				$taskOwner = $isReceivedItem ? olDelegatedTask : olOwnTask;
402
				break;
403
		}
404
405
		$props = [
406
			$this->props['taskhistory'] => $taskHistory,
407
			$this->props['taskstate'] => $taskState,
408
			$this->props['task_acceptance_state'] => $taskAcceptanceState,
409
			$this->props['ownership'] => $taskOwner,
410
		];
411
412
		// Get the task for this response
413
		$task = $this->getAssociatedTask($isCreateAssociatedTask);
414
		if ($task && $isAllowUpdateAssociatedTask) {
0 ignored issues
show
$task is of type resource, thus it always evaluated to false.
Loading history...
415
			// To avoid duplication of attachments in associated task. we simple remove the
416
			// all attachments from associated task.
417
			$taskAttachTable = mapi_message_getattachmenttable($task);
418
			$taskAttachments = mapi_table_queryallrows($taskAttachTable, [PR_ATTACH_NUM]);
419
			foreach ($taskAttachments as $taskAttach) {
420
				mapi_message_deleteattach($task, $taskAttach[PR_ATTACH_NUM]);
421
			}
422
423
			$ignoreProps = [
424
				$this->props['taskstate'],
425
				$this->props['taskhistory'],
426
				$this->props['taskmode'],
427
				$this->props['taskfcreator'],
428
			];
429
			// Ignore PR_ICON_INDEX when task request response
430
			// is not received item.
431
			if ($isReceivedItem === false) {
432
				$ignoreProps[] = PR_ICON_INDEX;
433
			}
434
435
			// We copy all properties except taskstate, taskhistory, taskmode and taskfcreator properties
436
			// from $sub message to $task even also we copy all attachments from $sub to $task message.
437
			mapi_copyto($sub, [], $ignoreProps, $task);
438
			$senderProps = mapi_getprops($this->message, [
439
				PR_SENDER_NAME,
440
				PR_SENDER_EMAIL_ADDRESS,
441
				PR_SENDER_ENTRYID,
442
				PR_SENDER_ADDRTYPE,
443
				PR_SENDER_SEARCH_KEY,
444
				PR_MESSAGE_DELIVERY_TIME,
445
				PR_SENT_REPRESENTING_NAME,
446
				PR_SENT_REPRESENTING_EMAIL_ADDRESS,
447
				PR_SENT_REPRESENTING_ADDRTYPE,
448
				PR_SENT_REPRESENTING_ENTRYID,
449
				PR_SENT_REPRESENTING_SEARCH_KEY, ]);
450
451
			mapi_setprops($task, $senderProps);
452
453
			// Update taskstate and task history (last action done by the assignee)
454
			mapi_setprops($task, $props);
455
456
			// Copy missing properties from embedded task
457
			$subProperties = $this->getSubProperties();
458
			$subprops = mapi_getprops($sub, $subProperties);
459
			mapi_setprops($task, $subprops);
460
461
			mapi_savechanges($task);
462
		}
463
464
		mapi_setprops($this->message, $props);
465
		mapi_savechanges($this->message);
466
467
		if ($isReceivedItem) {
468
			$this->updateSentTaskRequest();
469
		}
470
471
		return true;
472
	}
473
474
	/**
475
	 * Update the sent task request in sent items folder.
476
	 *
477
	 * @return bool
478
	 */
479
	public function updateSentTaskRequest() {
480
		$props = mapi_getprops($this->message, [
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

480
		$props = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [
Loading history...
481
			$this->props['taskhistory'],
482
			$this->props["taskstate"],
483
			$this->props["ownership"],
484
			$this->props['task_goid'],
485
			$this->props['task_acceptance_state'],
486
			$this->props["tasklastuser"],
487
			$this->props["tasklastdelegate"], ]);
488
489
		$store = $this->getDefaultStore();
490
		$storeProps = mapi_getprops($store, [PR_IPM_SENTMAIL_ENTRYID]);
0 ignored issues
show
It seems like $store can also be of type false; however, parameter $any of mapi_getprops() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

490
		$storeProps = mapi_getprops(/** @scrutinizer ignore-type */ $store, [PR_IPM_SENTMAIL_ENTRYID]);
Loading history...
491
492
		$sentFolder = mapi_msgstore_openentry($store, $storeProps[PR_IPM_SENTMAIL_ENTRYID]);
0 ignored issues
show
It seems like $store can also be of type false; however, parameter $store of mapi_msgstore_openentry() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

492
		$sentFolder = mapi_msgstore_openentry(/** @scrutinizer ignore-type */ $store, $storeProps[PR_IPM_SENTMAIL_ENTRYID]);
Loading history...
493
		if (!$sentFolder) {
0 ignored issues
show
$sentFolder is of type resource, thus it always evaluated to true.
Loading history...
494
			return false;
495
		}
496
497
		// Find the task by looking for the task_goid
498
		$restriction = [
499
			RES_PROPERTY,
500
			[
501
				RELOP => RELOP_EQ,
502
				ULPROPTAG => $this->props['task_goid'],
503
				VALUE => $props[$this->props['task_goid']],
504
			],
505
		];
506
507
		$contentsTable = mapi_folder_getcontentstable($sentFolder);
508
509
		$rows = mapi_table_queryallrows($contentsTable, [PR_ENTRYID], $restriction);
510
511
		if (!empty($rows)) {
512
			foreach ($rows as $row) {
513
				$sentTaskRequest = mapi_msgstore_openentry($store, $row[PR_ENTRYID]);
514
				mapi_setprops($sentTaskRequest, $props);
515
				mapi_setprops($sentTaskRequest, [PR_PROCESSED => true]);
516
				mapi_savechanges($sentTaskRequest);
517
			}
518
		}
519
520
		return true;
521
	}
522
523
	/**
524
	 * Creates a new message in the current user's outbox and submits it.
525
	 *
526
	 * Takes the task passed in the constructor as the task to be sent; recipient should
527
	 * be pre-existing. The task request will be sent to all recipients.
528
	 *
529
	 * @param string $prefix
530
	 *
531
	 * @return true
532
	 */
533
	public function sendTaskRequest($prefix): bool {
534
		// Generate a TaskGlobalObjectId
535
		$taskid = $this->createTGOID();
536
		$messageprops = mapi_getprops($this->message, [PR_SUBJECT]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

536
		$messageprops = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [PR_SUBJECT]);
Loading history...
537
538
		// Set properties on Task Request
539
		mapi_setprops($this->message, [
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_setprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

539
		mapi_setprops(/** @scrutinizer ignore-type */ $this->message, [
Loading history...
540
			$this->props['task_goid'] => $taskid, // our new task_goid
541
			$this->props['taskstate'] => tdsACC, // state for our outgoing request
542
			$this->props['taskmode'] => tdmtNothing, // we're not sending a change
543
			$this->props['updatecount'] => 2, // version 2 (no idea)
544
			$this->props['task_acceptance_state'] => olTaskDelegationUnknown, // no reply yet
545
			$this->props['ownership'] => olDelegatedTask, // Task has been assigned
546
			$this->props['taskhistory'] => thAssigned, // Task has been assigned
547
			PR_CONVERSATION_TOPIC => $messageprops[PR_SUBJECT],
548
			PR_ICON_INDEX => ICON_TASK_ASSIGNER,
549
		]);
550
		$this->setLastUser();
551
		$this->setOwnerForAssignor();
552
		mapi_savechanges($this->message);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_savechanges(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

552
		mapi_savechanges(/** @scrutinizer ignore-type */ $this->message);
Loading history...
553
554
		// Create outgoing task request message
555
		$outgoing = $this->createOutgoingMessage();
556
557
		// No need to copy PR_ICON_INDEX and  PR_SENT_* information in to outgoing message.
558
		$ignoreProps = [PR_ICON_INDEX, PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_EMAIL_ADDRESS, PR_SENT_REPRESENTING_ADDRTYPE, PR_SENT_REPRESENTING_ENTRYID, PR_SENT_REPRESENTING_SEARCH_KEY];
559
		mapi_copyto($this->message, [], $ignoreProps, $outgoing);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $src of mapi_copyto(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

559
		mapi_copyto(/** @scrutinizer ignore-type */ $this->message, [], $ignoreProps, $outgoing);
Loading history...
560
561
		// Make it a task request, and put it in sent items after it is sent
562
		mapi_setprops($outgoing, [
563
			PR_MESSAGE_CLASS => "IPM.TaskRequest", // class is task request
564
			$this->props['taskstate'] => tdsOWN, // for the recipient he is the task owner
565
			$this->props['taskmode'] => tdmtTaskReq, // for the recipient it's a request
566
			$this->props['updatecount'] => 1, // version 2 is in the attachment
567
			PR_SUBJECT_PREFIX => $prefix,
568
			PR_SUBJECT => $prefix . $messageprops[PR_SUBJECT],
569
		]);
570
571
		$attach = mapi_message_createattach($outgoing);
572
		mapi_setprops($attach, [
573
			PR_ATTACH_METHOD => ATTACH_EMBEDDED_MSG,
574
			PR_ATTACHMENT_HIDDEN => true,
575
			PR_DISPLAY_NAME => $messageprops[PR_SUBJECT], ]);
576
577
		$sub = mapi_attach_openproperty($attach, PR_ATTACH_DATA_OBJ, IID_IMessage, 0, MAPI_MODIFY | MAPI_CREATE);
0 ignored issues
show
The function mapi_attach_openproperty was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

577
		$sub = /** @scrutinizer ignore-call */ mapi_attach_openproperty($attach, PR_ATTACH_DATA_OBJ, IID_IMessage, 0, MAPI_MODIFY | MAPI_CREATE);
Loading history...
578
579
		mapi_copyto($this->message, [], [], $sub);
580
		mapi_setprops($sub, [PR_MESSAGE_CLASS => 'IPM.Task']);
581
582
		mapi_savechanges($sub);
583
584
		mapi_savechanges($attach);
585
586
		mapi_savechanges($outgoing);
587
		mapi_message_submitmessage($outgoing);
588
589
		return true;
590
	}
591
592
	// Assignee functions (called by the assignee)
593
594
	/**
595
	 * Updates task version counter.
596
	 *
597
	 * Must be called before each update to increase counter.
598
	 */
599
	public function updateTaskRequest(): void {
600
		$messageprops = mapi_getprops($this->message, [$this->props['updatecount']]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

600
		$messageprops = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [$this->props['updatecount']]);
Loading history...
601
602
		if (isset($messageprops)) {
603
			++$messageprops[$this->props['updatecount']];
604
		}
605
		else {
606
			$messageprops[$this->props['updatecount']] = 1;
607
		}
608
609
		mapi_setprops($this->message, $messageprops);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_setprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

609
		mapi_setprops(/** @scrutinizer ignore-type */ $this->message, $messageprops);
Loading history...
610
	}
611
612
	/**
613
	 * Processes a task request.
614
	 *
615
	 * Message passed should be an IPM.TaskRequest message. The task request is then processed to create
616
	 * the task in the tasks folder if needed.
617
	 *
618
	 * @return bool
619
	 */
620
	public function processTaskRequest() {
621
		if (!$this->isTaskRequest()) {
622
			return false;
623
		}
624
		$messageProps = mapi_getprops($this->message, [PR_PROCESSED, $this->props["taskupdates"], PR_MESSAGE_TO_ME]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

624
		$messageProps = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [PR_PROCESSED, $this->props["taskupdates"], PR_MESSAGE_TO_ME]);
Loading history...
625
		if (isset($messageProps[PR_PROCESSED]) && $messageProps[PR_PROCESSED]) {
626
			return true;
627
		}
628
629
		// if task is updated in task folder then we don't need to process
630
		// old request.
631
		if ($this->isTaskRequestUpdated()) {
632
			return true;
633
		}
634
635
		$isReceivedItem = $this->isReceivedItem($messageProps);
636
637
		$props = [];
638
		$props[PR_PROCESSED] = true;
639
		$props[$this->props["taskstate"]] = $isReceivedItem ? tdsOWN : tdsACC;
640
		$props[$this->props["ownership"]] = $isReceivedItem ? olOwnTask : olDelegatedTask;
641
642
		mapi_setprops($this->message, $props);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_setprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

642
		mapi_setprops(/** @scrutinizer ignore-type */ $this->message, $props);
Loading history...
643
		mapi_savechanges($this->message);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_savechanges(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

643
		mapi_savechanges(/** @scrutinizer ignore-type */ $this->message);
Loading history...
644
645
		// Don't create associated task in task folder if "taskupdates" is not true.
646
		if (!$isReceivedItem && !$messageProps[$this->props["taskupdates"]]) {
647
			return true;
648
		}
649
		// create an associated task in task folder while
650
		// reading/loading task request on client side.
651
		$task = $this->getAssociatedTask(true);
652
653
		$taskProps = mapi_getprops($task, [$this->props['taskmultrecips']]);
654
		$taskProps[$this->props["taskstate"]] = $isReceivedItem ? tdsOWN : tdsACC;
655
		$taskProps[$this->props["taskhistory"]] = thAssigned;
656
		$taskProps[$this->props["taskmode"]] = tdmtNothing;
657
		$taskProps[$this->props["taskaccepted"]] = false;
658
		$taskProps[$this->props["taskfcreator"]] = false;
659
		$taskProps[$this->props["ownership"]] = $isReceivedItem ? olOwnTask : olDelegatedTask;
660
		$taskProps[$this->props["task_acceptance_state"]] = olTaskNotDelegated;
661
		$taskProps[PR_ICON_INDEX] = ICON_TASK_ASSIGNEE;
662
663
		mapi_setprops($task, $taskProps);
664
		$this->setAssignorInRecipients($task);
665
666
		mapi_savechanges($task);
667
668
		return true;
669
	}
670
671
	/**
672
	 * Accepts a task request and sends the response.
673
	 *
674
	 * Message passed should be an IPM.Task (eg the task from getAssociatedTask())
675
	 *
676
	 * Copies the task to the user's task folder, sets it to accepted, and sends the acceptation
677
	 * message back to the organizer. The caller is responsible for removing the message.
678
	 *
679
	 * @return array|false PR_ENTRYID, PR_STORE_ENTRYID and PR_PARENT_ENTRYID of the task
680
	 */
681
	public function doAccept() {
682
		$prefix = _("Task Accepted:") . " ";
683
		$messageProps = mapi_getprops($this->message, [PR_MESSAGE_CLASS, $this->props['taskstate']]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

683
		$messageProps = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [PR_MESSAGE_CLASS, $this->props['taskstate']]);
Loading history...
684
685
		if (!isset($messageProps[$this->props['taskstate']]) || $messageProps[$this->props['taskstate']] != tdsOWN) {
686
			// Can only accept assignee task
687
			return false;
688
		}
689
690
		$this->setLastUser();
691
		$this->updateTaskRequest();
692
693
		$props = [
694
			$this->props['taskhistory'] => thAccepted,
695
			$this->props['task_assigned_time'] => time(),
696
			$this->props['taskaccepted'] => true,
697
			$this->props['task_acceptance_state'] => olTaskNotDelegated, ];
698
699
		// Message is TaskRequest then update the associated task as well.
700
		if ($this->isTaskRequest($messageProps[PR_MESSAGE_CLASS])) {
701
			$task = $this->getAssociatedTask(false);
702
			if ($task) {
0 ignored issues
show
$task is of type resource, thus it always evaluated to false.
Loading history...
703
				mapi_setprops($task, $props);
704
				mapi_savechanges($task);
705
			}
706
		}
707
708
		// Set as accepted
709
		mapi_setprops($this->message, $props);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_setprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

709
		mapi_setprops(/** @scrutinizer ignore-type */ $this->message, $props);
Loading history...
710
711
		// As we copy the all properties from received message we need to remove following
712
		// properties from accept response.
713
		mapi_deleteprops($this->message, [PR_MESSAGE_RECIP_ME, PR_MESSAGE_TO_ME, PR_MESSAGE_CC_ME, PR_PROCESSED]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_deleteprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

713
		mapi_deleteprops(/** @scrutinizer ignore-type */ $this->message, [PR_MESSAGE_RECIP_ME, PR_MESSAGE_TO_ME, PR_MESSAGE_CC_ME, PR_PROCESSED]);
Loading history...
714
715
		mapi_savechanges($this->message);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_savechanges(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

715
		mapi_savechanges(/** @scrutinizer ignore-type */ $this->message);
Loading history...
716
717
		$this->sendResponse(tdmtTaskAcc, $prefix);
718
719
		return $this->deleteReceivedTR();
720
	}
721
722
	/**
723
	 * Declines a task request and sends the response.
724
	 *
725
	 * Passed message must be a task request message, ie isTaskRequest() must return TRUE.
726
	 *
727
	 * Sends the decline message back to the organizer. The caller is responsible for removing the message.
728
	 *
729
	 * @return array|false TRUE on success, FALSE on failure
730
	 */
731
	public function doDecline() {
732
		$prefix = _("Task Declined:") . " ";
733
		$messageProps = mapi_getprops($this->message, [$this->props['taskstate']]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

733
		$messageProps = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [$this->props['taskstate']]);
Loading history...
734
735
		if (!isset($messageProps[$this->props['taskstate']]) || $messageProps[$this->props['taskstate']] != tdsOWN) {
736
			return false; // Can only decline assignee task
737
		}
738
739
		$this->setLastUser();
740
		$this->updateTaskRequest();
741
742
		// Set as declined
743
		mapi_setprops($this->message, [
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_setprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

743
		mapi_setprops(/** @scrutinizer ignore-type */ $this->message, [
Loading history...
744
			$this->props['taskhistory'] => thDeclined,
745
			$this->props['task_acceptance_state'] => olTaskDelegationDeclined,
746
		]);
747
		mapi_deleteprops($this->message, [PR_MESSAGE_RECIP_ME, PR_MESSAGE_TO_ME, PR_MESSAGE_CC_ME, PR_PROCESSED]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_deleteprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

747
		mapi_deleteprops(/** @scrutinizer ignore-type */ $this->message, [PR_MESSAGE_RECIP_ME, PR_MESSAGE_TO_ME, PR_MESSAGE_CC_ME, PR_PROCESSED]);
Loading history...
748
		mapi_savechanges($this->message);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_savechanges(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

748
		mapi_savechanges(/** @scrutinizer ignore-type */ $this->message);
Loading history...
749
750
		$this->sendResponse(tdmtTaskDec, $prefix);
751
752
		// Delete the associated task when task request is declined by the assignee.
753
		$task = $this->getAssociatedTask(false);
754
		if ($task) {
0 ignored issues
show
$task is of type resource, thus it always evaluated to false.
Loading history...
755
			$taskFolder = $this->getDefaultTasksFolder();
756
			$props = mapi_getprops($task, [PR_ENTRYID]);
757
			mapi_folder_deletemessages($taskFolder, [$props[PR_ENTRYID]]);
758
		}
759
760
		return $this->deleteReceivedTR();
761
	}
762
763
	/**
764
	 * Sends an update of the task if requested, and sends the Status-On-Completion report if complete and requested.
765
	 *
766
	 * If no updates were requested from the organizer, this function does nothing.
767
	 *
768
	 * @return bool TRUE if the update succeeded, FALSE otherwise
769
	 */
770
	public function doUpdate() {
771
		$messageProps = mapi_getprops($this->message, [$this->props['taskstate'], PR_SUBJECT]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

771
		$messageProps = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [$this->props['taskstate'], PR_SUBJECT]);
Loading history...
772
773
		if (!isset($messageProps[$this->props['taskstate']]) || $messageProps[$this->props['taskstate']] != tdsOWN) {
774
			return false; // Can only update assignee task
775
		}
776
777
		$this->setLastUser();
778
		$this->updateTaskRequest();
779
780
		// Set as updated
781
		mapi_setprops($this->message, [$this->props['taskhistory'] => thUpdated]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_setprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

781
		mapi_setprops(/** @scrutinizer ignore-type */ $this->message, [$this->props['taskhistory'] => thUpdated]);
Loading history...
782
783
		mapi_savechanges($this->message);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_savechanges(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

783
		mapi_savechanges(/** @scrutinizer ignore-type */ $this->message);
Loading history...
784
785
		$props = mapi_getprops($this->message, [$this->props['taskupdates'], $this->props['tasksoc'], $this->props['recurring'], $this->props['complete']]);
786
		if (!$props[$this->props['complete']] && $props[$this->props['taskupdates']] && !(isset($props[$this->props['recurring']]) && $props[$this->props['recurring']])) {
787
			$this->sendResponse(tdmtTaskUpd, _("Task Updated:") . " ");
788
		}
789
		elseif ($props[$this->props['complete']]) {
790
			$this->sendResponse(tdmtTaskUpd, _("Task Completed:") . " ");
791
		}
792
793
		return true;
794
	}
795
796
	/**
797
	 * Gets the store associated with the task.
798
	 *
799
	 * Normally this will just open the store that the processed message is in. However, if the message is opened
800
	 * by a delegate, this function opens the store that the message was delegated from.
801
	 */
802
	public function getTaskFolderStore() {
803
		$ownerentryid = false;
804
805
		$rcvdprops = mapi_getprops($this->message, [PR_RCVD_REPRESENTING_ENTRYID]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

805
		$rcvdprops = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [PR_RCVD_REPRESENTING_ENTRYID]);
Loading history...
806
		if (isset($rcvdprops[PR_RCVD_REPRESENTING_ENTRYID])) {
807
			$ownerentryid = $rcvdprops[PR_RCVD_REPRESENTING_ENTRYID];
808
		}
809
810
		if (!$ownerentryid) {
811
			$store = $this->store;
812
		}
813
		else {
814
			$ab = mapi_openaddressbook($this->session);
0 ignored issues
show
$this->session of type resource is incompatible with the type resource expected by parameter $session of mapi_openaddressbook(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

814
			$ab = mapi_openaddressbook(/** @scrutinizer ignore-type */ $this->session);
Loading history...
815
			if (!$ab) {
0 ignored issues
show
$ab is of type resource, thus it always evaluated to true.
Loading history...
816
				return false;
817
			}
818
819
			$mailuser = mapi_ab_openentry($ab, $ownerentryid);
820
			if (!$mailuser) {
0 ignored issues
show
$mailuser is of type resource, thus it always evaluated to true.
Loading history...
821
				return false;
822
			}
823
824
			$mailuserprops = mapi_getprops($mailuser, [PR_EMAIL_ADDRESS]);
825
			if (!isset($mailuserprops[PR_EMAIL_ADDRESS])) {
826
				return false;
827
			}
828
829
			$storeid = mapi_msgstore_createentryid($this->store, $mailuserprops[PR_EMAIL_ADDRESS]);
0 ignored issues
show
$this->store of type resource is incompatible with the type resource expected by parameter $store of mapi_msgstore_createentryid(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

829
			$storeid = mapi_msgstore_createentryid(/** @scrutinizer ignore-type */ $this->store, $mailuserprops[PR_EMAIL_ADDRESS]);
Loading history...
830
831
			$store = mapi_openmsgstore($this->session, $storeid);
0 ignored issues
show
$this->session of type resource is incompatible with the type resource expected by parameter $ses of mapi_openmsgstore(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

831
			$store = mapi_openmsgstore(/** @scrutinizer ignore-type */ $this->session, $storeid);
Loading history...
832
		}
833
834
		return $store;
835
	}
836
837
	/**
838
	 * Opens the default task folder for the current user, or the specified user if passed.
839
	 */
840
	public function getDefaultTasksFolder() {
841
		$store = $this->getTaskFolderStore();
842
843
		$inbox = mapi_msgstore_getreceivefolder($store);
0 ignored issues
show
It seems like $store can also be of type false and resource; however, parameter $store of mapi_msgstore_getreceivefolder() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

843
		$inbox = mapi_msgstore_getreceivefolder(/** @scrutinizer ignore-type */ $store);
Loading history...
844
		$inboxprops = mapi_getprops($inbox, [PR_IPM_TASK_ENTRYID]);
845
		if (!isset($inboxprops[PR_IPM_TASK_ENTRYID])) {
846
			return false;
847
		}
848
849
		return mapi_msgstore_openentry($store, $inboxprops[PR_IPM_TASK_ENTRYID]);
0 ignored issues
show
It seems like $store can also be of type false and resource; however, parameter $store of mapi_msgstore_openentry() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

849
		return mapi_msgstore_openentry(/** @scrutinizer ignore-type */ $store, $inboxprops[PR_IPM_TASK_ENTRYID]);
Loading history...
850
	}
851
852
	/**
853
	 * Prepares the sent representing properties from given MAPI store.
854
	 *
855
	 * @param mixed $store MAPI store object
856
	 *
857
	 * @return array[][][][][]|false if store is not mail box owner entryid then return false else prepare the sent representing props and return it
858
	 *
859
	 * @psalm-return array<array<array<array<array<array<never, never>>>>>>|false
860
	 */
861
	public function getSentReprProps($store) {
862
		$storeprops = mapi_getprops($store, [PR_MAILBOX_OWNER_ENTRYID]);
863
		if (!isset($storeprops[PR_MAILBOX_OWNER_ENTRYID])) {
864
			return false;
865
		}
866
867
		$ab = mapi_openaddressbook($this->session);
0 ignored issues
show
$this->session of type resource is incompatible with the type resource expected by parameter $session of mapi_openaddressbook(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

867
		$ab = mapi_openaddressbook(/** @scrutinizer ignore-type */ $this->session);
Loading history...
868
		$mailuser = mapi_ab_openentry($ab, $storeprops[PR_MAILBOX_OWNER_ENTRYID]);
869
		$mailuserprops = mapi_getprops($mailuser, [PR_ADDRTYPE, PR_EMAIL_ADDRESS, PR_DISPLAY_NAME, PR_SEARCH_KEY, PR_ENTRYID]);
870
871
		$props = [];
872
		$props[PR_SENT_REPRESENTING_ADDRTYPE] = $mailuserprops[PR_ADDRTYPE];
873
		$props[PR_SENT_REPRESENTING_EMAIL_ADDRESS] = $mailuserprops[PR_EMAIL_ADDRESS];
874
		$props[PR_SENT_REPRESENTING_NAME] = $mailuserprops[PR_DISPLAY_NAME];
875
		$props[PR_SENT_REPRESENTING_SEARCH_KEY] = $mailuserprops[PR_SEARCH_KEY];
876
		$props[PR_SENT_REPRESENTING_ENTRYID] = $mailuserprops[PR_ENTRYID];
877
878
		return $props;
879
	}
880
881
	/**
882
	 * Creates an outgoing message based on the passed message - will set delegate information
883
	 * and sent mail folder.
884
	 */
885
	public function createOutgoingMessage() {
886
		// Open our default store for this user (that's the only store we can submit in)
887
		$store = $this->getDefaultStore();
888
		$storeprops = mapi_getprops($store, [PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID]);
0 ignored issues
show
It seems like $store can also be of type false; however, parameter $any of mapi_getprops() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

888
		$storeprops = mapi_getprops(/** @scrutinizer ignore-type */ $store, [PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID]);
Loading history...
889
890
		$outbox = mapi_msgstore_openentry($store, $storeprops[PR_IPM_OUTBOX_ENTRYID]);
0 ignored issues
show
It seems like $store can also be of type false; however, parameter $store of mapi_msgstore_openentry() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

890
		$outbox = mapi_msgstore_openentry(/** @scrutinizer ignore-type */ $store, $storeprops[PR_IPM_OUTBOX_ENTRYID]);
Loading history...
891
		if (!$outbox) {
0 ignored issues
show
$outbox is of type resource, thus it always evaluated to true.
Loading history...
892
			return false;
893
		}
894
895
		$outgoing = mapi_folder_createmessage($outbox);
896
		if (!$outgoing) {
0 ignored issues
show
$outgoing is of type resource, thus it always evaluated to true.
Loading history...
897
			return false;
898
		}
899
900
		// Set SENT_REPRESENTING in case we're sending as a delegate
901
		$ownerstore = $this->getTaskFolderStore();
902
		$sentreprprops = $this->getSentReprProps($ownerstore);
903
		mapi_setprops($outgoing, $sentreprprops);
0 ignored issues
show
$sentreprprops of type false is incompatible with the type array expected by parameter $propvals of mapi_setprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

903
		mapi_setprops($outgoing, /** @scrutinizer ignore-type */ $sentreprprops);
Loading history...
904
905
		mapi_setprops($outgoing, [PR_SENTMAIL_ENTRYID => $storeprops[PR_IPM_SENTMAIL_ENTRYID]]);
906
907
		return $outgoing;
908
	}
909
910
	/**
911
	 * Sends a response message (from assignee back to organizer).
912
	 *
913
	 * @param int   $type   Type of response (tdmtTaskAcc, tdmtTaskDec, tdmtTaskUpd)
914
	 * @param mixed $prefix
915
	 *
916
	 * @return bool TRUE on success
917
	 */
918
	public function sendResponse($type, $prefix) {
919
		// Create a message in our outbox
920
		$outgoing = $this->createOutgoingMessage();
921
		$messageprops = mapi_getprops($this->message, [PR_CONVERSATION_TOPIC, PR_MESSAGE_CLASS, $this->props['complete']]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

921
		$messageprops = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [PR_CONVERSATION_TOPIC, PR_MESSAGE_CLASS, $this->props['complete']]);
Loading history...
922
923
		$attach = mapi_message_createattach($outgoing);
924
		mapi_setprops($attach, [PR_ATTACH_METHOD => ATTACH_EMBEDDED_MSG, PR_DISPLAY_NAME => $messageprops[PR_CONVERSATION_TOPIC], PR_ATTACHMENT_HIDDEN => true]);
925
		$sub = mapi_attach_openproperty($attach, PR_ATTACH_DATA_OBJ, IID_IMessage, 0, MAPI_CREATE | MAPI_MODIFY);
0 ignored issues
show
The function mapi_attach_openproperty was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

925
		$sub = /** @scrutinizer ignore-call */ mapi_attach_openproperty($attach, PR_ATTACH_DATA_OBJ, IID_IMessage, 0, MAPI_CREATE | MAPI_MODIFY);
Loading history...
926
927
		$message = !$this->isTaskRequest() ? $this->message : $this->getAssociatedTask(false);
928
929
		$ignoreProps = [PR_ICON_INDEX, $this->props["categories"], PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_EMAIL_ADDRESS, PR_SENT_REPRESENTING_ADDRTYPE, PR_SENT_REPRESENTING_ENTRYID, PR_SENT_REPRESENTING_SEARCH_KEY];
930
931
		mapi_copyto($message, [], $ignoreProps, $outgoing);
0 ignored issues
show
$message of type resource is incompatible with the type resource expected by parameter $src of mapi_copyto(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

931
		mapi_copyto(/** @scrutinizer ignore-type */ $message, [], $ignoreProps, $outgoing);
Loading history...
932
		mapi_copyto($message, [], [], $sub);
933
934
		if (!$this->setRecipientsForResponse($outgoing, $type)) {
935
			return false;
936
		}
937
938
		$props = [];
939
940
		switch ($type) {
941
			case tdmtTaskAcc:
942
				$props[PR_MESSAGE_CLASS] = "IPM.TaskRequest.Accept";
943
				mapi_setprops($sub, [PR_ICON_INDEX => ICON_TASK_ASSIGNER]);
944
				break;
945
946
			case tdmtTaskDec:
947
				$props[PR_MESSAGE_CLASS] = "IPM.TaskRequest.Decline";
948
				mapi_setprops($sub, [PR_ICON_INDEX => ICON_TASK_DECLINE]);
949
				break;
950
951
			case tdmtTaskUpd:
952
				mapi_setprops($sub, [PR_ICON_INDEX => ICON_TASK_ASSIGNER]);
953
				if ($messageprops[$this->props['complete']]) {
954
					$props[PR_MESSAGE_CLASS] = "IPM.TaskRequest.Complete";
955
				}
956
				else {
957
					$props[PR_MESSAGE_CLASS] = "IPM.TaskRequest.Update";
958
				}
959
960
				break;
961
		}
962
963
		mapi_savechanges($sub);
964
		mapi_savechanges($attach);
965
966
		$props[PR_SUBJECT] = $prefix . $messageprops[PR_CONVERSATION_TOPIC];
967
		$props[$this->props['taskmode']] = $type;
968
		$props[$this->props['task_assigned_time']] = time();
969
970
		mapi_setprops($outgoing, $props);
971
972
		// taskCommentsInfo contains some comments which added by assignee while
973
		// edit response before sending task response.
974
		if ($this->taskCommentsInfo != '') {
975
			$comments = $this->getTaskCommentsInfo();
976
			$stream = mapi_openproperty($outgoing, PR_BODY, IID_IStream, STGM_TRANSACTED, MAPI_CREATE | MAPI_MODIFY);
977
			mapi_stream_setsize($stream, strlen($comments));
978
			mapi_stream_write($stream, $comments);
979
			mapi_stream_commit($stream);
980
		}
981
982
		mapi_savechanges($outgoing);
983
		mapi_message_submitmessage($outgoing);
984
985
		return true;
986
	}
987
988
	public function getDefaultStore() {
989
		$table = mapi_getmsgstorestable($this->session);
0 ignored issues
show
$this->session of type resource is incompatible with the type resource expected by parameter $session of mapi_getmsgstorestable(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

989
		$table = mapi_getmsgstorestable(/** @scrutinizer ignore-type */ $this->session);
Loading history...
990
		$rows = mapi_table_queryallrows($table, [PR_DEFAULT_STORE, PR_ENTRYID]);
991
992
		foreach ($rows as $row) {
993
			if ($row[PR_DEFAULT_STORE]) {
994
				return mapi_openmsgstore($this->session, $row[PR_ENTRYID]);
0 ignored issues
show
$this->session of type resource is incompatible with the type resource expected by parameter $ses of mapi_openmsgstore(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

994
				return mapi_openmsgstore(/** @scrutinizer ignore-type */ $this->session, $row[PR_ENTRYID]);
Loading history...
995
			}
996
		}
997
998
		return false;
999
	}
1000
1001
	/**
1002
	 * Creates a new TaskGlobalObjId.
1003
	 *
1004
	 * Just 16 bytes of random data
1005
	 */
1006
	public function createTGOID(): string {
1007
		$goid = "";
1008
		for ($i = 0; $i < 16; ++$i) {
1009
			$goid .= chr(random_int(0, 255));
1010
		}
1011
1012
		return $goid;
1013
	}
1014
1015
	/**
1016
	 * Gets the embedded task of task request. Further used to
1017
	 * create/update associated task of assigner/assignee.
1018
	 *
1019
	 * @return bool|resource embedded task if found else false
1020
	 */
1021
	public function getEmbeddedTask() {
1022
		$task = false;
1023
		$goid = mapi_getprops($this->message, [$this->props["task_goid"]]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1023
		$goid = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [$this->props["task_goid"]]);
Loading history...
1024
		$attachmentTable = mapi_message_getattachmenttable($this->message);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $msg of mapi_message_getattachmenttable(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1024
		$attachmentTable = mapi_message_getattachmenttable(/** @scrutinizer ignore-type */ $this->message);
Loading history...
1025
		$restriction = [RES_PROPERTY,
1026
			[RELOP => RELOP_EQ,
1027
				ULPROPTAG => PR_ATTACH_METHOD,
1028
				VALUE => ATTACH_EMBEDDED_MSG, ],
1029
		];
1030
		$rows = mapi_table_queryallrows($attachmentTable, [PR_ATTACH_NUM], $restriction);
1031
1032
		if (empty($rows)) {
1033
			return $task;
1034
		}
1035
1036
		foreach ($rows as $row) {
1037
			try {
1038
				$attach = mapi_message_openattach($this->message, $row[PR_ATTACH_NUM]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $msg of mapi_message_openattach(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1038
				$attach = mapi_message_openattach(/** @scrutinizer ignore-type */ $this->message, $row[PR_ATTACH_NUM]);
Loading history...
1039
				$task = mapi_attach_openobj($attach);
1040
			}
1041
			catch (MAPIException) {
1042
				continue;
1043
			}
1044
1045
			$taskGoid = mapi_getprops($task, [$this->props["task_goid"]]);
1046
			if ($goid[$this->props["task_goid"]] === $taskGoid[$this->props["task_goid"]]) {
1047
				mapi_setprops($attach, [PR_ATTACHMENT_HIDDEN => true]);
1048
				mapi_savechanges($attach);
1049
				mapi_savechanges($this->message);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_savechanges(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1049
				mapi_savechanges(/** @scrutinizer ignore-type */ $this->message);
Loading history...
1050
				break;
1051
			}
1052
		}
1053
1054
		return $task;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $task also could return the type resource which is incompatible with the documented return type boolean|resource.
Loading history...
1055
	}
1056
1057
	/**
1058
	 * Sets the user name who has last used this task. Update the
1059
	 * tasklastdelegate and task_assigned_time.
1060
	 */
1061
	public function setLastUser(): void {
1062
		$delegatestore = $this->getDefaultStore();
1063
		$taskstore = $this->getTaskFolderStore();
1064
1065
		$delegateprops = mapi_getprops($delegatestore, [PR_MAILBOX_OWNER_NAME]);
0 ignored issues
show
It seems like $delegatestore can also be of type false; however, parameter $any of mapi_getprops() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1065
		$delegateprops = mapi_getprops(/** @scrutinizer ignore-type */ $delegatestore, [PR_MAILBOX_OWNER_NAME]);
Loading history...
1066
		$taskprops = mapi_getprops($taskstore, [PR_MAILBOX_OWNER_NAME]);
0 ignored issues
show
It seems like $taskstore can also be of type false and resource; however, parameter $any of mapi_getprops() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1066
		$taskprops = mapi_getprops(/** @scrutinizer ignore-type */ $taskstore, [PR_MAILBOX_OWNER_NAME]);
Loading history...
1067
1068
		// The owner of the task
1069
		$username = $delegateprops[PR_MAILBOX_OWNER_NAME];
1070
		// This is me (the one calling the script)
1071
		$delegate = $taskprops[PR_MAILBOX_OWNER_NAME];
1072
1073
		if ($this->isTaskRequest()) {
1074
			$task = $this->getAssociatedTask(false);
1075
			mapi_setprops($task, [
0 ignored issues
show
$task of type resource is incompatible with the type resource expected by parameter $any of mapi_setprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1075
			mapi_setprops(/** @scrutinizer ignore-type */ $task, [
Loading history...
1076
				$this->props["tasklastuser"] => $username,
1077
				$this->props["tasklastdelegate"] => $delegate,
1078
				$this->props['task_assigned_time'] => time(),
1079
			]);
1080
			mapi_savechanges($task);
0 ignored issues
show
$task of type resource is incompatible with the type resource expected by parameter $any of mapi_savechanges(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1080
			mapi_savechanges(/** @scrutinizer ignore-type */ $task);
Loading history...
1081
		}
1082
		mapi_setprops($this->message, [
1083
			$this->props["tasklastuser"] => $username,
1084
			$this->props["tasklastdelegate"] => $delegate,
1085
			$this->props['task_assigned_time'] => time(),
1086
		]);
1087
	}
1088
1089
	/**
1090
	 * Sets assignee as owner in the assignor's copy of task.
1091
	 * Assignee becomes the owner when a user/assignor assigns any task to someone.
1092
	 * There can be more than one assignee.
1093
	 */
1094
	public function setOwnerForAssignor(): void {
1095
		$recipTable = mapi_message_getrecipienttable($this->message);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $msg of mapi_message_getrecipienttable(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1095
		$recipTable = mapi_message_getrecipienttable(/** @scrutinizer ignore-type */ $this->message);
Loading history...
1096
		$recips = mapi_table_queryallrows($recipTable, [PR_DISPLAY_NAME]);
1097
1098
		if (!empty($recips)) {
1099
			$owner = [];
1100
			foreach ($recips as $value) {
1101
				$owner[] = $value[PR_DISPLAY_NAME];
1102
			}
1103
1104
			$props = [$this->props['owner'] => implode("; ", $owner)];
1105
			mapi_setprops($this->message, $props);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_setprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1105
			mapi_setprops(/** @scrutinizer ignore-type */ $this->message, $props);
Loading history...
1106
		}
1107
	}
1108
1109
	/**
1110
	 * Sets assignor as recipients in assignee's copy of task.
1111
	 *
1112
	 * If assignor has requested task updates then the assignor is added as recipient type MAPI_CC.
1113
	 *
1114
	 * Also if assignor has request SOC then the assignor is also add as recipient type MAPI_BCC
1115
	 *
1116
	 * @param mixed $task assignee's copy of task
1117
	 */
1118
	public function setAssignorInRecipients($task): void {
1119
		$recipTable = mapi_message_getrecipienttable($task);
1120
1121
		// Delete all MAPI_TO recipients
1122
		$recips = mapi_table_queryallrows($recipTable, [PR_ROWID], [
1123
			RES_PROPERTY,
1124
			[
1125
				RELOP => RELOP_EQ,
1126
				ULPROPTAG => PR_RECIPIENT_TYPE,
1127
				VALUE => MAPI_TO,
1128
			],
1129
		]);
1130
		foreach ($recips as $recip) {
1131
			mapi_message_modifyrecipients($task, MODRECIP_REMOVE, [$recip]);
1132
		}
1133
1134
		$recips = [];
1135
		$taskReqProps = mapi_getprops($this->message, [
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1135
		$taskReqProps = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [
Loading history...
1136
			PR_SENT_REPRESENTING_NAME,
1137
			PR_SENT_REPRESENTING_EMAIL_ADDRESS,
1138
			PR_SENT_REPRESENTING_ENTRYID,
1139
			PR_SENT_REPRESENTING_ADDRTYPE,
1140
			PR_SENT_REPRESENTING_SEARCH_KEY,
1141
		]);
1142
		$associatedTaskProps = mapi_getprops($task, [
1143
			$this->props['taskupdates'],
1144
			$this->props['tasksoc'],
1145
			$this->props['taskmultrecips'],
1146
		]);
1147
1148
		// Build assignor info
1149
		$assignor = [
1150
			PR_ENTRYID => $taskReqProps[PR_SENT_REPRESENTING_ENTRYID],
1151
			PR_DISPLAY_NAME => $taskReqProps[PR_SENT_REPRESENTING_NAME],
1152
			PR_EMAIL_ADDRESS => $taskReqProps[PR_SENT_REPRESENTING_EMAIL_ADDRESS],
1153
			PR_RECIPIENT_DISPLAY_NAME => $taskReqProps[PR_SENT_REPRESENTING_NAME],
1154
			PR_ADDRTYPE => empty($taskReqProps[PR_SENT_REPRESENTING_ADDRTYPE]) ? 'SMTP' : $taskReqProps[PR_SENT_REPRESENTING_ADDRTYPE],
1155
			PR_RECIPIENT_FLAGS => recipSendable,
1156
			PR_SEARCH_KEY => $taskReqProps[PR_SENT_REPRESENTING_SEARCH_KEY],
1157
		];
1158
1159
		// Assignor has requested task updates, so set him/her as MAPI_CC in recipienttable.
1160
		if ((isset($associatedTaskProps[$this->props['taskupdates']]) && $associatedTaskProps[$this->props['taskupdates']]) &&
1161
			!(isset($associatedTaskProps[$this->props['taskmultrecips']]) && $associatedTaskProps[$this->props['taskmultrecips']] == tmrReceived)) {
1162
			$assignor[PR_RECIPIENT_TYPE] = MAPI_CC;
1163
			$recips[] = $assignor;
1164
		}
1165
1166
		// Assignor wants to receive an email report when task is mark as 'Complete', so in recipients as MAPI_BCC
1167
		if ($associatedTaskProps[$this->props['tasksoc']]) {
1168
			$assignor[PR_RECIPIENT_TYPE] = MAPI_BCC;
1169
			$recips[] = $assignor;
1170
		}
1171
1172
		if (!empty($recips)) {
1173
			mapi_message_modifyrecipients($task, MODRECIP_ADD, $recips);
1174
		}
1175
	}
1176
1177
	/**
1178
	 * Deletes incoming task request from Inbox.
1179
	 *
1180
	 * @returns array|bool PR_ENTRYID, PR_STORE_ENTRYID and PR_PARENT_ENTRYID of the deleted task request
1181
	 *
1182
	 * @return array|false
1183
	 */
1184
	public function deleteReceivedTR() {
1185
		$store = $this->getTaskFolderStore();
1186
		$storeType = mapi_getprops($store, [PR_MDB_PROVIDER]);
0 ignored issues
show
It seems like $store can also be of type false and resource; however, parameter $any of mapi_getprops() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1186
		$storeType = mapi_getprops(/** @scrutinizer ignore-type */ $store, [PR_MDB_PROVIDER]);
Loading history...
1187
		if ($storeType[PR_MDB_PROVIDER] === ZARAFA_STORE_PUBLIC_GUID) {
1188
			$store = $this->getDefaultStore();
1189
		}
1190
		$inbox = mapi_msgstore_getreceivefolder($store);
0 ignored issues
show
It seems like $store can also be of type false and resource; however, parameter $store of mapi_msgstore_getreceivefolder() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1190
		$inbox = mapi_msgstore_getreceivefolder(/** @scrutinizer ignore-type */ $store);
Loading history...
1191
1192
		$storeProps = mapi_getprops($store, [PR_IPM_WASTEBASKET_ENTRYID]);
1193
		$props = mapi_getprops($this->message, [$this->props['task_goid']]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1193
		$props = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [$this->props['task_goid']]);
Loading history...
1194
		$goid = $props[$this->props['task_goid']];
1195
1196
		// Find the task by looking for the task_goid
1197
		$restriction = [
1198
			RES_PROPERTY,
1199
			[
1200
				RELOP => RELOP_EQ,
1201
				ULPROPTAG => $this->props['task_goid'],
1202
				VALUE => $goid,
1203
			],
1204
		];
1205
1206
		$contents = mapi_folder_getcontentstable($inbox);
1207
1208
		$rows = mapi_table_queryallrows($contents, [PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID], $restriction);
1209
1210
		if (!empty($rows)) {
1211
			// If there are multiple, just use the first
1212
			$entryid = $rows[0][PR_ENTRYID];
1213
			$wastebasket = mapi_msgstore_openentry($store, $storeProps[PR_IPM_WASTEBASKET_ENTRYID]);
0 ignored issues
show
It seems like $store can also be of type false and resource; however, parameter $store of mapi_msgstore_openentry() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1213
			$wastebasket = mapi_msgstore_openentry(/** @scrutinizer ignore-type */ $store, $storeProps[PR_IPM_WASTEBASKET_ENTRYID]);
Loading history...
1214
			mapi_folder_copymessages($inbox, [$entryid], $wastebasket, MESSAGE_MOVE);
1215
1216
			return [PR_ENTRYID => $entryid, PR_PARENT_ENTRYID => $rows[0][PR_PARENT_ENTRYID], PR_STORE_ENTRYID => $rows[0][PR_STORE_ENTRYID]];
1217
		}
1218
1219
		return false;
1220
	}
1221
1222
	/**
1223
	 * Sets recipients for the outgoing message according to type of the response.
1224
	 *
1225
	 * If it is a task update, then only recipient type MAPI_CC are taken from the task message.
1226
	 *
1227
	 * If it is accept/decline response, then PR_SENT_REPRESENTATING_XXXX are taken as recipient.
1228
	 *
1229
	 * @param mixed $outgoing     outgoing mapi message
1230
	 * @param int   $responseType response type (tdmtTaskAcc, tdmtTaskDec, tdmtTaskUpd)
1231
	 */
1232
	public function setRecipientsForResponse($outgoing, $responseType): bool {
1233
		// Clear recipients from outgoing msg
1234
		$this->deleteAllRecipients($outgoing);
1235
1236
		// If it is a task update then get MAPI_CC recipients which are assignors who has asked for task update.
1237
		if ($responseType == tdmtTaskUpd) {
1238
			$props = mapi_getprops($this->message, [$this->props['complete']]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1238
			$props = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [$this->props['complete']]);
Loading history...
1239
			$isComplete = $props[$this->props['complete']];
1240
1241
			$recipTable = mapi_message_getrecipienttable($this->message);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $msg of mapi_message_getrecipienttable(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1241
			$recipTable = mapi_message_getrecipienttable(/** @scrutinizer ignore-type */ $this->message);
Loading history...
1242
			$recips = mapi_table_queryallrows($recipTable, $this->recipProps, [
1243
				RES_PROPERTY,
1244
				[
1245
					RELOP => RELOP_EQ,
1246
					ULPROPTAG => PR_RECIPIENT_TYPE,
1247
					VALUE => ($isComplete ? MAPI_BCC : MAPI_CC),
1248
				],
1249
			]);
1250
1251
			// No recipients found, return error
1252
			if (empty($recips)) {
1253
				return false;
1254
			}
1255
1256
			foreach ($recips as $recip) {
1257
				$recip[PR_RECIPIENT_TYPE] = MAPI_TO;	// Change recipient type to MAPI_TO
1258
				mapi_message_modifyrecipients($outgoing, MODRECIP_ADD, [$recip]);
1259
			}
1260
1261
			return true;
1262
		}
1263
1264
		$orgprops = mapi_getprops($this->message, [
1265
			PR_SENT_REPRESENTING_NAME,
1266
			PR_SENT_REPRESENTING_EMAIL_ADDRESS,
1267
			PR_SENT_REPRESENTING_ADDRTYPE,
1268
			PR_SENT_REPRESENTING_ENTRYID,
1269
			PR_SUBJECT,
1270
		]);
1271
1272
		$recip = [
1273
			PR_DISPLAY_NAME => $orgprops[PR_SENT_REPRESENTING_NAME],
1274
			PR_EMAIL_ADDRESS => $orgprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS],
1275
			PR_ADDRTYPE => $orgprops[PR_SENT_REPRESENTING_ADDRTYPE],
1276
			PR_ENTRYID => $orgprops[PR_SENT_REPRESENTING_ENTRYID],
1277
			PR_RECIPIENT_TYPE => MAPI_TO, ];
1278
1279
		mapi_message_modifyrecipients($outgoing, MODRECIP_ADD, [$recip]);
1280
1281
		return true;
1282
	}
1283
1284
	/**
1285
	 * Deletes all recipients from given message object.
1286
	 *
1287
	 * @param mixed $message MAPI message from which recipients are to be removed
1288
	 */
1289
	public function deleteAllRecipients($message): void {
1290
		$recipTable = mapi_message_getrecipienttable($message);
1291
		$recipRows = mapi_table_queryallrows($recipTable, [PR_ROWID]);
1292
1293
		foreach ($recipRows as $recipient) {
1294
			mapi_message_modifyrecipients($message, MODRECIP_REMOVE, [$recipient]);
1295
		}
1296
	}
1297
1298
	/**
1299
	 * Marks the record to complete and send complete update
1300
	 * notification to assigner.
1301
	 *
1302
	 * @return bool TRUE if the update succeeded, FALSE otherwise
1303
	 */
1304
	public function sendCompleteUpdate() {
1305
		$messageprops = mapi_getprops($this->message, [$this->props['taskstate']]);
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_getprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1305
		$messageprops = mapi_getprops(/** @scrutinizer ignore-type */ $this->message, [$this->props['taskstate']]);
Loading history...
1306
1307
		if (!isset($messageprops[$this->props['taskstate']]) || $messageprops[$this->props['taskstate']] != tdsOWN) {
1308
			return false; // Can only decline assignee task
1309
		}
1310
1311
		mapi_setprops($this->message, [
0 ignored issues
show
$this->message of type resource is incompatible with the type resource expected by parameter $any of mapi_setprops(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1311
		mapi_setprops(/** @scrutinizer ignore-type */ $this->message, [
Loading history...
1312
			$this->props['complete'] => true,
1313
			$this->props['datecompleted'] => time(),
1314
			$this->props['status'] => 2,
1315
			$this->props['percent_complete'] => 1,
1316
		]);
1317
1318
		return $this->doUpdate();
1319
	}
1320
1321
	/**
1322
	 * Returns extra info about task request comments along with message body
1323
	 * which will be included in body while sending task request/response.
1324
	 *
1325
	 * @return string info about task request comments along with message body
1326
	 */
1327
	public function getTaskCommentsInfo() {
1328
		return $this->taskCommentsInfo;
1329
	}
1330
1331
	/**
1332
	 * Sets an extra info about task request comments along with message body
1333
	 * which will be included in body while sending task request/response.
1334
	 *
1335
	 * @param string $taskCommentsInfo info about task request comments along with message body
1336
	 */
1337
	public function setTaskCommentsInfo($taskCommentsInfo): void {
1338
		$this->taskCommentsInfo = $taskCommentsInfo;
1339
	}
1340
1341
	public function getSubProperties() {
1342
		$subProperties = [];
1343
		$subProperties["subject"] = PR_SUBJECT;
1344
		$subProperties["convtopic"] = PR_CONVERSATION_TOPIC;
1345
		$subProperties["complete"] = "PT_BOOLEAN:PSETID_Task:" . PidLidTaskComplete;
1346
		$subProperties["datecompleted"] = "PT_SYSTIME:PSETID_Task:" . PidLidTaskDateCompleted;
1347
		$subProperties["recurring"] = "PT_BOOLEAN:PSETID_Task:0x8126";
1348
		$subProperties["startdate"] = "PT_SYSTIME:PSETID_Task:" . PidLidTaskStartDate;
1349
		$subProperties["duedate"] = "PT_SYSTIME:PSETID_Task:" . PidLidTaskDueDate;
1350
		$subProperties["status"] = "PT_LONG:PSETID_Task:" . PidLidTaskStatus;
1351
		$subProperties["percent_complete"] = "PT_DOUBLE:PSETID_Task:" . PidLidPercentComplete;
1352
		$subProperties["totalwork"] = "PT_LONG:PSETID_Task:0x8111";
1353
		$subProperties["actualwork"] = "PT_LONG:PSETID_Task:0x8110";
1354
		$subProperties["categories"] = "PT_MV_STRING8:PS_PUBLIC_STRINGS:Keywords";
1355
		$subProperties["companies"] = "PT_MV_STRING8:PSETID_Common:0x8539";
1356
		$subProperties["mileage"] = "PT_STRING8:PSETID_Common:0x8534";
1357
		$subProperties["billinginformation"] = "PT_STRING8:PSETID_Common:0x8535";
1358
1359
		return getPropIdsFromStrings($this->store, $subProperties);
1360
	}
1361
}
1362