hrow new \InvalidArgumentException($response['message']); } return $response; } public function isEmailAddressAuthorized(string $email): bool { $authorizedEmails = $this->bridge->getAuthorizedEmailAddresses() ?: []; return $this->validateAuthorizedEmail($authorizedEmails, $email); } public function checkAuthorizedEmailAddresses() { if (!Bridge::isMPSendingServiceEnabled()) { $this->settings->set(self::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING, null); $this->updateMailerLog(); return null; } $authorizedEmails = $this->bridge->getAuthorizedEmailAddresses(); // Keep previous check result for an invalid response from API if (!$authorizedEmails) { return null; } $authorizedEmails = array_map('strtolower', $authorizedEmails); $verifiedDomains = $this->senderDomainController->getVerifiedSenderDomainsIgnoringCache(); $result = []; $result = $this->validateAddressesInSettings($authorizedEmails, $verifiedDomains, $result); $result = $this->validateAddressesInScheduledAndAutomaticEmails($authorizedEmails, $verifiedDomains, $result); $this->settings->set(self::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING, $result ?: null); $this->updateMailerLog($result); return $result; } public function onSettingsSave($settings): ?array { $senderAddressSet = !empty($settings['sender']['address']); $mailpoetSendingMethodSet = ($settings[Mailer::MAILER_CONFIG_SETTING_NAME]['method'] ?? null) === Mailer::METHOD_MAILPOET; if ($senderAddressSet || $mailpoetSendingMethodSet) { return $this->checkAuthorizedEmailAddresses(); } return null; } public function onNewsletterSenderAddressUpdate(NewsletterEntity $newsletter, string $oldSenderAddress = null) { if ($newsletter->getSenderAddress() === $oldSenderAddress) { return; } if ($newsletter->getType() === NewsletterEntity::TYPE_STANDARD && $newsletter->getStatus() === NewsletterEntity::STATUS_SCHEDULED) { $this->checkAuthorizedEmailAddresses(); } if (in_array($newsletter->getType(), $this->automaticEmailTypes, true) && $newsletter->getStatus() === NewsletterEntity::STATUS_ACTIVE) { $this->checkAuthorizedEmailAddresses(); } } public function isSenderAddressValid(NewsletterEntity $newsletter, string $context = 'activation'): bool { if (!in_array($newsletter->getType(), NewsletterEntity::CAMPAIGN_TYPES)) { return true; } $isAuthorizedDomainRequired = $context === 'activation' ? $this->senderDomainController->isAuthorizedDomainRequiredForNewCampaigns() : $this->senderDomainController->isAuthorizedDomainRequiredForExistingCampaigns(); if (!$isAuthorizedDomainRequired) { return true; } $verifiedDomains = $context === 'activation' ? $this->senderDomainController->getVerifiedSenderDomainsIgnoringCache() : $this->senderDomainController->getVerifiedSenderDomains(); // The shop is not returning data, so we allow sending and let the Sending Service block the campaign if needed. if ($context === 'sending' && empty($verifiedDomains) && !$this->senderDomainController->isCacheAvailable()) { return true; } return $this->validateEmailDomainIsVerified($verifiedDomains, $newsletter->getSenderAddress()); } private function validateAddressesInSettings($authorizedEmails, $verifiedDomains, $result = []) { $defaultSenderAddress = $this->settings->get('sender.address'); if ($this->validateEmailDomainIsVerified($verifiedDomains, $defaultSenderAddress)) { // allow sending from any email address in a verified domain return $result; } if (!$this->validateAuthorizedEmail($authorizedEmails, $defaultSenderAddress)) { $result['invalid_sender_address'] = $defaultSenderAddress; } return $result; } private function validateAddressesInScheduledAndAutomaticEmails($authorizedEmails, $verifiedDomains, $result = []) { $newsletters = $this->newslettersRepository->getScheduledStandardEmailsAndActiveAutomaticEmails($this->automaticEmailTypes); $invalidSendersInNewsletters = []; foreach ($newsletters as $newsletter) { if ($this->validateAuthorizedEmail($authorizedEmails, $newsletter->getSenderAddress())) { continue; } if ($this->validateEmailDomainIsVerified($verifiedDomains, $newsletter->getSenderAddress())) { // allow sending from any email address in a verified domain continue; } $invalidSendersInNewsletters[] = [ 'newsletter_id' => $newsletter->getId(), 'subject' => $newsletter->getSubject(), 'sender_address' => $newsletter->getSenderAddress(), ]; } if (!count($invalidSendersInNewsletters)) { return $result; } $result['invalid_senders_in_newsletters'] = $invalidSendersInNewsletters; return $result; } /** * @param array|null $error */ private function updateMailerLog(array $error = null) { if ($error) { return; } $mailerLogError = MailerLog::getError(); if ($mailerLogError && $mailerLogError['operation'] === MailerError::OPERATION_AUTHORIZATION) { MailerLog::resumeSending(); } } private function validateAuthorizedEmail($authorizedEmails = [], $email = '') { $lowercaseAuthorizedEmails = array_map('strtolower', $authorizedEmails); return in_array(strtolower($email), $lowercaseAuthorizedEmails, true); } private function validateEmailDomainIsVerified(array $verifiedDomains = [], string $email = ''): bool { $lowercaseVerifiedDomains = array_map('strtolower', $verifiedDomains); $emailDomain = Helpers::extractEmailDomain($email); return in_array($emailDomain, $lowercaseVerifiedDomains, true); } }
Fatal error: Uncaught Error: Class "MailPoet\Services\AuthorizedEmailsController" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:4828 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(926): MailPoetGenerated\FreeCachedContainer->getAuthorizedEmailsControllerService() #1 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(5592): MailPoetGenerated\FreeCachedContainer->getSettingsService() #2 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2612): MailPoetGenerated\FreeCachedContainer->getDotcomLicenseProvisionerService() #3 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2640): MailPoetGenerated\FreeCachedContainer->getHooks2Service() #4 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(122): MailPoetGenerated\FreeCachedContainer->getInitializerService() #5 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(110): MailPoetVendor\Symfony\Component\DependencyInjection\Container->make('MailPoet\\Config...', 1) #6 /htdocs/wp-content/plugins/mailpoet/lib/DI/ContainerWrapper.php(39): MailPoetVendor\Symfony\Component\DependencyInjection\Container->get('MailPoet\\Config...') #7 /htdocs/wp-content/plugins/mailpoet/mailpoet_initializer.php(89): MailPoet\DI\ContainerWrapper->get('MailPoet\\Config...') #8 /htdocs/wp-content/plugins/mailpoet/mailpoet.php(194): require_once('/htdocs/wp-cont...') #9 /htdocs/wp-settings.php(526): include_once('/htdocs/wp-cont...') #10 /htdocs/wp-config.php(85): require_once('/htdocs/wp-sett...') #11 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #12 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #13 /htdocs/index.php(17): require('/htdocs/wp-blog...') #14 {main} thrown in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php on line 4828