Prevent sending confirmation emails when address is unauthorized

[MAILPOET-1987]
This commit is contained in:
Rostislav Wolny
2019-05-13 09:27:08 +02:00
committed by M. Shull
parent d574ac09a6
commit ced9c549f6
2 changed files with 31 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ use Html2Text\Html2Text;
use MailPoet\Mailer\Mailer;
use MailPoet\Mailer\MailerError;
use MailPoet\Models\Subscriber;
use MailPoet\Services\Bridge;
use MailPoet\Settings\SettingsController;
use MailPoet\Subscription\Url;
use MailPoet\Util\Helpers;
@@ -52,6 +53,12 @@ class ConfirmationEmailMailer {
return false;
}
$authorization_emails_validation = $this->settings->get(Bridge::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING_NAME);
$unauthorized_confirmation_email = isset($authorization_emails_validation['invalid_confirmation_address']);
if (Bridge::isMPSendingServiceEnabled() && $unauthorized_confirmation_email) {
return false;
}
$segments = $subscriber->segments()->findMany();
$segment_names = array_map(function($segment) {
return $segment->name;

View File

@@ -8,6 +8,8 @@ use MailPoet\Mailer\Mailer;
use MailPoet\Models\Segment;
use MailPoet\Models\Subscriber;
use MailPoet\Models\SubscriberSegment;
use MailPoet\Services\Bridge;
use MailPoet\Settings\SettingsController;
use MailPoet\WP\Functions as WPFunctions;
class ConfirmationEmailMailerTest extends \MailPoetTest {
@@ -69,6 +71,28 @@ class ConfirmationEmailMailerTest extends \MailPoetTest {
expect($subscriber->getErrors()[0])->equals('send error');
}
function testItDoesntSendWhenMSSIsActiveAndConfirmationEmailIsNotAuthorized() {
$subscriber = Subscriber::create();
$subscriber->hydrate([
'first_name' => 'John',
'last_name' => 'Mailer',
'email' => 'john@mailpoet.com'
]);
$mailer = $this->makeEmpty(Mailer::class, [
'send' => Stub\Expected::never(),
]);
$settings = new SettingsController;
$settings->set(Bridge::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING_NAME, ['invalid_confirmation_address' => 'email@email.com']);
$settings->set(Mailer::MAILER_CONFIG_SETTING_NAME, ['method' => Mailer::METHOD_MAILPOET]);
$sender = new ConfirmationEmailMailer($mailer);
$result = $sender->sendConfirmationEmail($subscriber);
expect($result)->equals(false);
$settings->set(Bridge::AUTHORIZED_EMAIL_ADDRESSES_ERROR_SETTING_NAME, null);
}
function testItLimitsNumberOfConfirmationEmailsForNotLoggedInUser() {
wp_set_current_user(0);
expect((new WPFunctions)->isUserLoggedIn())->false();