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