mailboxConfig = [ 'server' => $this->action->server, 'username' => $this->action->username, 'password' => $this->action->password, 'port' => $this->action->port, 'connect_method' => $this->action->connection_method, 'secure_method' => $this->action->secure_method, 'self_signed' => $this->action->self_signed, 'timeout' => 10, 'bounce_access_token' => empty($this->action->bounce_access_token) ? '' : $this->action->bounce_access_token, ]; return $this->isConfigurationValid(); } private function isConfigurationValid(): bool { $keyShouldNotBeEmpty = in_array($this->mailboxConfig['server'], self::HOSTS_NEEDING_OAUTH) ? 'bounce_access_token' : 'password'; $error = false; foreach ($this->mailboxConfig as $key => $oneConfig) { if (empty($oneConfig) && $key === $keyShouldNotBeEmpty) { $error = true; break; } } return !$error; } public function isConnectionValid(object $mailbox, bool $close = true): bool { $this->action = $mailbox; if (!$this->buildConfigFromMailbox()) { return false; } if (!$this->init($this->mailboxConfig) || !$this->connect()) { return false; } if ($close) { $this->close(); } return true; } private function senderConditionPass(): bool { $conditions = $this->action->conditions; $fromEmail = $this->_message->header->from_email; if ($conditions['sender'] === 'specific') { $allowedSenders = explode(',', $conditions['specific']); if (empty($allowedSenders) || !in_array($fromEmail, $allowedSenders)) { $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X', $fromEmail), self::MESSAGE_TYPE_INFO); return false; } } if ($conditions['sender'] === 'group') { $cmsUserId = acym_getCmsUserIdByEmail($fromEmail); if (empty($cmsUserId)) { $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X_CMS', $fromEmail, ACYM_CMS_TITLE), self::MESSAGE_TYPE_INFO); return false; } $groups = acym_getGroupsByUser($cmsUserId, false); if (!in_array($conditions['groups'], $groups)) { $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X_GROUP', $fromEmail, implode(', ', $conditions['groups'])), self::MESSAGE_TYPE_INFO); return false; } } if ($conditions['sender'] == 'lists' && !empty($conditions['lists'])) { $userClass = new UserClass(); $user = $userClass->getOneByEmail($fromEmail); if (empty($user)) { $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X_NOT_EXISTS', $fromEmail), self::MESSAGE_TYPE_INFO); return false; } $subscriptions = $userClass->getSubscriptionStatus($user->id, $conditions['lists'], 1); if (empty($subscriptions)) { $this->display(acym_translationSprintf('ACYM_SENDER_NOT_ALLOWED_X_LIST', $fromEmail), self::MESSAGE_TYPE_INFO); return false; } } return true; } private function subjectConditionPass(): bool { $conditions = $this->action->conditions; $subject = $this->_message->subject; $passSubject = true; if (empty($subject)) { $passSubject = false; } elseif ($conditions['subject'] == 'begins' && strpos($subject, $conditions['subject_text']) !== 0) { $passSubject = false; } elseif ($conditions['subject'] == 'ends' && strpos($subject, $conditions['subject_text']) !== strlen($subject) - strlen($conditions['subjectvalue'])) { $passSubject = false; } elseif ($conditions['subject'] == 'contains' && strpos($subject, $conditions['subject_text']) === false) { $passSubject = false; } elseif ($conditions['subject'] == 'regex' && !preg_match($conditions['subject_regex'], $subject)) { $passSubject = false; } if (!$passSubject) { $this->display(acym_translation('ACYM_SUBJECT_DOESNT_MATCH'), self::MESSAGE_TYPE_INFO); return false; } return true; } public function conditionsPass(): bool { if (!empty($this->action->conditions['sender']) && !$this->senderConditionPass()) { return false; } if (!empty($this->action->conditions['subject']) && !$this->subjectConditionPass()) { return false; } return true; } public function handleAction(): void { if (empty($this->action)) { return; } $maxMessages = min($this->nbMessages, 100); if ($this->report) { if (function_exists('apache_get_modules')) { $modules = apache_get_modules(); $this->mod_security2 = in_array('mod_security2', $modules); } @ini_set('output_buffering', 'off'); @ini_set('zlib.output_compression', 0); if (!headers_sent()) { while (ob_get_level() > 0 && $this->obend++ < 3) { @ob_end_flush(); } } $disp = "