| @@ -19,10 +19,9 @@ | ||
| 19 | 19 | 'connect_method' => $this->action->connection_method, |
| 20 | 20 | 'secure_method' => $this->action->secure_method, |
| 21 | 21 | 'self_signed' => $this->action->self_signed, |
| 22 | 22 | 'timeout' => 10, |
| 23 | - 'bounce_token' => empty($this->action->bounce_token) ? '' : $this->action->bounce_token, | |
| 24 | - 'imap_connection_method' => empty($this->action->imap_connection_method) ? 'classic' : $this->action->imap_connection_method, | |
| 23 | + 'bounce_access_token' => empty($this->action->bounce_access_token) ? '' : $this->action->bounce_access_token, | |
| 25 | 24 | ]; |
| 26 | 25 | |
| 27 | 26 | return $this->isConfigurationValid(); |
| 28 | 27 | } |
| @@ -28,9 +27,9 @@ | ||
| 28 | 27 | } |
| 29 | 28 | |
| 30 | 29 | private function isConfigurationValid(): bool |
| 31 | 30 | { |
| 32 | - $keyShouldNotBeEmpty = $this->mailboxConfig['imap_connection_method'] === 'classic' ? 'password' : 'bounce_token'; | |
| 31 | + $keyShouldNotBeEmpty = in_array($this->mailboxConfig['server'], self::HOSTS_NEEDING_OAUTH) ? 'bounce_access_token' : 'password'; | |
| 33 | 32 | |
| 34 | 33 | $error = false; |
| 35 | 34 | foreach ($this->mailboxConfig as $key => $oneConfig) { |
| 36 | 35 | if (empty($oneConfig) && $key === $keyShouldNotBeEmpty) { |
| @@ -64,21 +63,21 @@ | ||
| 64 | 63 | { |
| 65 | 64 | $conditions = $this->action->conditions; |
| 66 | 65 | $fromEmail = $this->_message->header->from_email; |
| 67 | 66 | |
| 68 | - if ($conditions['sender'] == 'specific') { | |
| 67 | + if ($conditions['sender'] === 'specific') { | |
| 69 | 68 | $allowedSenders = explode(',', $conditions['specific']); |
| 70 | 69 | if (empty($allowedSenders) || !in_array($fromEmail, $allowedSenders)) { |
| 71 | - $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X', $fromEmail)); | |
| 70 | + $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X', $fromEmail), self::MESSAGE_TYPE_INFO); | |
| 72 | 71 | |
| 73 | 72 | return false; |
| 74 | 73 | } |
| 75 | 74 | } |
| 76 | 75 | |
| 77 | - if ($conditions['sender'] == 'group') { | |
| 76 | + if ($conditions['sender'] === 'groups') { | |
| 78 | 77 | $cmsUserId = acym_getCmsUserIdByEmail($fromEmail); |
| 79 | 78 | if (empty($cmsUserId)) { |
| 80 | - $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X_CMS', $fromEmail, ACYM_CMS_TITLE)); | |
| 79 | + $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X_CMS', $fromEmail, ACYM_CMS_TITLE), self::MESSAGE_TYPE_INFO); | |
| 81 | 80 | |
| 82 | 81 | return false; |
| 83 | 82 | } |
| 84 | 83 | |
| @@ -83,10 +82,10 @@ | ||
| 83 | 82 | } |
| 84 | 83 | |
| 85 | 84 | $groups = acym_getGroupsByUser($cmsUserId, false); |
| 86 | 85 | |
| 87 | - if (!in_array($conditions['groups'], $groups)) { | |
| 88 | - $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X_GROUP', $fromEmail, implode(', ', $conditions['groups']))); | |
| 86 | + if (empty(array_intersect((array)$conditions['groups'], $groups))) { | |
| 87 | + $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X_GROUP', $fromEmail, implode(', ', $conditions['groups'])), self::MESSAGE_TYPE_INFO); | |
| 89 | 88 | |
| 90 | 89 | return false; |
| 91 | 90 | } |
| 92 | 91 | } |
| @@ -95,9 +94,9 @@ | ||
| 95 | 94 | $userClass = new UserClass(); |
| 96 | 95 | $user = $userClass->getOneByEmail($fromEmail); |
| 97 | 96 | |
| 98 | 97 | if (empty($user)) { |
| 99 | - $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X_NOT_EXISTS', $fromEmail)); | |
| 98 | + $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X_NOT_EXISTS', $fromEmail), self::MESSAGE_TYPE_INFO); | |
| 100 | 99 | |
| 101 | 100 | return false; |
| 102 | 101 | } |
| 103 | 102 | |
| @@ -103,9 +102,9 @@ | ||
| 103 | 102 | |
| 104 | 103 | $subscriptions = $userClass->getSubscriptionStatus($user->id, $conditions['lists'], 1); |
| 105 | 104 | |
| 106 | 105 | if (empty($subscriptions)) { |
| 107 | - $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X_LIST', $fromEmail)); | |
| 106 | + $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X_LIST', $fromEmail), self::MESSAGE_TYPE_INFO); | |
| 108 | 107 | |
| 109 | 108 | return false; |
| 110 | 109 | } |
| 111 | 110 | } |
| @@ -122,12 +121,9 @@ | ||
| 122 | 121 | if (empty($subject)) { |
| 123 | 122 | $passSubject = false; |
| 124 | 123 | } elseif ($conditions['subject'] == 'begins' && strpos($subject, $conditions['subject_text']) !== 0) { |
| 125 | 124 | $passSubject = false; |
| 126 | - } elseif ($conditions['subject'] == 'ends' && strpos( | |
| 127 | - $subject, | |
| 128 | - $conditions['subject_text'] | |
| 129 | - ) !== strlen($subject) - strlen($conditions['subjectvalue'])) { | |
| 125 | + } elseif ($conditions['subject'] == 'ends' && strpos($subject, $conditions['subject_text']) !== strlen($subject) - strlen($conditions['subject_text'])) { | |
| 130 | 126 | $passSubject = false; |
| 131 | 127 | } elseif ($conditions['subject'] == 'contains' && strpos($subject, $conditions['subject_text']) === false) { |
| 132 | 128 | $passSubject = false; |
| 133 | 129 | } elseif ($conditions['subject'] == 'regex' && !preg_match($conditions['subject_regex'], $subject)) { |
| @@ -134,9 +130,9 @@ | ||
| 134 | 130 | $passSubject = false; |
| 135 | 131 | } |
| 136 | 132 | |
| 137 | 133 | if (!$passSubject) { |
| 138 | - $this->display(acym_translation('ACYM_SUBJECT_DOESNT_MATCH')); | |
| 134 | + $this->display(acym_translation('ACYM_SUBJECT_DOESNT_MATCH'), self::MESSAGE_TYPE_INFO); | |
| 139 | 135 | |
| 140 | 136 | return false; |
| 141 | 137 | } |
| 142 | 138 | |
| @@ -169,9 +165,12 @@ | ||
| 169 | 165 | $modules = apache_get_modules(); |
| 170 | 166 | $this->mod_security2 = in_array('mod_security2', $modules); |
| 171 | 167 | } |
| 172 | 168 | |
| 169 | + /*This is to avoid the blank page... and it apparently works! ;) */ | |
| 170 | + // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged -- Disabled to prevent blank output pages. | |
| 173 | 171 | @ini_set('output_buffering', 'off'); |
| 172 | + // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged -- Disabled to prevent blank output pages. | |
| 174 | 173 | @ini_set('zlib.output_compression', 0); |
| 175 | 174 | |
| 176 | 175 | if (!headers_sent()) { |
| 177 | 176 | while (ob_get_level() > 0 && $this->obend++ < 3) { |
| @@ -177,21 +176,22 @@ | ||
| 177 | 176 | while (ob_get_level() > 0 && $this->obend++ < 3) { |
| 178 | 177 | @ob_end_flush(); |
| 179 | 178 | } |
| 180 | 179 | } |
| 181 | - | |
| 182 | - $disp = "<div style='position:fixed; top:3px;left:3px;background-color : white;border : 1px solid grey; padding : 3px;font-size:14px'>"; | |
| 183 | - $disp .= acym_translation('ACYM_MAILBOX_ACTIONS'); | |
| 184 | - $disp .= ': <span id="counter">0</span> / '.$maxMessages; | |
| 185 | - $disp .= '</div>'; | |
| 186 | - $disp .= '<script type="text/javascript" language="javascript">'; | |
| 187 | - $disp .= 'var mycounter = document.getElementById("counter");'; | |
| 188 | - $disp .= 'function setCounter(val){ mycounter.innerHTML=val;}'; | |
| 189 | - $disp .= '</script>'; | |
| 190 | - echo $disp; | |
| 180 | + ?> | |
| 181 | + <div style="position:fixed; top:3px; left:3px; background-color: white; border: 1px solid grey; padding: 3px; font-size:14px"> | |
| 182 | + <?php echo esc_html(acym_translation('ACYM_MAILBOX_ACTIONS')); ?> : <span id="counter">0</span> / <?php echo esc_attr($maxMessages); ?> | |
| 183 | + </div> | |
| 184 | + <script type="text/javascript" language="javascript"> | |
| 185 | + function setCounter(val) { | |
| 186 | + document.getElementById('counter').innerHTML = val; | |
| 187 | + } | |
| 188 | + </script> | |
| 189 | + <?php | |
| 191 | 190 | if (function_exists('ob_flush')) { |
| 192 | 191 | @ob_flush(); |
| 193 | 192 | } |
| 193 | + | |
| 194 | 194 | if (!$this->mod_security2) { |
| 195 | 195 | @flush(); |
| 196 | 196 | } |
| 197 | 197 | } |
| @@ -199,9 +199,9 @@ | ||
| 199 | 199 | $msgNB = $maxMessages; |
| 200 | 200 | |
| 201 | 201 | while (($msgNB > 0) && ($this->_message = $this->getMessage($msgNB))) { |
| 202 | 202 | if ($this->report) { |
| 203 | - echo '<script type="text/javascript" language="javascript">setCounter('.($maxMessages - $msgNB + 1).')</script>'; | |
| 203 | + echo '<script type="text/javascript" language="javascript">setCounter('.esc_html($maxMessages - $msgNB + 1).')</script>'; | |
| 204 | 204 | if (function_exists('ob_flush')) { |
| 205 | 205 | @ob_flush(); |
| 206 | 206 | } |
| 207 | 207 | if (!$this->mod_security2) { |
| @@ -214,10 +214,11 @@ | ||
| 214 | 214 | if (empty($this->_message->subject)) { |
| 215 | 215 | $this->_message->subject = ''; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | + //We could not retrieve the message... we continue with the next message | |
| 218 | 219 | if (!$this->decodeMessage()) { |
| 219 | - $this->display(acym_translation('ACYM_ERROR_RETRIEVING_MESSAGE'), false, $maxMessages - $this->_message->messageNB + 1); | |
| 220 | + $this->display(acym_translation('ACYM_ERROR_RETRIEVING_MESSAGE'), self::MESSAGE_TYPE_ERROR, $maxMessages - $this->_message->messageNB + 1); | |
| 220 | 221 | continue; |
| 221 | 222 | } |
| 222 | 223 | |
| 223 | 224 | if (empty($this->_message->html)) { |
| @@ -222,12 +223,12 @@ | ||
| 222 | 223 | |
| 223 | 224 | if (empty($this->_message->html)) { |
| 224 | 225 | $this->_message->html = nl2br($this->_message->text); |
| 225 | 226 | } |
| 226 | - $stripedHtml = strip_tags($this->_message->html); | |
| 227 | + $stripedHtml = acym_stripTags($this->_message->html); | |
| 227 | 228 | |
| 228 | 229 | if (strlen($stripedHtml) < 3) { |
| 229 | - $this->display(acym_translation('ACYM_EMPTY_EMAIL_X', acym_escape($this->_message->subject))); | |
| 230 | + $this->display(acym_translation('ACYM_EMPTY_EMAIL_X', esc_html($this->_message->subject)), self::MESSAGE_TYPE_ERROR); | |
| 230 | 231 | if ($this->action->delete_wrong_emails) { |
| 231 | 232 | $this->deleteMessage($this->_message->messageNB); |
| 232 | 233 | } |
| 233 | 234 | continue; |
| @@ -233,9 +234,9 @@ | ||
| 233 | 234 | continue; |
| 234 | 235 | } |
| 235 | 236 | |
| 236 | 237 | if (!$this->conditionsPass()) { |
| 237 | - $this->display(acym_translation('ACYM_INVALID_EMAIL', $this->_message->subject)); | |
| 238 | + $this->display(acym_translation('ACYM_INVALID_EMAIL', $this->_message->subject), self::MESSAGE_TYPE_ERROR); | |
| 238 | 239 | if ($this->action->delete_wrong_emails) { |
| 239 | 240 | $this->deleteMessage($this->_message->messageNB); |
| 240 | 241 | } |
| 241 | 242 | continue; |
| @@ -245,8 +246,9 @@ | ||
| 245 | 246 | $this->display(acym_translation('ACYM_MESSAGE_DELETED')); |
| 246 | 247 | $this->deleteMessage($this->_message->messageNB); |
| 247 | 248 | } |
| 248 | 249 | |
| 250 | + //We don't have time to finish the process? Ok, we stop it now! | |
| 249 | 251 | if (!empty($this->stoptime) && time() > $this->stoptime) { |
| 250 | 252 | break; |
| 251 | 253 | } |
| 252 | 254 | } |
| @@ -256,9 +258,8 @@ | ||
| 256 | 258 | { |
| 257 | 259 | $executedActions = []; |
| 258 | 260 | |
| 259 | 261 | foreach ($this->action->actions as $actionKey => $oneAction) { |
| 260 | - | |
| 261 | 262 | $this->display('<strong>'.acym_translationSprintf('ACYM_ACTION_X', intval($actionKey) + 1).'</strong>'); |
| 262 | 263 | |
| 263 | 264 | $actionId = array_keys($oneAction)[0]; |
| 264 | 265 | |
| @@ -270,9 +271,9 @@ | ||
| 270 | 271 | $reportMessages = []; |
| 271 | 272 | acym_trigger('onAcymMailboxAction_'.$actionId, [&$oneAction[$actionId], &$reportMessages, &$executedActions[$actionKey], $this]); |
| 272 | 273 | |
| 273 | 274 | foreach ($reportMessages as $reportMessage) { |
| 274 | - $this->display($reportMessage['message'], $reportMessage['success']); | |
| 275 | + $this->display($reportMessage['message'], $reportMessage['success'] ? self::MESSAGE_TYPE_SUCCESS : self::MESSAGE_TYPE_ERROR); | |
| 275 | 276 | } |
| 276 | 277 | |
| 277 | 278 | $this->attachments = []; |
| 278 | 279 | } |
| @@ -281,8 +282,9 @@ | ||
| 281 | 282 | foreach ($executedActions as $oneActionExecuted) { |
| 282 | 283 | $allActionsExecuted = $allActionsExecuted && $oneActionExecuted; |
| 283 | 284 | } |
| 284 | 285 | |
| 286 | + // If false one or more actions were not executed | |
| 285 | 287 | return $allActionsExecuted; |
| 286 | 288 | } |
| 287 | 289 | |
| 288 | 290 | public function getAttachments(): string |