grommunio /
grommunio-web
| 1 | <?php |
||||
| 2 | |||||
| 3 | /** |
||||
| 4 | * Contact ItemModule |
||||
| 5 | * Module which opens, creates, saves and deletes an item. It |
||||
| 6 | * extends the Module class. |
||||
| 7 | */ |
||||
| 8 | class ContactItemModule extends ItemModule { |
||||
| 9 | /** |
||||
| 10 | * Constructor. |
||||
| 11 | * |
||||
| 12 | * @param int $id unique id |
||||
| 13 | * @param array $data list of all actions |
||||
| 14 | */ |
||||
| 15 | public function __construct($id, $data) { |
||||
| 16 | $this->properties = $GLOBALS['properties']->getContactProperties(); |
||||
| 17 | |||||
| 18 | parent::__construct($id, $data); |
||||
| 19 | |||||
| 20 | $this->plaintext = false; |
||||
| 21 | } |
||||
| 22 | |||||
| 23 | /** |
||||
| 24 | * Function which opens an item. |
||||
| 25 | * |
||||
| 26 | * @param object $store MAPI Message Store Object |
||||
| 27 | * @param string $entryid entryid of the message |
||||
| 28 | * @param array $action the action data, sent by the client |
||||
| 29 | */ |
||||
| 30 | #[Override] |
||||
| 31 | public function open($store, $entryid, $action) { |
||||
| 32 | $data = []; |
||||
| 33 | $orEntryid = $entryid; |
||||
| 34 | |||||
| 35 | if ($entryid) { |
||||
| 36 | // Check if OneOff entryid is a local contact |
||||
| 37 | if ($GLOBALS['entryid']->hasAddressBookOneOff(bin2hex($entryid))) { |
||||
| 38 | try { |
||||
| 39 | $oneoff = mapi_parseoneoff($entryid); |
||||
| 40 | $ab = $GLOBALS['mapisession']->getAddressbook(); |
||||
| 41 | $ab_dir = mapi_ab_openentry($ab); |
||||
| 42 | $res = $this->searchContactsFolders($ab, $ab_dir, $oneoff['address']); |
||||
| 43 | if (count($res) > 0) { |
||||
| 44 | $entryid = $res[0][PR_ENTRYID]; |
||||
| 45 | } |
||||
| 46 | } |
||||
| 47 | catch (MAPIException $ex) { |
||||
|
0 ignored issues
–
show
|
|||||
| 48 | error_log(sprintf( |
||||
| 49 | "Unable to open contact because mapi_parseoneoff failed: %s - %s", |
||||
| 50 | get_mapi_error_name($ex->getCode()), |
||||
| 51 | $ex->getDisplayMessage() |
||||
| 52 | )); |
||||
| 53 | } |
||||
| 54 | } |
||||
| 55 | /* Check if given entryid is shared folder distlist then |
||||
| 56 | * get the store of distlist for fetching it's members. |
||||
| 57 | */ |
||||
| 58 | $storeData = $this->getStoreParentEntryIdFromEntryId($entryid); |
||||
| 59 | $store = $storeData["store"]; |
||||
| 60 | $message = $storeData["message"]; |
||||
| 61 | } |
||||
| 62 | |||||
| 63 | if (empty($message)) { |
||||
| 64 | return; |
||||
| 65 | } |
||||
| 66 | |||||
| 67 | // Open embedded message if requested |
||||
| 68 | $attachNum = !empty($action['attach_num']) ? $action['attach_num'] : false; |
||||
| 69 | if ($attachNum) { |
||||
| 70 | // get message props of sub message |
||||
| 71 | $parentMessage = $message; |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
| 72 | $message = $GLOBALS['operations']->openMessage($store, $entryid, $attachNum); |
||||
| 73 | |||||
| 74 | if (empty($message)) { |
||||
| 75 | return; |
||||
| 76 | } |
||||
| 77 | |||||
| 78 | // Check if message is distlist then we need to use different set of properties |
||||
| 79 | $props = mapi_getprops($message, [PR_MESSAGE_CLASS]); |
||||
| 80 | |||||
| 81 | if (class_match_prefix($props[PR_MESSAGE_CLASS], "IPM.Distlist")) |
||||
| 82 | // for distlist we need to use different set of properties |
||||
| 83 | $this->properties = $GLOBALS['properties']->getDistListProperties(); |
||||
| 84 | |||||
| 85 | $data['item'] = $GLOBALS['operations']->getEmbeddedMessageProps($store, $message, $this->properties, $parentMessage, $attachNum); |
||||
| 86 | } |
||||
| 87 | else { |
||||
| 88 | // Check if message is distlist then we need to use different set of properties |
||||
| 89 | $props = mapi_getprops($message, [PR_MESSAGE_CLASS]); |
||||
| 90 | |||||
| 91 | if (class_match_prefix($props[PR_MESSAGE_CLASS], "IPM.Distlist")) |
||||
| 92 | // for distlist we need to use different set of properties |
||||
| 93 | $this->properties = $GLOBALS['properties']->getDistListProperties(); |
||||
| 94 | |||||
| 95 | // get message props of the message |
||||
| 96 | $data['item'] = $GLOBALS['operations']->getMessageProps($store, $message, $this->properties, $this->plaintext, true); |
||||
| 97 | } |
||||
| 98 | |||||
| 99 | // By openentry from address book, the entryid will differ, make it same as the origin |
||||
| 100 | $data['item']['entryid'] = bin2hex($orEntryid); |
||||
| 101 | |||||
| 102 | // Allowing to hook in just before the data sent away to be sent to the client |
||||
| 103 | $GLOBALS['PluginManager']->triggerHook('server.module.contactitemmodule.open.after', [ |
||||
| 104 | 'moduleObject' => &$this, |
||||
| 105 | 'store' => $store, |
||||
| 106 | 'entryid' => $entryid, |
||||
| 107 | 'action' => $action, |
||||
| 108 | 'message' => &$message, |
||||
| 109 | 'data' => &$data, |
||||
| 110 | ]); |
||||
| 111 | |||||
| 112 | $this->addActionData('item', $data); |
||||
| 113 | $GLOBALS['bus']->addData($this->getResponseData()); |
||||
| 114 | } |
||||
| 115 | |||||
| 116 | /** |
||||
| 117 | * Function which saves an item. It sets the right properties for a contact |
||||
| 118 | * item (address book properties). |
||||
| 119 | * |
||||
| 120 | * @param object $store MAPI Message Store Object |
||||
| 121 | * @param string $parententryid parent entryid of the message |
||||
| 122 | * @param string $entryid entryid of the message |
||||
| 123 | * @param array $action the action data, sent by the client |
||||
| 124 | */ |
||||
| 125 | #[Override] |
||||
| 126 | public function save($store, $parententryid, $entryid, $action, $actionType = 'save') { |
||||
| 127 | $properiesToDelete = []; // create an array of properties which should be deleted |
||||
| 128 | // this array is passed to $GLOBALS['operations']->saveMessage() function |
||||
| 129 | |||||
| 130 | if (!$store && !$parententryid) { |
||||
|
0 ignored issues
–
show
|
|||||
| 131 | if (isset($action['props']['message_class'])) { |
||||
| 132 | $store = $GLOBALS['mapisession']->getDefaultMessageStore(); |
||||
| 133 | $parententryid = $this->getDefaultFolderEntryID($store, $action['props']['message_class']); |
||||
| 134 | } |
||||
| 135 | elseif ($entryid) { |
||||
| 136 | $data = $this->getStoreParentEntryIdFromEntryId($entryid); |
||||
| 137 | $store = $data["store"]; |
||||
| 138 | $parententryid = $data["parent_entryid"]; |
||||
| 139 | } |
||||
| 140 | } |
||||
| 141 | elseif (!$parententryid) { |
||||
| 142 | if (isset($action['props']['message_class'])) { |
||||
| 143 | $parententryid = $this->getDefaultFolderEntryID($store, $action['props']['message_class']); |
||||
| 144 | } |
||||
| 145 | } |
||||
| 146 | |||||
| 147 | if ($store && $parententryid && isset($action['props'])) { |
||||
| 148 | if (isset($action['members'])) { |
||||
| 149 | // DistList |
||||
| 150 | |||||
| 151 | // for distlist we need to use different set of properties |
||||
| 152 | $this->properties = $GLOBALS['properties']->getDistListProperties(); |
||||
| 153 | |||||
| 154 | // do conversion of client data |
||||
| 155 | $props = Conversion::mapXML2MAPI($this->properties, $action['props']); |
||||
| 156 | |||||
| 157 | // collect members |
||||
| 158 | $members = []; |
||||
| 159 | $oneoff_members = []; |
||||
| 160 | |||||
| 161 | $items = $action['members']; |
||||
| 162 | |||||
| 163 | foreach ($items as $item) { |
||||
| 164 | if (empty($item['email_address'])) { |
||||
| 165 | // if no email address is given then mapi_parseoneoff fails, so always give |
||||
| 166 | // email address, OL07 uses Unknown as email address so we do same here |
||||
| 167 | $item['email_address'] = 'Unknown'; |
||||
| 168 | } |
||||
| 169 | |||||
| 170 | $oneoff = mapi_createoneoff($item['display_name'], $item['address_type'], $item['email_address']); |
||||
| 171 | |||||
| 172 | if ($item['distlist_type'] == DL_EXTERNAL_MEMBER) { |
||||
| 173 | $member = $oneoff; |
||||
| 174 | } |
||||
| 175 | else { |
||||
| 176 | $parts = []; |
||||
| 177 | $parts['distlist_guid'] = WAB_GUID; |
||||
| 178 | $parts['distlist_type'] = $item['distlist_type']; |
||||
| 179 | $parts['entryid'] = hex2bin((string) $item['entryid']); |
||||
| 180 | $member = pack('VA16CA*', 0, $parts['distlist_guid'], $parts['distlist_type'], $parts['entryid']); |
||||
| 181 | } |
||||
| 182 | |||||
| 183 | $oneoff_members[] = $oneoff; |
||||
| 184 | $members[] = $member; |
||||
| 185 | } |
||||
| 186 | |||||
| 187 | if (!empty($members) && !empty($oneoff_members)) { |
||||
| 188 | $props[$this->properties['members']] = $members; |
||||
| 189 | $props[$this->properties['oneoff_members']] = $oneoff_members; |
||||
| 190 | } |
||||
| 191 | else { |
||||
| 192 | $properiesToDelete[] = $this->properties['members']; |
||||
| 193 | $properiesToDelete[] = $this->properties['oneoff_members']; |
||||
| 194 | } |
||||
| 195 | |||||
| 196 | unset($action['members']); |
||||
| 197 | } |
||||
| 198 | else { |
||||
| 199 | // Contact |
||||
| 200 | |||||
| 201 | $isCopyGABToContact = isset($action["message_action"], $action["message_action"]["action_type"]) && |
||||
| 202 | |||||
| 203 | $action["message_action"]["action_type"] === "copyToContact"; |
||||
| 204 | |||||
| 205 | if ($isCopyGABToContact) { |
||||
| 206 | $this->copyGABRecordProps($action); |
||||
| 207 | } |
||||
| 208 | // generate one-off entryids for email addresses |
||||
| 209 | for ($index = 1; $index < 4; ++$index) { |
||||
| 210 | if (!empty($action['props']['email_address_' . $index]) && !empty($action['props']['email_address_display_name_' . $index])) { |
||||
| 211 | $action['props']['email_address_entryid_' . $index] = bin2hex(mapi_createoneoff($action['props']['email_address_display_name_' . $index], $action['props']['email_address_type_' . $index], $action['props']['email_address_' . $index])); |
||||
| 212 | } |
||||
| 213 | } |
||||
| 214 | |||||
| 215 | // set properties for primary fax number |
||||
| 216 | if (isset($action['props']['fax_1_email_address']) && !empty($action['props']['fax_1_email_address'])) { |
||||
| 217 | $action['props']['fax_1_original_entryid'] = bin2hex(mapi_createoneoff($action['props']['fax_1_original_display_name'], $action['props']['fax_1_address_type'], $action['props']['fax_1_email_address'], MAPI_UNICODE)); |
||||
| 218 | } |
||||
| 219 | else { |
||||
| 220 | // delete properties to remove previous values |
||||
| 221 | $properiesToDelete[] = $this->properties['fax_1_address_type']; |
||||
| 222 | $properiesToDelete[] = $this->properties['fax_1_original_display_name']; |
||||
| 223 | $properiesToDelete[] = $this->properties['fax_1_email_address']; |
||||
| 224 | $properiesToDelete[] = $this->properties['fax_1_original_entryid']; |
||||
| 225 | } |
||||
| 226 | |||||
| 227 | // set properties for business fax number |
||||
| 228 | if (isset($action['props']['fax_2_email_address']) && !empty($action['props']['fax_2_email_address'])) { |
||||
| 229 | $action['props']['fax_2_original_entryid'] = bin2hex(mapi_createoneoff($action['props']['fax_2_original_display_name'], $action['props']['fax_2_address_type'], $action['props']['fax_2_email_address'], MAPI_UNICODE)); |
||||
| 230 | } |
||||
| 231 | else { |
||||
| 232 | $properiesToDelete[] = $this->properties['fax_2_address_type']; |
||||
| 233 | $properiesToDelete[] = $this->properties['fax_2_original_display_name']; |
||||
| 234 | $properiesToDelete[] = $this->properties['fax_2_email_address']; |
||||
| 235 | $properiesToDelete[] = $this->properties['fax_2_original_entryid']; |
||||
| 236 | } |
||||
| 237 | |||||
| 238 | // set properties for home fax number |
||||
| 239 | if (isset($action['props']['fax_3_email_address']) && !empty($action['props']['fax_3_email_address'])) { |
||||
| 240 | $action['props']['fax_3_original_entryid'] = bin2hex(mapi_createoneoff($action['props']['fax_3_original_display_name'], $action['props']['fax_3_address_type'], $action['props']['fax_3_email_address'], MAPI_UNICODE)); |
||||
| 241 | } |
||||
| 242 | else { |
||||
| 243 | $properiesToDelete[] = $this->properties['fax_3_address_type']; |
||||
| 244 | $properiesToDelete[] = $this->properties['fax_3_original_display_name']; |
||||
| 245 | $properiesToDelete[] = $this->properties['fax_3_email_address']; |
||||
| 246 | $properiesToDelete[] = $this->properties['fax_3_original_entryid']; |
||||
| 247 | } |
||||
| 248 | |||||
| 249 | // check for properties which should be deleted |
||||
| 250 | if (isset($action['entryid']) && !empty($action['entryid'])) { |
||||
| 251 | // check for empty email address properties |
||||
| 252 | for ($i = 1; $i < 4; ++$i) { |
||||
| 253 | if (isset($action['props']['email_address_' . $i]) && empty($action['props']['email_address_' . $i])) { |
||||
| 254 | array_push($properiesToDelete, $this->properties['email_address_entryid_' . $i]); |
||||
| 255 | array_push($properiesToDelete, $this->properties['email_address_' . $i]); |
||||
| 256 | array_push($properiesToDelete, $this->properties['email_address_display_name_' . $i]); |
||||
| 257 | array_push($properiesToDelete, $this->properties['email_address_display_name_email_' . $i]); |
||||
| 258 | array_push($properiesToDelete, $this->properties['email_address_type_' . $i]); |
||||
| 259 | } |
||||
| 260 | } |
||||
| 261 | |||||
| 262 | // check for empty address_book_mv and address_book_long properties |
||||
| 263 | if (isset($action['props']['address_book_long']) && $action['props']['address_book_long'] === 0) { |
||||
| 264 | $properiesToDelete[] = $this->properties['address_book_mv']; |
||||
| 265 | $properiesToDelete[] = $this->properties['address_book_long']; |
||||
| 266 | } |
||||
| 267 | |||||
| 268 | // Check if the birthday and anniversary properties are empty. If so delete them. |
||||
| 269 | if (array_key_exists('birthday', $action['props']) && empty($action['props']['birthday'])) { |
||||
| 270 | array_push($properiesToDelete, $this->properties['birthday']); |
||||
| 271 | array_push($properiesToDelete, $this->properties['birthday_eventid']); |
||||
| 272 | if (!empty($action['props']['birthday_eventid'])) { |
||||
| 273 | $this->deleteSpecialDateAppointment($store, $action['props']['birthday_eventid']); |
||||
| 274 | } |
||||
| 275 | } |
||||
| 276 | |||||
| 277 | if (array_key_exists('wedding_anniversary', $action['props']) && empty($action['props']['wedding_anniversary'])) { |
||||
| 278 | array_push($properiesToDelete, $this->properties['wedding_anniversary']); |
||||
| 279 | array_push($properiesToDelete, $this->properties['anniversary_eventid']); |
||||
| 280 | if (!empty($action['props']['anniversary_eventid'])) { |
||||
| 281 | $this->deleteSpecialDateAppointment($store, $action['props']['anniversary_eventid']); |
||||
| 282 | } |
||||
| 283 | } |
||||
| 284 | } |
||||
| 285 | |||||
| 286 | /* |
||||
| 287 | * convert all line endings(LF) into CRLF |
||||
| 288 | * XML parser will normalize all CR, LF and CRLF into LF |
||||
| 289 | * but outlook(windows) uses CRLF as line ending |
||||
| 290 | */ |
||||
| 291 | if (isset($action['props']['business_address'])) { |
||||
| 292 | $action['props']['business_address'] = str_replace('\n', '\r\n', $action['props']['business_address']); |
||||
| 293 | } |
||||
| 294 | |||||
| 295 | if (isset($action['props']['home_address'])) { |
||||
| 296 | $action['props']['home_address'] = str_replace('\n', '\r\n', $action['props']['home_address']); |
||||
| 297 | } |
||||
| 298 | |||||
| 299 | if (isset($action['props']['other_address'])) { |
||||
| 300 | $action['props']['other_address'] = str_replace('\n', '\r\n', $action['props']['other_address']); |
||||
| 301 | } |
||||
| 302 | |||||
| 303 | // check birthday props to make an appointment |
||||
| 304 | if (!empty($action['props']['birthday'])) { |
||||
| 305 | $action['props']['birthday_eventid'] = $this->updateAppointments($store, $action, 'birthday'); |
||||
| 306 | } |
||||
| 307 | |||||
| 308 | // check anniversary props to make an appointment |
||||
| 309 | if (!empty($action['props']['wedding_anniversary'])) { |
||||
| 310 | $action['props']['anniversary_eventid'] = $this->updateAppointments($store, $action, 'wedding_anniversary'); |
||||
| 311 | } |
||||
| 312 | |||||
| 313 | // do the conversion when all processing has been finished |
||||
| 314 | $props = Conversion::mapXML2MAPI($this->properties, $action['props']); |
||||
| 315 | } |
||||
| 316 | |||||
| 317 | $messageProps = []; |
||||
| 318 | |||||
| 319 | $result = $GLOBALS['operations']->saveMessage($store, $entryid, $parententryid, $props, $messageProps, [], $action['attachments'] ?? [], $properiesToDelete); |
||||
| 320 | |||||
| 321 | if ($result) { |
||||
| 322 | $GLOBALS['bus']->notify(bin2hex($parententryid), TABLE_SAVE, $messageProps); |
||||
| 323 | |||||
| 324 | if ($isCopyGABToContact) { |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
| 325 | $message = mapi_msgstore_openentry($store, $messageProps[PR_ENTRYID]); |
||||
| 326 | $messageProps = mapi_getprops($message, $this->properties); |
||||
| 327 | } |
||||
| 328 | |||||
| 329 | $this->addActionData('update', ['item' => Conversion::mapMAPI2XML($this->properties, $messageProps)]); |
||||
| 330 | $GLOBALS['bus']->addData($this->getResponseData()); |
||||
| 331 | } |
||||
| 332 | } |
||||
| 333 | } |
||||
| 334 | |||||
| 335 | /** |
||||
| 336 | * Function copy the some property from address book record to contact props. |
||||
| 337 | * |
||||
| 338 | * @param array $action the action data, sent by the client |
||||
| 339 | */ |
||||
| 340 | public function copyGABRecordProps(&$action) { |
||||
| 341 | $addrbook = $GLOBALS["mapisession"]->getAddressbook(); |
||||
| 342 | $abitem = mapi_ab_openentry($addrbook, hex2bin((string) $action["message_action"]["source_entryid"])); |
||||
| 343 | $abItemProps = mapi_getprops($abitem, [ |
||||
| 344 | PR_COMPANY_NAME, |
||||
| 345 | PR_ASSISTANT, |
||||
| 346 | PR_BUSINESS_TELEPHONE_NUMBER, |
||||
| 347 | PR_BUSINESS2_TELEPHONE_NUMBER, |
||||
| 348 | PR_HOME2_TELEPHONE_NUMBER, |
||||
| 349 | PR_STREET_ADDRESS, |
||||
| 350 | PR_LOCALITY, |
||||
| 351 | PR_STATE_OR_PROVINCE, |
||||
| 352 | PR_POSTAL_CODE, |
||||
| 353 | PR_COUNTRY, |
||||
| 354 | PR_MOBILE_TELEPHONE_NUMBER, |
||||
| 355 | ]); |
||||
| 356 | $action["props"]["company_name"] = $abItemProps[PR_COMPANY_NAME] ?? ''; |
||||
| 357 | $action["props"]["assistant"] = $abItemProps[PR_ASSISTANT] ?? ''; |
||||
| 358 | $action["props"]["business_telephone_number"] = $abItemProps[PR_BUSINESS_TELEPHONE_NUMBER] ?? ''; |
||||
| 359 | $action["props"]["business2_telephone_number"] = $abItemProps[PR_BUSINESS2_TELEPHONE_NUMBER] ?? ''; |
||||
| 360 | $action["props"]["home2_telephone_number"] = $abItemProps[PR_HOME2_TELEPHONE_NUMBER] ?? ''; |
||||
| 361 | $action["props"]["home_address_street"] = $abItemProps[PR_STREET_ADDRESS] ?? ''; |
||||
| 362 | $action["props"]["home_address_city"] = $abItemProps[PR_LOCALITY] ?? ''; |
||||
| 363 | $action["props"]["home_address_state"] = $abItemProps[PR_STATE_OR_PROVINCE] ?? ''; |
||||
| 364 | $action["props"]["home_address_postal_code"] = $abItemProps[PR_POSTAL_CODE] ?? ''; |
||||
| 365 | $action["props"]["home_address_country"] = $abItemProps[PR_COUNTRY] ?? ''; |
||||
| 366 | |||||
| 367 | $action["props"]["cellular_telephone_number"] = $abItemProps[PR_MOBILE_TELEPHONE_NUMBER] ?? ''; |
||||
| 368 | |||||
| 369 | // Set the home_address property value |
||||
| 370 | $props = ["street", "city", "state", "postal_code", "country"]; |
||||
| 371 | $homeAddress = ""; |
||||
| 372 | foreach ($props as $index => $prop) { |
||||
| 373 | if (isset($action["props"]["home_address_" . $prop]) && !empty($action["props"]["home_address_" . $prop])) { |
||||
| 374 | $homeAddress .= $action["props"]["home_address_" . $prop] . " "; |
||||
| 375 | if ($prop == "street" || $prop == "postal_code") { |
||||
| 376 | $homeAddress .= PHP_EOL; |
||||
| 377 | } |
||||
| 378 | } |
||||
| 379 | } |
||||
| 380 | |||||
| 381 | $action["props"]["home_address"] = $homeAddress; |
||||
| 382 | } |
||||
| 383 | |||||
| 384 | /** |
||||
| 385 | * Function which deletes an item. Extended here to also delete corresponding birthday/anniversary |
||||
| 386 | * appointments from calendar. |
||||
| 387 | * |
||||
| 388 | * @param object $store MAPI Message Store Object |
||||
| 389 | * @param string $parententryid parent entryid of the message |
||||
| 390 | * @param string $entryid entryid of the message |
||||
| 391 | * @param array $action the action data, sent by the client |
||||
| 392 | */ |
||||
| 393 | #[Override] |
||||
| 394 | public function delete($store, $parententryid, $entryid, $action) { |
||||
| 395 | $message = false; |
||||
| 396 | if (!$store && !$parententryid && $entryid) { |
||||
|
0 ignored issues
–
show
|
|||||
| 397 | $data = $this->getStoreParentEntryIdFromEntryId($entryid); |
||||
| 398 | $store = $data["store"]; |
||||
| 399 | $message = $data["message"]; |
||||
| 400 | $parententryid = $data["parent_entryid"]; |
||||
| 401 | } |
||||
| 402 | |||||
| 403 | if ($store && $entryid) { |
||||
| 404 | try { |
||||
| 405 | if ($message === false) { |
||||
|
0 ignored issues
–
show
|
|||||
| 406 | $message = $GLOBALS["operations"]->openMessage($store, $entryid); |
||||
| 407 | } |
||||
| 408 | |||||
| 409 | $props = mapi_getprops($message, [$this->properties['anniversary_eventid'], $this->properties['birthday_eventid']]); |
||||
| 410 | |||||
| 411 | // if any of the appointment entryid exists then delete it |
||||
| 412 | if (!empty($props[$this->properties['birthday_eventid']])) { |
||||
| 413 | $this->deleteSpecialDateAppointment($store, bin2hex((string) $props[$this->properties['birthday_eventid']])); |
||||
| 414 | } |
||||
| 415 | |||||
| 416 | if (!empty($props[$this->properties['anniversary_eventid']])) { |
||||
| 417 | $this->deleteSpecialDateAppointment($store, bin2hex((string) $props[$this->properties['anniversary_eventid']])); |
||||
| 418 | } |
||||
| 419 | } |
||||
| 420 | catch (MAPIException $e) { |
||||
| 421 | // if any error occurs in deleting appointments then we shouldn't block deletion of contact item |
||||
| 422 | // so ignore errors now |
||||
| 423 | $e->setHandled(); |
||||
| 424 | } |
||||
| 425 | |||||
| 426 | parent::delete($store, $parententryid, $entryid, $action); |
||||
| 427 | } |
||||
| 428 | } |
||||
| 429 | |||||
| 430 | /** |
||||
| 431 | * Function which retrieve the store, parent_entryid from record entryid. |
||||
| 432 | * |
||||
| 433 | * @param $entryid entryid of the message |
||||
| 434 | * |
||||
| 435 | * @return array which contains store and message object and parent entryid of that message |
||||
| 436 | */ |
||||
| 437 | public function getStoreParentEntryIdFromEntryId($entryid) { |
||||
| 438 | $message = $GLOBALS['mapisession']->openMessage($entryid); |
||||
| 439 | $messageStoreInfo = mapi_getprops($message, [PR_STORE_ENTRYID, PR_PARENT_ENTRYID]); |
||||
| 440 | $store = $GLOBALS['mapisession']->openMessageStore($messageStoreInfo[PR_STORE_ENTRYID]); |
||||
| 441 | $parentEntryid = $messageStoreInfo[PR_PARENT_ENTRYID]; |
||||
| 442 | |||||
| 443 | return ["message" => $message, "store" => $store, "parent_entryid" => $parentEntryid]; |
||||
| 444 | } |
||||
| 445 | |||||
| 446 | /** |
||||
| 447 | * Function will create/update a yearly recurring appointment on the respective date of birthday or anniversary in user's calendar. |
||||
| 448 | * |
||||
| 449 | * @param object $store MAPI Message Store Object |
||||
| 450 | * @param array $action the action data, sent by the client |
||||
| 451 | * @param string $type type of appointment that should be created/updated, valid values are 'birthday' and 'wedding_anniversary' |
||||
| 452 | * |
||||
| 453 | * @return HexString entryid of the newly created appointment in hex format |
||||
|
0 ignored issues
–
show
The type
HexString was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 454 | */ |
||||
| 455 | public function updateAppointments($store, $action, $type) { |
||||
| 456 | $result = false; |
||||
| 457 | |||||
| 458 | $root = mapi_msgstore_openentry($store); |
||||
| 459 | $rootProps = mapi_getprops($root, [PR_IPM_APPOINTMENT_ENTRYID, PR_STORE_ENTRYID]); |
||||
| 460 | $parentEntryId = bin2hex((string) $rootProps[PR_IPM_APPOINTMENT_ENTRYID]); |
||||
| 461 | $storeEntryId = bin2hex((string) $rootProps[PR_STORE_ENTRYID]); |
||||
| 462 | |||||
| 463 | $actionProps = $action['props']; |
||||
| 464 | $subject = !empty($actionProps['subject']) ? $actionProps['subject'] : _('Untitled'); |
||||
| 465 | $subject = ($type === 'birthday' ? sprintf(_('%s\'s Birthday'), $subject) : sprintf(_('%s\'s Anniversary'), $subject)); |
||||
| 466 | |||||
| 467 | // UTC time |
||||
| 468 | $startDateUTC = $actionProps[$type]; |
||||
| 469 | $dueDateUTC = $actionProps[$type] + (24 * 60 * 60); // ONE DAY is added to set duedate of item. |
||||
| 470 | |||||
| 471 | // get local time from UTC time |
||||
| 472 | $recur = new Recurrence($store, []); |
||||
|
0 ignored issues
–
show
The type
Recurrence was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 473 | $startDate = $recur->fromGMT($actionProps, $startDateUTC); |
||||
| 474 | $dueDate = $recur->fromGMT($actionProps, $dueDateUTC); |
||||
| 475 | |||||
| 476 | // Find the number of minutes since the start of the year to the given month, |
||||
| 477 | // taking leap years into account. |
||||
| 478 | $month = date('m', $startDate); |
||||
| 479 | $year = date('y', $startDate); |
||||
| 480 | |||||
| 481 | $d1 = new DateTime(); |
||||
| 482 | $d1->setDate($year, 1, 1); |
||||
|
0 ignored issues
–
show
$year of type string is incompatible with the type integer expected by parameter $year of DateTime::setDate().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 483 | $d2 = new DateTime(); |
||||
| 484 | $d2->setDate($year, $month, 1); |
||||
|
0 ignored issues
–
show
$month of type string is incompatible with the type integer expected by parameter $month of DateTime::setDate().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 485 | |||||
| 486 | $diff = $d2->diff($d1); |
||||
| 487 | $month = $diff->days * 24 * 60; |
||||
| 488 | |||||
| 489 | $props = [ |
||||
| 490 | 'message_class' => 'IPM.Appointment', |
||||
| 491 | 'icon_index' => 1025, |
||||
| 492 | 'busystatus' => fbFree, |
||||
| 493 | 'meeting' => olNonMeeting, |
||||
| 494 | 'object_type' => MAPI_MESSAGE, |
||||
| 495 | 'message_flags' => MSGFLAG_READ | MSGFLAG_UNSENT, |
||||
| 496 | 'subject' => $subject, |
||||
| 497 | |||||
| 498 | 'startdate' => $startDateUTC, |
||||
| 499 | 'duedate' => $dueDateUTC, |
||||
| 500 | 'commonstart' => $startDateUTC, |
||||
| 501 | 'commonend' => $dueDateUTC, |
||||
| 502 | 'alldayevent' => true, |
||||
| 503 | 'duration' => 1440, |
||||
| 504 | 'reminder' => true, |
||||
| 505 | 'reminder_minutes' => 1080, |
||||
| 506 | 'reminder_time' => $startDateUTC, |
||||
| 507 | 'flagdueby' => $startDateUTC - (1080 * 60), |
||||
| 508 | |||||
| 509 | 'recurring' => true, |
||||
| 510 | 'recurring_reset' => true, |
||||
| 511 | 'startocc' => 0, |
||||
| 512 | 'endocc' => 1440, |
||||
| 513 | 'start' => $startDate, |
||||
| 514 | 'end' => $dueDate, |
||||
| 515 | 'term' => 35, |
||||
| 516 | 'everyn' => 12, |
||||
| 517 | 'subtype' => 2, |
||||
| 518 | 'type' => 13, |
||||
| 519 | 'regen' => 0, |
||||
| 520 | 'month' => $month, |
||||
| 521 | 'monthday' => date('j', $startDate), |
||||
| 522 | 'timezone' => $actionProps['timezone'], |
||||
| 523 | 'timezonedst' => $actionProps['timezonedst'], |
||||
| 524 | 'dststartmonth' => $actionProps['dststartmonth'], |
||||
| 525 | 'dststartweek' => $actionProps['dststartweek'], |
||||
| 526 | 'dststartday' => $actionProps['dststartday'], |
||||
| 527 | 'dststarthour' => $actionProps['dststarthour'], |
||||
| 528 | 'dstendmonth' => $actionProps['dstendmonth'], |
||||
| 529 | 'dstendweek' => $actionProps['dstendweek'], |
||||
| 530 | 'dstendday' => $actionProps['dstendday'], |
||||
| 531 | 'dstendhour' => $actionProps['dstendhour'], |
||||
| 532 | ]; |
||||
| 533 | |||||
| 534 | $data = []; |
||||
| 535 | $data['store'] = $storeEntryId; |
||||
| 536 | $data['parententryid'] = $parentEntryId; |
||||
| 537 | |||||
| 538 | $entryid = false; |
||||
| 539 | // if entryid is provided then update existing appointment, else create new one |
||||
| 540 | if ($type === 'birthday' && !empty($actionProps['birthday_eventid'])) { |
||||
| 541 | $entryid = $actionProps['birthday_eventid']; |
||||
| 542 | } |
||||
| 543 | elseif ($type === 'wedding_anniversary' && !empty($actionProps['anniversary_eventid'])) { |
||||
| 544 | $entryid = $actionProps['anniversary_eventid']; |
||||
| 545 | } |
||||
| 546 | |||||
| 547 | if ($entryid !== false) { |
||||
| 548 | $data['entryid'] = $entryid; |
||||
| 549 | } |
||||
| 550 | |||||
| 551 | if (isset($action['timezone_iana'])) { |
||||
| 552 | $props['timezone_iana'] = $action['timezone_iana']; |
||||
| 553 | } |
||||
| 554 | |||||
| 555 | $data['props'] = $props; |
||||
| 556 | |||||
| 557 | // Save appointment (saveAppointment takes care of creating/modifying exceptions to recurring |
||||
| 558 | // items if necessary) |
||||
| 559 | try { |
||||
| 560 | $messageProps = $GLOBALS['operations']->saveAppointment($store, hex2bin((string) $entryid), hex2bin($parentEntryId), $data); |
||||
| 561 | } |
||||
| 562 | catch (MAPIException $e) { |
||||
| 563 | // if the appointment is deleted then create a new one |
||||
| 564 | if ($e->getCode() == MAPI_E_NOT_FOUND) { |
||||
| 565 | $e->setHandled(); |
||||
| 566 | $messageProps = $GLOBALS['operations']->saveAppointment($store, false, hex2bin($parentEntryId), $data); |
||||
| 567 | } |
||||
| 568 | } |
||||
| 569 | |||||
| 570 | // Notify the bus if the save was OK |
||||
| 571 | if ($messageProps && !(is_array($messageProps) && isset($messageProps['error']))) { |
||||
| 572 | $GLOBALS['bus']->notify($parentEntryId, TABLE_SAVE, $messageProps); |
||||
| 573 | $result = bin2hex((string) $messageProps[PR_ENTRYID]); |
||||
| 574 | } |
||||
| 575 | |||||
| 576 | return $result; |
||||
|
0 ignored issues
–
show
|
|||||
| 577 | } |
||||
| 578 | |||||
| 579 | /** |
||||
| 580 | * Function will delete the appointment on the respective date of birthday or anniversary in user's calendar. |
||||
| 581 | * |
||||
| 582 | * @param object $store MAPI Message Store Object |
||||
| 583 | * @param $entryid of the message with will be deleted,sent by the client |
||||
|
0 ignored issues
–
show
The type
of was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 584 | */ |
||||
| 585 | public function deleteSpecialDateAppointment($store, $entryid) { |
||||
| 586 | $root = mapi_msgstore_openentry($store); |
||||
| 587 | $rootProps = mapi_getprops($root, [PR_IPM_APPOINTMENT_ENTRYID, PR_STORE_ENTRYID]); |
||||
| 588 | $parentEntryId = $rootProps[PR_IPM_APPOINTMENT_ENTRYID]; |
||||
| 589 | $storeEntryId = $rootProps[PR_STORE_ENTRYID]; |
||||
| 590 | |||||
| 591 | $props = []; |
||||
| 592 | $props[PR_PARENT_ENTRYID] = $parentEntryId; |
||||
| 593 | $props[PR_ENTRYID] = hex2bin((string) $entryid); |
||||
| 594 | $props[PR_STORE_ENTRYID] = $storeEntryId; |
||||
| 595 | |||||
| 596 | $result = $GLOBALS['operations']->deleteMessages($store, $parentEntryId, $props[PR_ENTRYID]); |
||||
| 597 | |||||
| 598 | if ($result) { |
||||
| 599 | $GLOBALS['bus']->notify(bin2hex((string) $parentEntryId), TABLE_DELETE, $props); |
||||
| 600 | } |
||||
| 601 | } |
||||
| 602 | |||||
| 603 | /** |
||||
| 604 | * This function searches the private contact folders for users and returns an array with data. |
||||
| 605 | * Please note that the returning array must be UTF8. |
||||
| 606 | * |
||||
| 607 | * @param resource $ab The addressbook |
||||
| 608 | * @param resource $ab_dir The addressbook container |
||||
| 609 | * @param string $searchstr The search query, case is ignored |
||||
| 610 | */ |
||||
| 611 | public function searchContactsFolders($ab, $ab_dir, $searchstr) { |
||||
| 612 | $r = []; |
||||
| 613 | $abhtable = mapi_folder_gethierarchytable($ab_dir, MAPI_DEFERRED_ERRORS | CONVENIENT_DEPTH); |
||||
| 614 | $abcntfolders = mapi_table_queryallrows($abhtable, [PR_ENTRYID, PR_AB_PROVIDER_ID, PR_DISPLAY_NAME]); |
||||
| 615 | $restriction = [ |
||||
| 616 | RES_CONTENT, |
||||
| 617 | [ |
||||
| 618 | FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE, |
||||
| 619 | ULPROPTAG => PR_SMTP_ADDRESS, |
||||
| 620 | VALUE => [PR_SMTP_ADDRESS => $searchstr], |
||||
| 621 | ], |
||||
| 622 | ]; |
||||
| 623 | // restriction on hierarchy table for PR_AB_PROVIDER_ID |
||||
| 624 | // seems not to work, just loop through |
||||
| 625 | foreach ($abcntfolders as $abcntfolder) { |
||||
| 626 | if ($abcntfolder[PR_AB_PROVIDER_ID] == ZARAFA_CONTACTS_GUID) { |
||||
| 627 | $abfldentry = mapi_ab_openentry($ab, $abcntfolder[PR_ENTRYID]); |
||||
| 628 | $abfldcontents = mapi_folder_getcontentstable($abfldentry); |
||||
| 629 | mapi_table_restrict($abfldcontents, $restriction); |
||||
| 630 | $r = mapi_table_queryallrows($abfldcontents, [PR_ENTRYID]); |
||||
| 631 | if (is_array($r) && !empty($r)) { |
||||
| 632 | return $r; |
||||
| 633 | } |
||||
| 634 | } |
||||
| 635 | } |
||||
| 636 | |||||
| 637 | return $r; |
||||
| 638 | } |
||||
| 639 | } |
||||
| 640 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths