Conditions | 10 |
Paths | 15 |
Total Lines | 55 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
33 | public function schedule(Message $iTipMessage) { |
||
34 | $this->logger->trace("method: %s - recipient: %s - significantChange: %d - scheduleStatus: %s - message: %s", $iTipMessage->method, $iTipMessage->recipient, $iTipMessage->significantChange, $iTipMessage->scheduleStatus, $iTipMessage->message->serialize()); |
||
35 | |||
36 | if (!$iTipMessage->significantChange) { |
||
37 | if (!$iTipMessage->scheduleStatus) { |
||
38 | $iTipMessage->scheduleStatus = "1.0;We got the message, but it's not significant enough to warrant an email"; |
||
39 | } |
||
40 | |||
41 | return; |
||
42 | } |
||
43 | |||
44 | $recipient = preg_replace('!^mailto:!i', '', $iTipMessage->recipient); |
||
45 | $session = $this->gDavBackend->GetSession(); |
||
46 | $addrbook = $this->gDavBackend->GetAddressBook(); |
||
47 | $store = $this->gDavBackend->GetStore($this->gDavBackend->GetUser()); |
||
48 | $storeprops = mapi_getprops($store, [PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID]); |
||
49 | if (!isset($storeprops[PR_IPM_OUTBOX_ENTRYID]) || !isset($storeprops[PR_IPM_SENTMAIL_ENTRYID])) { |
||
50 | /* handle error */ |
||
51 | $this->logger->error("no outbox found aborting user: %s", $this->gDavBackend->GetUser()); |
||
52 | |||
53 | return; |
||
54 | } |
||
55 | |||
56 | /* create message and convert */ |
||
57 | $outbox = mapi_msgstore_openentry($store, $storeprops[PR_IPM_OUTBOX_ENTRYID]); |
||
58 | $newmessage = mapi_folder_createmessage($outbox); |
||
59 | mapi_icaltomapi($session, $store, $addrbook, $newmessage, $iTipMessage->message->serialize(), false); |
||
60 | mapi_setprops($newmessage, [PR_SENTMAIL_ENTRYID => $storeprops[PR_IPM_SENTMAIL_ENTRYID], PR_DELETE_AFTER_SUBMIT => false]); |
||
61 | |||
62 | /* clean the recipients (needed since mapi_icaltomapi does not take IC2M_NO_ORGANIZER) */ |
||
63 | $recipientTable = mapi_message_getrecipienttable($newmessage); |
||
64 | $recipientRows = mapi_table_queryallrows($recipientTable, [PR_SMTP_ADDRESS, PR_ROWID]); |
||
65 | $removeRecipients = []; |
||
66 | foreach ($recipientRows as $key => $recip) { |
||
67 | if (!isset($recip[PR_SMTP_ADDRESS])) { |
||
68 | continue; |
||
69 | } |
||
70 | if (strcasecmp($recip[PR_SMTP_ADDRESS], $recipient) != 0) { |
||
71 | $removeRecipients[] = $recip; |
||
72 | } |
||
73 | } |
||
74 | if (count($removeRecipients) == count($recipientRows)) { |
||
75 | $this->logger->error("message will have no recipients. List to remove: %s - recipientRows: %s", $removeRecipients, $recipientRows); |
||
76 | |||
77 | return; |
||
78 | } |
||
79 | if (count($removeRecipients) > 0) { |
||
80 | mapi_message_modifyrecipients($newmessage, MODRECIP_REMOVE, $removeRecipients); |
||
81 | } |
||
82 | |||
83 | /* save message and send */ |
||
84 | mapi_savechanges($newmessage); |
||
85 | mapi_message_submitmessage($newmessage); |
||
86 | $this->logger->info("email sent, recipient: %s", $recipient); |
||
87 | $iTipMessage->scheduleStatus = '1.1;Scheduling message sent via iMip'; |
||
88 | } |
||
90 |