| @@ -6,13 +6,50 @@ | ||
| 6 | 6 | use AcyMailing\Helpers\MailerHelper; |
| 7 | 7 | |
| 8 | 8 | trait ForwardMailboxAction |
| 9 | 9 | { |
| 10 | - public function onAcymMailboxActionDefine(&$actions) | |
| 10 | + protected function initMailboxActions(): void | |
| 11 | 11 | { |
| 12 | + $this->mailboxActions = [ | |
| 13 | + 'forward_specific' => acym_translation('ACYM_FORWARD_EMAIL'), | |
| 14 | + 'forward_list' => acym_translation('ACYM_FORWARD_TO_A_LIST'), | |
| 15 | + ]; | |
| 16 | + } | |
| 17 | + | |
| 18 | + public function displayMailboxActionOptions_forward_specific(string $fieldName): void | |
| 19 | + { | |
| 20 | + ?> | |
| 21 | + <input type="text" | |
| 22 | + name="<?php echo esc_attr($fieldName.'[addresses]'); ?>" | |
| 23 | + placeholder="[email protected],[email protected]"><br /> | |
| 24 | + <?php | |
| 25 | + $this->displayForwardTemplateChoice($fieldName); | |
| 26 | + } | |
| 27 | + | |
| 28 | + public function displayMailboxActionOptions_forward_list(string $fieldName): void | |
| 29 | + { | |
| 12 | 30 | $listClass = new ListClass(); |
| 13 | - $lists = $listClass->getAllWithIdName(); | |
| 31 | + ?> | |
| 32 | + <div class="intext_select_mailbox cell"> | |
| 33 | + <?php acym_select( | |
| 34 | + $listClass->getAllWithIdName(), | |
| 35 | + $fieldName.'[list_id]', | |
| 36 | + null, | |
| 37 | + ['class' => 'acym__select'], | |
| 38 | + 'value', | |
| 39 | + 'text', | |
| 40 | + null, | |
| 41 | + false, | |
| 42 | + true | |
| 43 | + ); ?> | |
| 44 | + </div> | |
| 45 | + <br /><br /> | |
| 46 | + <?php | |
| 47 | + $this->displayForwardTemplateChoice($fieldName); | |
| 48 | + } | |
| 14 | 49 | |
| 50 | + private function displayForwardTemplateChoice(string $fieldName): void | |
| 51 | + { | |
| 15 | 52 | $mailClass = new MailClass(); |
| 16 | 53 | $templates = $mailClass->getTemplatesForMailboxAction(); |
| 17 | 54 | |
| 18 | 55 | $firstOption = new stdClass(); |
| @@ -19,48 +56,21 @@ | ||
| 19 | 56 | $firstOption->id = 0; |
| 20 | 57 | $firstOption->name = acym_translation('ACYM_CHOOSE_TEMPLATE'); |
| 21 | 58 | array_unshift($templates, $firstOption); |
| 22 | 59 | |
| 23 | - $actions['forward_specific'] = new stdClass(); | |
| 24 | - $actions['forward_specific']->name = acym_translation('ACYM_FORWARD_EMAIL'); | |
| 25 | - $actions['forward_specific']->option = '<input type="text" | |
| 26 | - name="acym_action[__num__][forward_specific][addresses]" | |
| 27 | - placeholder="[email protected],[email protected]"><br />'; | |
| 28 | - $actions['forward_specific']->option .= acym_translationSprintf( | |
| 29 | - 'ACYM_INCLUDE_IN_TEMPLATE', | |
| 30 | - '<div class="intext_select_mailbox cell">'.acym_select( | |
| 60 | + $templateSelect = '<div class="intext_select_mailbox cell">'.acym_select( | |
| 31 | 61 | $templates, |
| 32 | - 'acym_action[__num__][forward_specific][template_id]', | |
| 62 | + $fieldName.'[template_id]', | |
| 33 | 63 | null, |
| 34 | 64 | ['class' => 'acym__select'], |
| 35 | 65 | 'id', |
| 36 | 66 | 'name' |
| 37 | - ).'</div>' | |
| 38 | - ); | |
| 39 | - $actions['forward_specific']->option .= acym_info('ACYM_INCLUDE_IN_TEMPLATE_DESC'); | |
| 67 | + ).'</div>'; | |
| 40 | 68 | |
| 41 | - $actions['forward_list'] = new stdClass(); | |
| 42 | - $actions['forward_list']->name = acym_translation('ACYM_FORWARD_TO_A_LIST'); | |
| 43 | - $actions['forward_list']->option = '<div class="intext_select_mailbox cell">'; | |
| 44 | - $actions['forward_list']->option .= acym_select( | |
| 45 | - $lists, | |
| 46 | - 'acym_action[__num__][forward_list][list_id]', | |
| 47 | - null, | |
| 48 | - ['class' => 'acym__select'] | |
| 49 | - ); | |
| 50 | - $actions['forward_list']->option .= '</div><br /><br />'; | |
| 51 | - $actions['forward_list']->option .= acym_translationSprintf( | |
| 52 | - 'ACYM_INCLUDE_IN_TEMPLATE', | |
| 53 | - '<div class="intext_select_mailbox cell">'.acym_select( | |
| 54 | - $templates, | |
| 55 | - 'acym_action[__num__][forward_list][template_id]', | |
| 56 | - null, | |
| 57 | - ['class' => 'acym__select'], | |
| 58 | - 'id', | |
| 59 | - 'name' | |
| 60 | - ).'</div>' | |
| 61 | - ); | |
| 62 | - $actions['forward_list']->option .= acym_info('ACYM_INCLUDE_IN_TEMPLATE_DESC'); | |
| 69 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The select is built and escaped by acym_select just above, and its position in the sentence depends on the language. | |
| 70 | + echo acym_translationSprintf('ACYM_INCLUDE_IN_TEMPLATE', $templateSelect); | |
| 71 | + | |
| 72 | + acym_info(['textShownInTooltip' => 'ACYM_INCLUDE_IN_TEMPLATE_DESC']); | |
| 63 | 73 | } |
| 64 | 74 | |
| 65 | 75 | public function onAcymMailboxActionSummaryListing(&$action, &$result) |
| 66 | 76 | { |
| @@ -106,14 +116,14 @@ | ||
| 106 | 116 | $mailInfo = $newMail->subject.' ('.$newMail->id.')'; |
| 107 | 117 | foreach ($receivers as $oneReceiver) { |
| 108 | 118 | if ($mailerHelper->sendOne($newMail->id, $oneReceiver)) { |
| 109 | 119 | $report[] = [ |
| 110 | - 'message' => acym_translationSprintf('ACYM_SEND_SUCCESS', $mailInfo, acym_escape($oneReceiver)), | |
| 120 | + 'message' => acym_translationSprintf('ACYM_SEND_SUCCESS', $mailInfo, esc_attr($oneReceiver)), | |
| 111 | 121 | 'success' => true, |
| 112 | 122 | ]; |
| 113 | 123 | } else { |
| 114 | 124 | $report[] = [ |
| 115 | - 'message' => acym_translationSprintf('ACYM_SEND_ERROR', $mailInfo, acym_escape($oneReceiver)), | |
| 125 | + 'message' => acym_translationSprintf('ACYM_SEND_ERROR', $mailInfo, esc_attr($oneReceiver)), | |
| 116 | 126 | 'success' => false, |
| 117 | 127 | ]; |
| 118 | 128 | } |
| 119 | 129 | } |
| @@ -118,9 +128,9 @@ | ||
| 118 | 128 | } |
| 119 | 129 | } |
| 120 | 130 | |
| 121 | 131 | $mailClass = new MailClass(); |
| 122 | - $mailClass->delete($newMail->id); | |
| 132 | + $mailClass->delete([$newMail->id]); | |
| 123 | 133 | } |
| 124 | 134 | |
| 125 | 135 | public function onAcymMailboxAction_forward_list(&$action, &$report, &$executedActions, $mailboxHelper) |
| 126 | 136 | { |
| @@ -146,11 +156,12 @@ | ||
| 146 | 156 | $newMail->body = str_replace('{mailheader:cc}', htmlspecialchars($mailboxHelper->_message->ccaddress, ENT_QUOTES, 'UTF-8'), $newMail->body); |
| 147 | 157 | } |
| 148 | 158 | |
| 149 | 159 | if (!empty($mailboxHelper->_message->Date)) { |
| 150 | - $newMail->body = str_replace('{mailheader:date}', date('d.m.Y H:i', strtotime($mailboxHelper->_message->Date)), $newMail->body); | |
| 160 | + $newMail->body = str_replace('{mailheader:date}', acym_date(strtotime($mailboxHelper->_message->Date), 'd.m.Y H:i'), $newMail->body); | |
| 151 | 161 | } |
| 152 | 162 | |
| 163 | + // Clean tags if we couldn't replace them | |
| 153 | 164 | $newMail->body = str_replace( |
| 154 | 165 | [ |
| 155 | 166 | '{mailheader:from}', |
| 156 | 167 | '{mailheader:to}', |
| @@ -221,12 +232,14 @@ | ||
| 221 | 232 | |
| 222 | 233 | return false; |
| 223 | 234 | } |
| 224 | 235 | |
| 236 | + // We're going to forward the email, save its attachments and embed images | |
| 225 | 237 | $mailboxHelper->decodeMessage(true); |
| 226 | 238 | |
| 227 | 239 | $subject = $mailboxHelper->_message->subject; |
| 228 | 240 | |
| 241 | + //If the option remove subject is set | |
| 229 | 242 | if (!empty($mailboxHelper->action->conditions['subject_remove'])) { |
| 230 | 243 | if (!empty($mailboxHelper->action->conditions['subject_text'])) { |
| 231 | 244 | $subject = str_replace($mailboxHelper->action->conditions['subject_text'], '', $mailboxHelper->_message->subject); |
| 232 | 245 | } elseif (!empty($mailboxHelper->action->conditions['subject_regex'])) { |
| @@ -262,14 +275,14 @@ | ||
| 262 | 275 | $newMail->creation_date = acym_date('now', 'Y-m-d H:i:s', false); |
| 263 | 276 | |
| 264 | 277 | if (!empty($mailboxHelper->action->senderfrom)) { |
| 265 | 278 | $newMail->from_email = $mailboxHelper->decodeHeader($mailboxHelper->_message->header->from_email); |
| 266 | - $newMail->from_name = strip_tags($mailboxHelper->decodeHeader($mailboxHelper->_message->header->from_name)); | |
| 279 | + $newMail->from_name = acym_stripTags($mailboxHelper->decodeHeader($mailboxHelper->_message->header->from_name)); | |
| 267 | 280 | } |
| 268 | 281 | |
| 269 | 282 | if (!empty($mailboxHelper->action->senderto)) { |
| 270 | 283 | $newMail->reply_to_email = $mailboxHelper->decodeHeader($mailboxHelper->_message->header->from_email); |
| 271 | - $newMail->reply_to_name = strip_tags($mailboxHelper->decodeHeader($mailboxHelper->_message->header->from_name)); | |
| 284 | + $newMail->reply_to_name = acym_stripTags($mailboxHelper->decodeHeader($mailboxHelper->_message->header->from_name)); | |
| 272 | 285 | } |
| 273 | 286 | |
| 274 | 287 | if (!empty($mailboxHelper->attachments)) { |
| 275 | 288 | $newMail->attachments = $mailboxHelper->getAttachments(); |