Total Complexity | 140 |
Total Lines | 1290 |
Duplicated Lines | 0 % |
Changes | 5 | ||
Bugs | 2 | Features | 0 |
Complex classes like TaskRequest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TaskRequest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
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) { |
||
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]); |
||
|
|||
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]); |
||
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) { |
||
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']]); |
||
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); |
||
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); |
||
257 | |||
258 | $sub = $this->getEmbeddedTask(); |
||
259 | try { |
||
260 | mapi_copyto($sub, [], [$this->props['categories']], $task); |
||
261 | } |
||
262 | catch (MAPIException $e) { |
||
263 | if ($e->getCode() !== MAPI_E_INVALID_PARAMETER) { |
||
264 | throw $e; |
||
265 | } |
||
266 | // Some stores reject excluding categories during copy when attachments are present. |
||
267 | // Retry without exclusions to keep attachments intact and drop categories afterwards. |
||
268 | mapi_copyto($sub, [], [], $task); |
||
269 | mapi_deleteprops($task, [$this->props['categories']]); |
||
270 | } |
||
271 | |||
272 | $senderProps = [ |
||
273 | PR_SENT_REPRESENTING_NAME, |
||
274 | PR_SENT_REPRESENTING_EMAIL_ADDRESS, |
||
275 | PR_SENT_REPRESENTING_ENTRYID, |
||
276 | PR_SENT_REPRESENTING_ADDRTYPE, |
||
277 | PR_SENT_REPRESENTING_SEARCH_KEY, |
||
278 | PR_SENDER_NAME, |
||
279 | PR_SENDER_EMAIL_ADDRESS, |
||
280 | PR_SENDER_ENTRYID, |
||
281 | PR_SENDER_ADDRTYPE, |
||
282 | PR_SENDER_SEARCH_KEY, ]; |
||
283 | |||
284 | // Copy sender information from the e-mail |
||
285 | $props = mapi_getprops($this->message, $senderProps); |
||
286 | $props[PR_MESSAGE_CLASS] = 'IPM.Task'; |
||
287 | mapi_setprops($task, $props); |
||
288 | } |
||
289 | else { |
||
290 | // If there are multiple, just use the first |
||
291 | $entryid = $rows[0][PR_ENTRYID]; |
||
292 | |||
293 | $store = $this->getTaskFolderStore(); |
||
294 | $task = mapi_msgstore_openentry($store, $entryid); |
||
295 | } |
||
296 | |||
297 | return $task; |
||
298 | } |
||
299 | |||
300 | /** |
||
301 | * Function which checks that if we have received a task request/response |
||
302 | * for an already updated task in task folder. |
||
303 | * |
||
304 | * @return bool true if task request is updated later |
||
305 | */ |
||
306 | public function isTaskRequestUpdated() { |
||
307 | $props = mapi_getprops($this->message, [PR_MESSAGE_CLASS, $this->props['task_goid'], $this->props['updatecount']]); |
||
308 | $result = false; |
||
309 | $associatedTask = $this->getAssociatedTask(false); |
||
310 | if ($this->isTaskRequest($props[PR_MESSAGE_CLASS])) { |
||
311 | if ($associatedTask) { |
||
312 | return true; |
||
313 | } |
||
314 | $folder = $this->getDefaultTasksFolder(); |
||
315 | $goid = $props[$this->props['task_goid']]; |
||
316 | |||
317 | // Find the task by looking for the task_goid |
||
318 | $restriction = [ |
||
319 | RES_PROPERTY, |
||
320 | [ |
||
321 | RELOP => RELOP_EQ, |
||
322 | ULPROPTAG => $this->props['task_goid'], |
||
323 | VALUE => $goid, |
||
324 | ], |
||
325 | ]; |
||
326 | |||
327 | $table = mapi_folder_getcontentstable($folder, MAPI_DEFERRED_ERRORS | SHOW_SOFT_DELETES); |
||
328 | $softDeletedItems = mapi_table_queryallrows($table, [PR_ENTRYID], $restriction); |
||
329 | if (!empty($softDeletedItems)) { |
||
330 | return true; |
||
331 | } |
||
332 | } |
||
333 | |||
334 | if ($associatedTask !== false) { |
||
335 | $taskItemProps = mapi_getprops($associatedTask, [$this->props['updatecount']]); |
||
336 | /* |
||
337 | * if(message_counter < task_counter) task object is newer then task response (task is updated) |
||
338 | * if(message_counter >= task_counter) task is not updated, do normal processing |
||
339 | */ |
||
340 | if (isset($taskItemProps[$this->props['updatecount']], $props[$this->props['updatecount']])) { |
||
341 | if ($props[$this->props['updatecount']] < $taskItemProps[$this->props['updatecount']]) { |
||
342 | $result = true; |
||
343 | } |
||
344 | } |
||
345 | } |
||
346 | |||
347 | return $result; |
||
348 | } |
||
349 | |||
350 | // Organizer functions (called by the organizer) |
||
351 | |||
352 | /** |
||
353 | * Processes a task request response, which can be any of the following: |
||
354 | * - Task accept (task history is marked as accepted) |
||
355 | * - Task decline (task history is marked as declined) |
||
356 | * - Task update (updates completion %, etc). |
||
357 | * |
||
358 | * @return true |
||
359 | */ |
||
360 | public function processTaskResponse(): bool { |
||
361 | $messageProps = mapi_getprops($this->message, [PR_PROCESSED, $this->props["taskupdates"], PR_MESSAGE_TO_ME]); |
||
362 | if (isset($messageProps[PR_PROCESSED]) && $messageProps[PR_PROCESSED]) { |
||
363 | return true; |
||
364 | } |
||
365 | mapi_setprops($this->message, [PR_PROCESSED => true]); |
||
366 | mapi_savechanges($this->message); |
||
367 | |||
368 | // Get the embedded task information. |
||
369 | $sub = $this->getEmbeddedTask(); |
||
370 | // OL saves the task related properties in the embedded message |
||
371 | $subProps = mapi_getprops($sub, [$this->props["taskupdates"]]); |
||
372 | |||
373 | // If task is updated in task folder then we don't need to process |
||
374 | // old response |
||
375 | if ($this->isTaskRequestUpdated()) { |
||
376 | return true; |
||
377 | } |
||
378 | |||
379 | $isReceivedItem = $this->isReceivedItem($messageProps); |
||
380 | |||
381 | $taskHistory = 0; |
||
382 | $taskState = 0; |
||
383 | $taskAcceptanceState = 0; |
||
384 | $taskOwner = 0; |
||
385 | $isCreateAssociatedTask = false; |
||
386 | $isAllowUpdateAssociatedTask = $subProps[$this->props["taskupdates"]]; |
||
387 | $props = mapi_getprops($this->message, [PR_MESSAGE_CLASS]); |
||
388 | |||
389 | // Set correct taskmode and taskhistory depending on response type |
||
390 | switch ($props[PR_MESSAGE_CLASS]) { |
||
391 | case 'IPM.TaskRequest.Accept': |
||
392 | $taskHistory = thAccepted; |
||
393 | $taskState = $isReceivedItem ? tdsACC : tdsOWN; |
||
394 | $taskOwner = $isReceivedItem ? olDelegatedTask : olOwnTask; |
||
395 | $taskAcceptanceState = $isReceivedItem ? olTaskDelegationAccepted : olTaskNotDelegated; |
||
396 | break; |
||
397 | |||
398 | case 'IPM.TaskRequest.Decline': |
||
399 | $isCreateAssociatedTask = $isReceivedItem; |
||
400 | $isAllowUpdateAssociatedTask = $isReceivedItem; |
||
401 | $taskHistory = thDeclined; |
||
402 | $taskState = $isReceivedItem ? tdsDEC : tdsACC; |
||
403 | $taskOwner = $isReceivedItem ? olOwnTask : olDelegatedTask; |
||
404 | $taskAcceptanceState = $isReceivedItem ? olTaskDelegationDeclined : olTaskDelegationUnknown; |
||
405 | break; |
||
406 | |||
407 | case 'IPM.TaskRequest.Update': |
||
408 | case 'IPM.TaskRequest.Complete': |
||
409 | $taskHistory = thUpdated; |
||
410 | $taskState = $isReceivedItem ? tdsACC : tdsOWN; |
||
411 | $taskAcceptanceState = olTaskNotDelegated; |
||
412 | $taskOwner = $isReceivedItem ? olDelegatedTask : olOwnTask; |
||
413 | break; |
||
414 | } |
||
415 | |||
416 | $props = [ |
||
417 | $this->props['taskhistory'] => $taskHistory, |
||
418 | $this->props['taskstate'] => $taskState, |
||
419 | $this->props['task_acceptance_state'] => $taskAcceptanceState, |
||
420 | $this->props['ownership'] => $taskOwner, |
||
421 | ]; |
||
422 | |||
423 | // Get the task for this response |
||
424 | $task = $this->getAssociatedTask($isCreateAssociatedTask); |
||
425 | if ($task && $isAllowUpdateAssociatedTask) { |
||
426 | // To avoid duplication of attachments in associated task. we simple remove the |
||
427 | // all attachments from associated task. |
||
428 | $taskAttachTable = mapi_message_getattachmenttable($task); |
||
429 | $taskAttachments = mapi_table_queryallrows($taskAttachTable, [PR_ATTACH_NUM]); |
||
430 | foreach ($taskAttachments as $taskAttach) { |
||
431 | mapi_message_deleteattach($task, $taskAttach[PR_ATTACH_NUM]); |
||
432 | } |
||
433 | |||
434 | $ignoreProps = [ |
||
435 | $this->props['taskstate'], |
||
436 | $this->props['taskhistory'], |
||
437 | $this->props['taskmode'], |
||
438 | $this->props['taskfcreator'], |
||
439 | ]; |
||
440 | // Ignore PR_ICON_INDEX when task request response |
||
441 | // is not received item. |
||
442 | if ($isReceivedItem === false) { |
||
443 | $ignoreProps[] = PR_ICON_INDEX; |
||
444 | } |
||
445 | |||
446 | // We copy all properties except taskstate, taskhistory, taskmode and taskfcreator properties |
||
447 | // from $sub message to $task even also we copy all attachments from $sub to $task message. |
||
448 | mapi_copyto($sub, [], $ignoreProps, $task); |
||
449 | $senderProps = mapi_getprops($this->message, [ |
||
450 | PR_SENDER_NAME, |
||
451 | PR_SENDER_EMAIL_ADDRESS, |
||
452 | PR_SENDER_ENTRYID, |
||
453 | PR_SENDER_ADDRTYPE, |
||
454 | PR_SENDER_SEARCH_KEY, |
||
455 | PR_MESSAGE_DELIVERY_TIME, |
||
456 | PR_SENT_REPRESENTING_NAME, |
||
457 | PR_SENT_REPRESENTING_EMAIL_ADDRESS, |
||
458 | PR_SENT_REPRESENTING_ADDRTYPE, |
||
459 | PR_SENT_REPRESENTING_ENTRYID, |
||
460 | PR_SENT_REPRESENTING_SEARCH_KEY, ]); |
||
461 | |||
462 | mapi_setprops($task, $senderProps); |
||
463 | |||
464 | // Update taskstate and task history (last action done by the assignee) |
||
465 | mapi_setprops($task, $props); |
||
466 | |||
467 | // Copy missing properties from embedded task |
||
468 | $subProperties = $this->getSubProperties(); |
||
469 | $subprops = mapi_getprops($sub, $subProperties); |
||
470 | mapi_setprops($task, $subprops); |
||
471 | |||
472 | mapi_savechanges($task); |
||
473 | } |
||
474 | |||
475 | mapi_setprops($this->message, $props); |
||
476 | mapi_savechanges($this->message); |
||
477 | |||
478 | if ($isReceivedItem) { |
||
479 | $this->updateSentTaskRequest(); |
||
480 | } |
||
481 | |||
482 | return true; |
||
483 | } |
||
484 | |||
485 | /** |
||
486 | * Update the sent task request in sent items folder. |
||
487 | * |
||
488 | * @return bool |
||
489 | */ |
||
490 | public function updateSentTaskRequest() { |
||
491 | $props = mapi_getprops($this->message, [ |
||
492 | $this->props['taskhistory'], |
||
493 | $this->props["taskstate"], |
||
494 | $this->props["ownership"], |
||
495 | $this->props['task_goid'], |
||
496 | $this->props['task_acceptance_state'], |
||
497 | $this->props["tasklastuser"], |
||
498 | $this->props["tasklastdelegate"], ]); |
||
499 | |||
500 | $store = $this->getDefaultStore(); |
||
501 | $storeProps = mapi_getprops($store, [PR_IPM_SENTMAIL_ENTRYID]); |
||
502 | |||
503 | $sentFolder = mapi_msgstore_openentry($store, $storeProps[PR_IPM_SENTMAIL_ENTRYID]); |
||
504 | if (!$sentFolder) { |
||
505 | return false; |
||
506 | } |
||
507 | |||
508 | // Find the task by looking for the task_goid |
||
509 | $restriction = [ |
||
510 | RES_PROPERTY, |
||
511 | [ |
||
512 | RELOP => RELOP_EQ, |
||
513 | ULPROPTAG => $this->props['task_goid'], |
||
514 | VALUE => $props[$this->props['task_goid']], |
||
515 | ], |
||
516 | ]; |
||
517 | |||
518 | $contentsTable = mapi_folder_getcontentstable($sentFolder); |
||
519 | |||
520 | $rows = mapi_table_queryallrows($contentsTable, [PR_ENTRYID], $restriction); |
||
521 | |||
522 | if (!empty($rows)) { |
||
523 | foreach ($rows as $row) { |
||
524 | $sentTaskRequest = mapi_msgstore_openentry($store, $row[PR_ENTRYID]); |
||
525 | mapi_setprops($sentTaskRequest, $props); |
||
526 | mapi_setprops($sentTaskRequest, [PR_PROCESSED => true]); |
||
527 | mapi_savechanges($sentTaskRequest); |
||
528 | } |
||
529 | } |
||
530 | |||
531 | return true; |
||
532 | } |
||
533 | |||
534 | /** |
||
535 | * Creates a new message in the current user's outbox and submits it. |
||
536 | * |
||
537 | * Takes the task passed in the constructor as the task to be sent; recipient should |
||
538 | * be pre-existing. The task request will be sent to all recipients. |
||
539 | * |
||
540 | * @param string $prefix |
||
541 | * |
||
542 | * @return true |
||
543 | */ |
||
544 | public function sendTaskRequest($prefix): bool { |
||
545 | // Generate a TaskGlobalObjectId |
||
546 | $taskid = $this->createTGOID(); |
||
547 | $messageprops = mapi_getprops($this->message, [PR_SUBJECT]); |
||
548 | |||
549 | // Set properties on Task Request |
||
550 | mapi_setprops($this->message, [ |
||
551 | $this->props['task_goid'] => $taskid, // our new task_goid |
||
552 | $this->props['taskstate'] => tdsACC, // state for our outgoing request |
||
553 | $this->props['taskmode'] => tdmtNothing, // we're not sending a change |
||
554 | $this->props['updatecount'] => 2, // version 2 (no idea) |
||
555 | $this->props['task_acceptance_state'] => olTaskDelegationUnknown, // no reply yet |
||
556 | $this->props['ownership'] => olDelegatedTask, // Task has been assigned |
||
557 | $this->props['taskhistory'] => thAssigned, // Task has been assigned |
||
558 | PR_CONVERSATION_TOPIC => $messageprops[PR_SUBJECT], |
||
559 | PR_ICON_INDEX => ICON_TASK_ASSIGNER, |
||
560 | ]); |
||
561 | $this->setLastUser(); |
||
562 | $this->setOwnerForAssignor(); |
||
563 | mapi_savechanges($this->message); |
||
564 | |||
565 | // Create outgoing task request message |
||
566 | $outgoing = $this->createOutgoingMessage(); |
||
567 | |||
568 | // No need to copy PR_ICON_INDEX and PR_SENT_* information in to outgoing message. |
||
569 | $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]; |
||
570 | mapi_copyto($this->message, [], $ignoreProps, $outgoing); |
||
571 | |||
572 | // Make it a task request, and put it in sent items after it is sent |
||
573 | mapi_setprops($outgoing, [ |
||
574 | PR_MESSAGE_CLASS => "IPM.TaskRequest", // class is task request |
||
575 | $this->props['taskstate'] => tdsOWN, // for the recipient he is the task owner |
||
576 | $this->props['taskmode'] => tdmtTaskReq, // for the recipient it's a request |
||
577 | $this->props['updatecount'] => 1, // version 2 is in the attachment |
||
578 | PR_SUBJECT_PREFIX => $prefix, |
||
579 | PR_SUBJECT => $prefix . $messageprops[PR_SUBJECT], |
||
580 | ]); |
||
581 | |||
582 | $attach = mapi_message_createattach($outgoing); |
||
583 | mapi_setprops($attach, [ |
||
584 | PR_ATTACH_METHOD => ATTACH_EMBEDDED_MSG, |
||
585 | PR_ATTACHMENT_HIDDEN => true, |
||
586 | PR_DISPLAY_NAME => $messageprops[PR_SUBJECT], ]); |
||
587 | |||
588 | $sub = mapi_attach_openproperty($attach, PR_ATTACH_DATA_OBJ, IID_IMessage, 0, MAPI_MODIFY | MAPI_CREATE); |
||
589 | |||
590 | mapi_copyto($this->message, [], [], $sub); |
||
591 | mapi_setprops($sub, [PR_MESSAGE_CLASS => 'IPM.Task']); |
||
592 | |||
593 | mapi_savechanges($sub); |
||
594 | |||
595 | mapi_savechanges($attach); |
||
596 | |||
597 | mapi_savechanges($outgoing); |
||
598 | mapi_message_submitmessage($outgoing); |
||
599 | |||
600 | return true; |
||
601 | } |
||
602 | |||
603 | // Assignee functions (called by the assignee) |
||
604 | |||
605 | /** |
||
606 | * Updates task version counter. |
||
607 | * |
||
608 | * Must be called before each update to increase counter. |
||
609 | */ |
||
610 | public function updateTaskRequest(): void { |
||
611 | $messageprops = mapi_getprops($this->message, [$this->props['updatecount']]); |
||
612 | |||
613 | if (isset($messageprops)) { |
||
614 | ++$messageprops[$this->props['updatecount']]; |
||
615 | } |
||
616 | else { |
||
617 | $messageprops[$this->props['updatecount']] = 1; |
||
618 | } |
||
619 | |||
620 | mapi_setprops($this->message, $messageprops); |
||
621 | } |
||
622 | |||
623 | /** |
||
624 | * Processes a task request. |
||
625 | * |
||
626 | * Message passed should be an IPM.TaskRequest message. The task request is then processed to create |
||
627 | * the task in the tasks folder if needed. |
||
628 | * |
||
629 | * @return bool |
||
630 | */ |
||
631 | public function processTaskRequest() { |
||
632 | if (!$this->isTaskRequest()) { |
||
633 | return false; |
||
634 | } |
||
635 | $messageProps = mapi_getprops($this->message, [PR_PROCESSED, $this->props["taskupdates"], PR_MESSAGE_TO_ME]); |
||
636 | if (isset($messageProps[PR_PROCESSED]) && $messageProps[PR_PROCESSED]) { |
||
637 | return true; |
||
638 | } |
||
639 | |||
640 | // if task is updated in task folder then we don't need to process |
||
641 | // old request. |
||
642 | if ($this->isTaskRequestUpdated()) { |
||
643 | return true; |
||
644 | } |
||
645 | |||
646 | $isReceivedItem = $this->isReceivedItem($messageProps); |
||
647 | |||
648 | $props = []; |
||
649 | $props[PR_PROCESSED] = true; |
||
650 | $props[$this->props["taskstate"]] = $isReceivedItem ? tdsOWN : tdsACC; |
||
651 | $props[$this->props["ownership"]] = $isReceivedItem ? olOwnTask : olDelegatedTask; |
||
652 | |||
653 | mapi_setprops($this->message, $props); |
||
654 | mapi_savechanges($this->message); |
||
655 | |||
656 | // Don't create associated task in task folder if "taskupdates" is not true. |
||
657 | if (!$isReceivedItem && !$messageProps[$this->props["taskupdates"]]) { |
||
658 | return true; |
||
659 | } |
||
660 | // create an associated task in task folder while |
||
661 | // reading/loading task request on client side. |
||
662 | $task = $this->getAssociatedTask(true); |
||
663 | |||
664 | $taskProps = mapi_getprops($task, [$this->props['taskmultrecips']]); |
||
665 | $taskProps[$this->props["taskstate"]] = $isReceivedItem ? tdsOWN : tdsACC; |
||
666 | $taskProps[$this->props["taskhistory"]] = thAssigned; |
||
667 | $taskProps[$this->props["taskmode"]] = tdmtNothing; |
||
668 | $taskProps[$this->props["taskaccepted"]] = false; |
||
669 | $taskProps[$this->props["taskfcreator"]] = false; |
||
670 | $taskProps[$this->props["ownership"]] = $isReceivedItem ? olOwnTask : olDelegatedTask; |
||
671 | $taskProps[$this->props["task_acceptance_state"]] = olTaskNotDelegated; |
||
672 | $taskProps[PR_ICON_INDEX] = ICON_TASK_ASSIGNEE; |
||
673 | |||
674 | mapi_setprops($task, $taskProps); |
||
675 | $this->setAssignorInRecipients($task); |
||
676 | |||
677 | mapi_savechanges($task); |
||
678 | |||
679 | return true; |
||
680 | } |
||
681 | |||
682 | /** |
||
683 | * Accepts a task request and sends the response. |
||
684 | * |
||
685 | * Message passed should be an IPM.Task (eg the task from getAssociatedTask()) |
||
686 | * |
||
687 | * Copies the task to the user's task folder, sets it to accepted, and sends the acceptation |
||
688 | * message back to the organizer. The caller is responsible for removing the message. |
||
689 | * |
||
690 | * @return array|false PR_ENTRYID, PR_STORE_ENTRYID and PR_PARENT_ENTRYID of the task |
||
691 | */ |
||
692 | public function doAccept() { |
||
693 | $prefix = _("Task Accepted:") . " "; |
||
694 | $messageProps = mapi_getprops($this->message, [PR_MESSAGE_CLASS, $this->props['taskstate']]); |
||
695 | |||
696 | if (!isset($messageProps[$this->props['taskstate']]) || $messageProps[$this->props['taskstate']] != tdsOWN) { |
||
697 | // Can only accept assignee task |
||
698 | return false; |
||
699 | } |
||
700 | |||
701 | $this->setLastUser(); |
||
702 | $this->updateTaskRequest(); |
||
703 | |||
704 | $props = [ |
||
705 | $this->props['taskhistory'] => thAccepted, |
||
706 | $this->props['task_assigned_time'] => time(), |
||
707 | $this->props['taskaccepted'] => true, |
||
708 | $this->props['task_acceptance_state'] => olTaskNotDelegated, ]; |
||
709 | |||
710 | // Message is TaskRequest then update the associated task as well. |
||
711 | if ($this->isTaskRequest($messageProps[PR_MESSAGE_CLASS])) { |
||
712 | $task = $this->getAssociatedTask(false); |
||
713 | if ($task) { |
||
714 | mapi_setprops($task, $props); |
||
715 | mapi_savechanges($task); |
||
716 | } |
||
717 | } |
||
718 | |||
719 | // Set as accepted |
||
720 | mapi_setprops($this->message, $props); |
||
721 | |||
722 | // As we copy the all properties from received message we need to remove following |
||
723 | // properties from accept response. |
||
724 | mapi_deleteprops($this->message, [PR_MESSAGE_RECIP_ME, PR_MESSAGE_TO_ME, PR_MESSAGE_CC_ME, PR_PROCESSED]); |
||
725 | |||
726 | mapi_savechanges($this->message); |
||
727 | |||
728 | $this->sendResponse(tdmtTaskAcc, $prefix); |
||
729 | |||
730 | return $this->deleteReceivedTR(); |
||
731 | } |
||
732 | |||
733 | /** |
||
734 | * Declines a task request and sends the response. |
||
735 | * |
||
736 | * Passed message must be a task request message, ie isTaskRequest() must return TRUE. |
||
737 | * |
||
738 | * Sends the decline message back to the organizer. The caller is responsible for removing the message. |
||
739 | * |
||
740 | * @return array|false TRUE on success, FALSE on failure |
||
741 | */ |
||
742 | public function doDecline() { |
||
743 | $prefix = _("Task Declined:") . " "; |
||
744 | $messageProps = mapi_getprops($this->message, [$this->props['taskstate']]); |
||
745 | |||
746 | if (!isset($messageProps[$this->props['taskstate']]) || $messageProps[$this->props['taskstate']] != tdsOWN) { |
||
747 | return false; // Can only decline assignee task |
||
748 | } |
||
749 | |||
750 | $this->setLastUser(); |
||
751 | $this->updateTaskRequest(); |
||
752 | |||
753 | // Set as declined |
||
754 | mapi_setprops($this->message, [ |
||
755 | $this->props['taskhistory'] => thDeclined, |
||
756 | $this->props['task_acceptance_state'] => olTaskDelegationDeclined, |
||
757 | ]); |
||
758 | mapi_deleteprops($this->message, [PR_MESSAGE_RECIP_ME, PR_MESSAGE_TO_ME, PR_MESSAGE_CC_ME, PR_PROCESSED]); |
||
759 | mapi_savechanges($this->message); |
||
760 | |||
761 | $this->sendResponse(tdmtTaskDec, $prefix); |
||
762 | |||
763 | // Delete the associated task when task request is declined by the assignee. |
||
764 | $task = $this->getAssociatedTask(false); |
||
765 | if ($task) { |
||
766 | $taskFolder = $this->getDefaultTasksFolder(); |
||
767 | $props = mapi_getprops($task, [PR_ENTRYID]); |
||
768 | mapi_folder_deletemessages($taskFolder, [$props[PR_ENTRYID]]); |
||
769 | } |
||
770 | |||
771 | return $this->deleteReceivedTR(); |
||
772 | } |
||
773 | |||
774 | /** |
||
775 | * Sends an update of the task if requested, and sends the Status-On-Completion report if complete and requested. |
||
776 | * |
||
777 | * If no updates were requested from the organizer, this function does nothing. |
||
778 | * |
||
779 | * @return bool TRUE if the update succeeded, FALSE otherwise |
||
780 | */ |
||
781 | public function doUpdate() { |
||
782 | $messageProps = mapi_getprops($this->message, [$this->props['taskstate'], PR_SUBJECT]); |
||
783 | |||
784 | if (!isset($messageProps[$this->props['taskstate']]) || $messageProps[$this->props['taskstate']] != tdsOWN) { |
||
785 | return false; // Can only update assignee task |
||
786 | } |
||
787 | |||
788 | $this->setLastUser(); |
||
789 | $this->updateTaskRequest(); |
||
790 | |||
791 | // Set as updated |
||
792 | mapi_setprops($this->message, [$this->props['taskhistory'] => thUpdated]); |
||
793 | |||
794 | mapi_savechanges($this->message); |
||
795 | |||
796 | $props = mapi_getprops($this->message, [$this->props['taskupdates'], $this->props['tasksoc'], $this->props['recurring'], $this->props['complete']]); |
||
797 | if (!$props[$this->props['complete']] && $props[$this->props['taskupdates']] && !(isset($props[$this->props['recurring']]) && $props[$this->props['recurring']])) { |
||
798 | $this->sendResponse(tdmtTaskUpd, _("Task Updated:") . " "); |
||
799 | } |
||
800 | elseif ($props[$this->props['complete']]) { |
||
801 | $this->sendResponse(tdmtTaskUpd, _("Task Completed:") . " "); |
||
802 | } |
||
803 | |||
804 | return true; |
||
805 | } |
||
806 | |||
807 | /** |
||
808 | * Gets the store associated with the task. |
||
809 | * |
||
810 | * Normally this will just open the store that the processed message is in. However, if the message is opened |
||
811 | * by a delegate, this function opens the store that the message was delegated from. |
||
812 | */ |
||
813 | public function getTaskFolderStore() { |
||
814 | $ownerentryid = false; |
||
815 | |||
816 | $rcvdprops = mapi_getprops($this->message, [PR_RCVD_REPRESENTING_ENTRYID]); |
||
817 | if (isset($rcvdprops[PR_RCVD_REPRESENTING_ENTRYID])) { |
||
818 | $ownerentryid = $rcvdprops[PR_RCVD_REPRESENTING_ENTRYID]; |
||
819 | } |
||
820 | |||
821 | if (!$ownerentryid) { |
||
822 | $store = $this->store; |
||
823 | } |
||
824 | else { |
||
825 | $ab = mapi_openaddressbook($this->session); |
||
826 | if (!$ab) { |
||
827 | return false; |
||
828 | } |
||
829 | |||
830 | $mailuser = mapi_ab_openentry($ab, $ownerentryid); |
||
831 | if (!$mailuser) { |
||
832 | return false; |
||
833 | } |
||
834 | |||
835 | $mailuserprops = mapi_getprops($mailuser, [PR_EMAIL_ADDRESS]); |
||
836 | if (!isset($mailuserprops[PR_EMAIL_ADDRESS])) { |
||
837 | return false; |
||
838 | } |
||
839 | |||
840 | $storeid = mapi_msgstore_createentryid($this->store, $mailuserprops[PR_EMAIL_ADDRESS]); |
||
841 | |||
842 | $store = mapi_openmsgstore($this->session, $storeid); |
||
843 | } |
||
844 | |||
845 | return $store; |
||
846 | } |
||
847 | |||
848 | /** |
||
849 | * Opens the default task folder for the current user, or the specified user if passed. |
||
850 | */ |
||
851 | public function getDefaultTasksFolder() { |
||
861 | } |
||
862 | |||
863 | /** |
||
864 | * Prepares the sent representing properties from given MAPI store. |
||
865 | * |
||
866 | * @param mixed $store MAPI store object |
||
867 | * |
||
868 | * @return array[][][][][]|false if store is not mail box owner entryid then return false else prepare the sent representing props and return it |
||
869 | * |
||
870 | * @psalm-return array<array<array<array<array<array<never, never>>>>>>|false |
||
871 | */ |
||
872 | public function getSentReprProps($store) { |
||
873 | $storeprops = mapi_getprops($store, [PR_MAILBOX_OWNER_ENTRYID]); |
||
874 | if (!isset($storeprops[PR_MAILBOX_OWNER_ENTRYID])) { |
||
875 | return false; |
||
876 | } |
||
877 | |||
878 | $ab = mapi_openaddressbook($this->session); |
||
879 | $mailuser = mapi_ab_openentry($ab, $storeprops[PR_MAILBOX_OWNER_ENTRYID]); |
||
880 | $mailuserprops = mapi_getprops($mailuser, [PR_ADDRTYPE, PR_EMAIL_ADDRESS, PR_DISPLAY_NAME, PR_SEARCH_KEY, PR_ENTRYID]); |
||
881 | |||
882 | $props = []; |
||
883 | $props[PR_SENT_REPRESENTING_ADDRTYPE] = $mailuserprops[PR_ADDRTYPE]; |
||
884 | $props[PR_SENT_REPRESENTING_EMAIL_ADDRESS] = $mailuserprops[PR_EMAIL_ADDRESS]; |
||
885 | $props[PR_SENT_REPRESENTING_NAME] = $mailuserprops[PR_DISPLAY_NAME]; |
||
886 | $props[PR_SENT_REPRESENTING_SEARCH_KEY] = $mailuserprops[PR_SEARCH_KEY]; |
||
887 | $props[PR_SENT_REPRESENTING_ENTRYID] = $mailuserprops[PR_ENTRYID]; |
||
888 | |||
889 | return $props; |
||
890 | } |
||
891 | |||
892 | /** |
||
893 | * Creates an outgoing message based on the passed message - will set delegate information |
||
894 | * and sent mail folder. |
||
895 | */ |
||
896 | public function createOutgoingMessage() { |
||
897 | // Open our default store for this user (that's the only store we can submit in) |
||
898 | $store = $this->getDefaultStore(); |
||
899 | $storeprops = mapi_getprops($store, [PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID]); |
||
900 | |||
901 | $outbox = mapi_msgstore_openentry($store, $storeprops[PR_IPM_OUTBOX_ENTRYID]); |
||
902 | if (!$outbox) { |
||
903 | return false; |
||
904 | } |
||
905 | |||
906 | $outgoing = mapi_folder_createmessage($outbox); |
||
907 | if (!$outgoing) { |
||
908 | return false; |
||
909 | } |
||
910 | |||
911 | // Set SENT_REPRESENTING in case we're sending as a delegate |
||
912 | $ownerstore = $this->getTaskFolderStore(); |
||
913 | $sentreprprops = $this->getSentReprProps($ownerstore); |
||
914 | mapi_setprops($outgoing, $sentreprprops); |
||
915 | |||
916 | mapi_setprops($outgoing, [PR_SENTMAIL_ENTRYID => $storeprops[PR_IPM_SENTMAIL_ENTRYID]]); |
||
917 | |||
918 | return $outgoing; |
||
919 | } |
||
920 | |||
921 | /** |
||
922 | * Sends a response message (from assignee back to organizer). |
||
923 | * |
||
924 | * @param int $type Type of response (tdmtTaskAcc, tdmtTaskDec, tdmtTaskUpd) |
||
925 | * @param mixed $prefix |
||
926 | * |
||
927 | * @return bool TRUE on success |
||
928 | */ |
||
929 | public function sendResponse($type, $prefix) { |
||
930 | // Create a message in our outbox |
||
931 | $outgoing = $this->createOutgoingMessage(); |
||
932 | $messageprops = mapi_getprops($this->message, [PR_CONVERSATION_TOPIC, PR_MESSAGE_CLASS, $this->props['complete']]); |
||
933 | |||
934 | $attach = mapi_message_createattach($outgoing); |
||
935 | mapi_setprops($attach, [PR_ATTACH_METHOD => ATTACH_EMBEDDED_MSG, PR_DISPLAY_NAME => $messageprops[PR_CONVERSATION_TOPIC], PR_ATTACHMENT_HIDDEN => true]); |
||
936 | $sub = mapi_attach_openproperty($attach, PR_ATTACH_DATA_OBJ, IID_IMessage, 0, MAPI_CREATE | MAPI_MODIFY); |
||
937 | |||
938 | $message = !$this->isTaskRequest() ? $this->message : $this->getAssociatedTask(false); |
||
939 | |||
940 | $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]; |
||
941 | |||
942 | mapi_copyto($message, [], $ignoreProps, $outgoing); |
||
943 | mapi_copyto($message, [], [], $sub); |
||
944 | |||
945 | if (!$this->setRecipientsForResponse($outgoing, $type)) { |
||
946 | return false; |
||
947 | } |
||
948 | |||
949 | $props = []; |
||
950 | |||
951 | switch ($type) { |
||
952 | case tdmtTaskAcc: |
||
953 | $props[PR_MESSAGE_CLASS] = "IPM.TaskRequest.Accept"; |
||
954 | mapi_setprops($sub, [PR_ICON_INDEX => ICON_TASK_ASSIGNER]); |
||
955 | break; |
||
956 | |||
957 | case tdmtTaskDec: |
||
958 | $props[PR_MESSAGE_CLASS] = "IPM.TaskRequest.Decline"; |
||
959 | mapi_setprops($sub, [PR_ICON_INDEX => ICON_TASK_DECLINE]); |
||
960 | break; |
||
961 | |||
962 | case tdmtTaskUpd: |
||
963 | mapi_setprops($sub, [PR_ICON_INDEX => ICON_TASK_ASSIGNER]); |
||
964 | if ($messageprops[$this->props['complete']]) { |
||
965 | $props[PR_MESSAGE_CLASS] = "IPM.TaskRequest.Complete"; |
||
966 | } |
||
967 | else { |
||
968 | $props[PR_MESSAGE_CLASS] = "IPM.TaskRequest.Update"; |
||
969 | } |
||
970 | |||
971 | break; |
||
972 | } |
||
973 | |||
974 | mapi_savechanges($sub); |
||
975 | mapi_savechanges($attach); |
||
976 | |||
977 | $props[PR_SUBJECT] = $prefix . $messageprops[PR_CONVERSATION_TOPIC]; |
||
978 | $props[$this->props['taskmode']] = $type; |
||
979 | $props[$this->props['task_assigned_time']] = time(); |
||
980 | |||
981 | mapi_setprops($outgoing, $props); |
||
982 | |||
983 | // taskCommentsInfo contains some comments which added by assignee while |
||
984 | // edit response before sending task response. |
||
985 | if ($this->taskCommentsInfo != '') { |
||
986 | $comments = $this->getTaskCommentsInfo(); |
||
987 | $stream = mapi_openproperty($outgoing, PR_BODY, IID_IStream, STGM_TRANSACTED, MAPI_CREATE | MAPI_MODIFY); |
||
988 | mapi_stream_setsize($stream, strlen($comments)); |
||
989 | mapi_stream_write($stream, $comments); |
||
990 | mapi_stream_commit($stream); |
||
991 | } |
||
992 | |||
993 | mapi_savechanges($outgoing); |
||
994 | mapi_message_submitmessage($outgoing); |
||
995 | |||
996 | return true; |
||
997 | } |
||
998 | |||
999 | public function getDefaultStore() { |
||
1000 | $table = mapi_getmsgstorestable($this->session); |
||
1001 | $rows = mapi_table_queryallrows($table, [PR_DEFAULT_STORE, PR_ENTRYID]); |
||
1002 | |||
1003 | foreach ($rows as $row) { |
||
1004 | if ($row[PR_DEFAULT_STORE]) { |
||
1005 | return mapi_openmsgstore($this->session, $row[PR_ENTRYID]); |
||
1006 | } |
||
1007 | } |
||
1008 | |||
1009 | return false; |
||
1010 | } |
||
1011 | |||
1012 | /** |
||
1013 | * Creates a new TaskGlobalObjId. |
||
1014 | * |
||
1015 | * Just 16 bytes of random data |
||
1016 | */ |
||
1017 | public function createTGOID(): string { |
||
1024 | } |
||
1025 | |||
1026 | /** |
||
1027 | * Gets the embedded task of task request. Further used to |
||
1028 | * create/update associated task of assigner/assignee. |
||
1029 | * |
||
1030 | * @return bool|resource embedded task if found else false |
||
1031 | */ |
||
1032 | public function getEmbeddedTask() { |
||
1033 | $task = false; |
||
1034 | $goid = mapi_getprops($this->message, [$this->props["task_goid"]]); |
||
1035 | $attachmentTable = mapi_message_getattachmenttable($this->message); |
||
1036 | $restriction = [RES_PROPERTY, |
||
1037 | [RELOP => RELOP_EQ, |
||
1038 | ULPROPTAG => PR_ATTACH_METHOD, |
||
1039 | VALUE => ATTACH_EMBEDDED_MSG, ], |
||
1040 | ]; |
||
1041 | $rows = mapi_table_queryallrows($attachmentTable, [PR_ATTACH_NUM], $restriction); |
||
1042 | |||
1043 | if (empty($rows)) { |
||
1044 | return $task; |
||
1045 | } |
||
1046 | |||
1047 | foreach ($rows as $row) { |
||
1048 | try { |
||
1049 | $attach = mapi_message_openattach($this->message, $row[PR_ATTACH_NUM]); |
||
1050 | $task = mapi_attach_openobj($attach); |
||
1051 | } |
||
1052 | catch (MAPIException) { |
||
1053 | continue; |
||
1054 | } |
||
1055 | |||
1056 | $taskGoid = mapi_getprops($task, [$this->props["task_goid"]]); |
||
1057 | if ($goid[$this->props["task_goid"]] === $taskGoid[$this->props["task_goid"]]) { |
||
1058 | mapi_setprops($attach, [PR_ATTACHMENT_HIDDEN => true]); |
||
1059 | mapi_savechanges($attach); |
||
1060 | mapi_savechanges($this->message); |
||
1061 | break; |
||
1062 | } |
||
1063 | } |
||
1064 | |||
1065 | return $task; |
||
1066 | } |
||
1067 | |||
1068 | /** |
||
1069 | * Sets the user name who has last used this task. Update the |
||
1070 | * tasklastdelegate and task_assigned_time. |
||
1071 | */ |
||
1072 | public function setLastUser(): void { |
||
1073 | $delegatestore = $this->getDefaultStore(); |
||
1074 | $taskstore = $this->getTaskFolderStore(); |
||
1075 | |||
1076 | $delegateprops = mapi_getprops($delegatestore, [PR_MAILBOX_OWNER_NAME]); |
||
1077 | $taskprops = mapi_getprops($taskstore, [PR_MAILBOX_OWNER_NAME]); |
||
1078 | |||
1079 | // The owner of the task |
||
1080 | $username = $delegateprops[PR_MAILBOX_OWNER_NAME]; |
||
1081 | // This is me (the one calling the script) |
||
1082 | $delegate = $taskprops[PR_MAILBOX_OWNER_NAME]; |
||
1083 | |||
1084 | if ($this->isTaskRequest()) { |
||
1085 | $task = $this->getAssociatedTask(false); |
||
1086 | mapi_setprops($task, [ |
||
1087 | $this->props["tasklastuser"] => $username, |
||
1088 | $this->props["tasklastdelegate"] => $delegate, |
||
1089 | $this->props['task_assigned_time'] => time(), |
||
1090 | ]); |
||
1091 | mapi_savechanges($task); |
||
1092 | } |
||
1093 | mapi_setprops($this->message, [ |
||
1094 | $this->props["tasklastuser"] => $username, |
||
1095 | $this->props["tasklastdelegate"] => $delegate, |
||
1096 | $this->props['task_assigned_time'] => time(), |
||
1097 | ]); |
||
1098 | } |
||
1099 | |||
1100 | /** |
||
1101 | * Sets assignee as owner in the assignor's copy of task. |
||
1102 | * Assignee becomes the owner when a user/assignor assigns any task to someone. |
||
1103 | * There can be more than one assignee. |
||
1104 | */ |
||
1105 | public function setOwnerForAssignor(): void { |
||
1106 | $recipTable = mapi_message_getrecipienttable($this->message); |
||
1107 | $recips = mapi_table_queryallrows($recipTable, [PR_DISPLAY_NAME]); |
||
1108 | |||
1109 | if (!empty($recips)) { |
||
1110 | $owner = []; |
||
1111 | foreach ($recips as $value) { |
||
1112 | $owner[] = $value[PR_DISPLAY_NAME]; |
||
1113 | } |
||
1114 | |||
1115 | $props = [$this->props['owner'] => implode("; ", $owner)]; |
||
1116 | mapi_setprops($this->message, $props); |
||
1117 | } |
||
1118 | } |
||
1119 | |||
1120 | /** |
||
1121 | * Sets assignor as recipients in assignee's copy of task. |
||
1122 | * |
||
1123 | * If assignor has requested task updates then the assignor is added as recipient type MAPI_CC. |
||
1124 | * |
||
1125 | * Also if assignor has request SOC then the assignor is also add as recipient type MAPI_BCC |
||
1126 | * |
||
1127 | * @param mixed $task assignee's copy of task |
||
1128 | */ |
||
1129 | public function setAssignorInRecipients($task): void { |
||
1130 | $recipTable = mapi_message_getrecipienttable($task); |
||
1131 | |||
1132 | // Delete all MAPI_TO recipients |
||
1133 | $recips = mapi_table_queryallrows($recipTable, [PR_ROWID], [ |
||
1134 | RES_PROPERTY, |
||
1135 | [ |
||
1136 | RELOP => RELOP_EQ, |
||
1137 | ULPROPTAG => PR_RECIPIENT_TYPE, |
||
1138 | VALUE => MAPI_TO, |
||
1139 | ], |
||
1140 | ]); |
||
1141 | foreach ($recips as $recip) { |
||
1142 | mapi_message_modifyrecipients($task, MODRECIP_REMOVE, [$recip]); |
||
1143 | } |
||
1144 | |||
1145 | $recips = []; |
||
1146 | $taskReqProps = mapi_getprops($this->message, [ |
||
1147 | PR_SENT_REPRESENTING_NAME, |
||
1148 | PR_SENT_REPRESENTING_EMAIL_ADDRESS, |
||
1149 | PR_SENT_REPRESENTING_ENTRYID, |
||
1150 | PR_SENT_REPRESENTING_ADDRTYPE, |
||
1151 | PR_SENT_REPRESENTING_SEARCH_KEY, |
||
1152 | ]); |
||
1153 | $associatedTaskProps = mapi_getprops($task, [ |
||
1154 | $this->props['taskupdates'], |
||
1155 | $this->props['tasksoc'], |
||
1156 | $this->props['taskmultrecips'], |
||
1157 | ]); |
||
1158 | |||
1159 | // Build assignor info |
||
1160 | $assignor = [ |
||
1161 | PR_ENTRYID => $taskReqProps[PR_SENT_REPRESENTING_ENTRYID], |
||
1162 | PR_DISPLAY_NAME => $taskReqProps[PR_SENT_REPRESENTING_NAME], |
||
1163 | PR_EMAIL_ADDRESS => $taskReqProps[PR_SENT_REPRESENTING_EMAIL_ADDRESS], |
||
1164 | PR_RECIPIENT_DISPLAY_NAME => $taskReqProps[PR_SENT_REPRESENTING_NAME], |
||
1165 | PR_ADDRTYPE => empty($taskReqProps[PR_SENT_REPRESENTING_ADDRTYPE]) ? 'SMTP' : $taskReqProps[PR_SENT_REPRESENTING_ADDRTYPE], |
||
1166 | PR_RECIPIENT_FLAGS => recipSendable, |
||
1167 | PR_SEARCH_KEY => $taskReqProps[PR_SENT_REPRESENTING_SEARCH_KEY], |
||
1168 | ]; |
||
1169 | |||
1170 | // Assignor has requested task updates, so set him/her as MAPI_CC in recipienttable. |
||
1171 | if ((isset($associatedTaskProps[$this->props['taskupdates']]) && $associatedTaskProps[$this->props['taskupdates']]) && |
||
1172 | !(isset($associatedTaskProps[$this->props['taskmultrecips']]) && $associatedTaskProps[$this->props['taskmultrecips']] == tmrReceived)) { |
||
1173 | $assignor[PR_RECIPIENT_TYPE] = MAPI_CC; |
||
1174 | $recips[] = $assignor; |
||
1175 | } |
||
1176 | |||
1177 | // Assignor wants to receive an email report when task is mark as 'Complete', so in recipients as MAPI_BCC |
||
1178 | if ($associatedTaskProps[$this->props['tasksoc']]) { |
||
1179 | $assignor[PR_RECIPIENT_TYPE] = MAPI_BCC; |
||
1180 | $recips[] = $assignor; |
||
1181 | } |
||
1182 | |||
1183 | if (!empty($recips)) { |
||
1184 | mapi_message_modifyrecipients($task, MODRECIP_ADD, $recips); |
||
1185 | } |
||
1186 | } |
||
1187 | |||
1188 | /** |
||
1189 | * Deletes incoming task request from Inbox. |
||
1190 | * |
||
1191 | * @returns array|bool PR_ENTRYID, PR_STORE_ENTRYID and PR_PARENT_ENTRYID of the deleted task request |
||
1192 | * |
||
1193 | * @return array|false |
||
1194 | */ |
||
1195 | public function deleteReceivedTR() { |
||
1196 | $store = $this->getTaskFolderStore(); |
||
1197 | $storeType = mapi_getprops($store, [PR_MDB_PROVIDER]); |
||
1198 | if ($storeType[PR_MDB_PROVIDER] === ZARAFA_STORE_PUBLIC_GUID) { |
||
1199 | $store = $this->getDefaultStore(); |
||
1200 | } |
||
1201 | $inbox = mapi_msgstore_getreceivefolder($store); |
||
1202 | |||
1203 | $storeProps = mapi_getprops($store, [PR_IPM_WASTEBASKET_ENTRYID]); |
||
1204 | $props = mapi_getprops($this->message, [$this->props['task_goid']]); |
||
1205 | $goid = $props[$this->props['task_goid']]; |
||
1206 | |||
1207 | // Find the task by looking for the task_goid |
||
1208 | $restriction = [ |
||
1209 | RES_PROPERTY, |
||
1210 | [ |
||
1211 | RELOP => RELOP_EQ, |
||
1212 | ULPROPTAG => $this->props['task_goid'], |
||
1213 | VALUE => $goid, |
||
1214 | ], |
||
1215 | ]; |
||
1216 | |||
1217 | $contents = mapi_folder_getcontentstable($inbox); |
||
1218 | |||
1219 | $rows = mapi_table_queryallrows($contents, [PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID], $restriction); |
||
1220 | |||
1221 | if (!empty($rows)) { |
||
1222 | // If there are multiple, just use the first |
||
1223 | $entryid = $rows[0][PR_ENTRYID]; |
||
1224 | $wastebasket = mapi_msgstore_openentry($store, $storeProps[PR_IPM_WASTEBASKET_ENTRYID]); |
||
1225 | mapi_folder_copymessages($inbox, [$entryid], $wastebasket, MESSAGE_MOVE); |
||
1226 | |||
1227 | return [PR_ENTRYID => $entryid, PR_PARENT_ENTRYID => $rows[0][PR_PARENT_ENTRYID], PR_STORE_ENTRYID => $rows[0][PR_STORE_ENTRYID]]; |
||
1228 | } |
||
1229 | |||
1230 | return false; |
||
1231 | } |
||
1232 | |||
1233 | /** |
||
1234 | * Sets recipients for the outgoing message according to type of the response. |
||
1235 | * |
||
1236 | * If it is a task update, then only recipient type MAPI_CC are taken from the task message. |
||
1237 | * |
||
1238 | * If it is accept/decline response, then PR_SENT_REPRESENTATING_XXXX are taken as recipient. |
||
1239 | * |
||
1240 | * @param mixed $outgoing outgoing mapi message |
||
1241 | * @param int $responseType response type (tdmtTaskAcc, tdmtTaskDec, tdmtTaskUpd) |
||
1242 | */ |
||
1243 | public function setRecipientsForResponse($outgoing, $responseType): bool { |
||
1244 | // Clear recipients from outgoing msg |
||
1245 | $this->deleteAllRecipients($outgoing); |
||
1246 | |||
1247 | // If it is a task update then get MAPI_CC recipients which are assignors who has asked for task update. |
||
1248 | if ($responseType == tdmtTaskUpd) { |
||
1249 | $props = mapi_getprops($this->message, [$this->props['complete']]); |
||
1250 | $isComplete = $props[$this->props['complete']]; |
||
1251 | |||
1252 | $recipTable = mapi_message_getrecipienttable($this->message); |
||
1253 | $recips = mapi_table_queryallrows($recipTable, $this->recipProps, [ |
||
1254 | RES_PROPERTY, |
||
1255 | [ |
||
1256 | RELOP => RELOP_EQ, |
||
1257 | ULPROPTAG => PR_RECIPIENT_TYPE, |
||
1258 | VALUE => ($isComplete ? MAPI_BCC : MAPI_CC), |
||
1259 | ], |
||
1260 | ]); |
||
1261 | |||
1262 | // No recipients found, return error |
||
1263 | if (empty($recips)) { |
||
1264 | return false; |
||
1265 | } |
||
1266 | |||
1267 | foreach ($recips as $recip) { |
||
1268 | $recip[PR_RECIPIENT_TYPE] = MAPI_TO; // Change recipient type to MAPI_TO |
||
1269 | mapi_message_modifyrecipients($outgoing, MODRECIP_ADD, [$recip]); |
||
1270 | } |
||
1271 | |||
1272 | return true; |
||
1273 | } |
||
1274 | |||
1275 | $orgprops = mapi_getprops($this->message, [ |
||
1276 | PR_SENT_REPRESENTING_NAME, |
||
1277 | PR_SENT_REPRESENTING_EMAIL_ADDRESS, |
||
1278 | PR_SENT_REPRESENTING_ADDRTYPE, |
||
1279 | PR_SENT_REPRESENTING_ENTRYID, |
||
1280 | PR_SUBJECT, |
||
1281 | ]); |
||
1282 | |||
1283 | $recip = [ |
||
1284 | PR_DISPLAY_NAME => $orgprops[PR_SENT_REPRESENTING_NAME], |
||
1285 | PR_EMAIL_ADDRESS => $orgprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS], |
||
1286 | PR_ADDRTYPE => $orgprops[PR_SENT_REPRESENTING_ADDRTYPE], |
||
1287 | PR_ENTRYID => $orgprops[PR_SENT_REPRESENTING_ENTRYID], |
||
1288 | PR_RECIPIENT_TYPE => MAPI_TO, ]; |
||
1289 | |||
1290 | mapi_message_modifyrecipients($outgoing, MODRECIP_ADD, [$recip]); |
||
1291 | |||
1292 | return true; |
||
1293 | } |
||
1294 | |||
1295 | /** |
||
1296 | * Deletes all recipients from given message object. |
||
1297 | * |
||
1298 | * @param mixed $message MAPI message from which recipients are to be removed |
||
1299 | */ |
||
1300 | public function deleteAllRecipients($message): void { |
||
1301 | $recipTable = mapi_message_getrecipienttable($message); |
||
1302 | $recipRows = mapi_table_queryallrows($recipTable, [PR_ROWID]); |
||
1303 | |||
1304 | foreach ($recipRows as $recipient) { |
||
1305 | mapi_message_modifyrecipients($message, MODRECIP_REMOVE, [$recipient]); |
||
1306 | } |
||
1307 | } |
||
1308 | |||
1309 | /** |
||
1310 | * Marks the record to complete and send complete update |
||
1311 | * notification to assigner. |
||
1312 | * |
||
1313 | * @return bool TRUE if the update succeeded, FALSE otherwise |
||
1314 | */ |
||
1315 | public function sendCompleteUpdate() { |
||
1330 | } |
||
1331 | |||
1332 | /** |
||
1333 | * Returns extra info about task request comments along with message body |
||
1334 | * which will be included in body while sending task request/response. |
||
1335 | * |
||
1336 | * @return string info about task request comments along with message body |
||
1337 | */ |
||
1338 | public function getTaskCommentsInfo() { |
||
1339 | return $this->taskCommentsInfo; |
||
1340 | } |
||
1341 | |||
1342 | /** |
||
1343 | * Sets an extra info about task request comments along with message body |
||
1344 | * which will be included in body while sending task request/response. |
||
1345 | * |
||
1346 | * @param string $taskCommentsInfo info about task request comments along with message body |
||
1347 | */ |
||
1348 | public function setTaskCommentsInfo($taskCommentsInfo): void { |
||
1349 | $this->taskCommentsInfo = $taskCommentsInfo; |
||
1350 | } |
||
1351 | |||
1352 | public function getSubProperties() { |
||
1371 | } |
||
1372 | } |
||
1373 |