diff --git a/Plugin/Magento/Framework/Mail/TransportInterface.php b/Plugin/Magento/Framework/Mail/TransportInterface.php
index c23e840..ca35e18 100644
--- a/Plugin/Magento/Framework/Mail/TransportInterface.php
+++ b/Plugin/Magento/Framework/Mail/TransportInterface.php
@@ -36,7 +36,6 @@ public function __construct(
* @param \Magento\Framework\Mail\TransportInterface $subject
* @param Closure $proceed
* @return Closure|void $proceed
- * @throws ReflectionException
*/
public function aroundSendMessage(
\Magento\Framework\Mail\TransportInterface $subject,
@@ -46,8 +45,8 @@ public function aroundSendMessage(
return $proceed();
}
- if ($this->emailcatcher->blackListEnabled() && in_array($this->getToEmailAddress($subject), $this->getBlacklistEmailAddresses())) {
- $subject->getMessage()->setSubject('Prevent Being Sent - Blacklisted Email Address');
+ if ($this->emailcatcher->blackListEnabled() && $this->emailInBlacklist($this->getToEmailAddress($subject))) {
+ $subject->getMessage()?->setSubject('Prevent Being Sent - Blacklisted Email Address');
$this->saveMessage($subject);
return;
@@ -88,7 +87,7 @@ private function getTemplateWhitelist(): array
/**
* @return array
*/
- protected function getBlacklistEmailAddresses() : array
+ private function getBlacklistEmailAddresses() : array
{
return explode(',', $this->scopeConfig->getValue('emailcatcher/blacklist/block_email_addresses'));
}
@@ -97,8 +96,33 @@ protected function getBlacklistEmailAddresses() : array
* @param $subject
* @return string
*/
- protected function getToEmailAddress($subject): string
+ private function getToEmailAddress($subject): string
{
return $subject->getMessage()->getTo()[0]->getEmail() ?? '';
}
+
+ /**
+ * @param string $emailAddress
+ * @return bool
+ */
+ private function domainInBlacklist(string $emailAddress): bool
+ {
+ $blacklistedDomains = explode(',', $this->scopeConfig->getValue('emailcatcher/blacklist/block_email_domains'));
+ $emailDomain = substr(strrchr($emailAddress, "@"), 1);
+
+ return in_array($emailDomain, $blacklistedDomains);
+ }
+
+ /**
+ * @param string $emailAddress
+ * @return bool
+ */
+ public function emailInBlacklist(string $emailAddress): bool
+ {
+ if ($this->domainInBlacklist($emailAddress)) {
+ return true;
+ }
+
+ return in_array($emailAddress, $this->getBlacklistEmailAddresses());
+ }
}
diff --git a/Plugin/Magento/Framework/Mail/TransportInterfacePlugin.php b/Plugin/Magento/Framework/Mail/TransportInterfacePlugin.php
index 6c19305..accd37d 100644
--- a/Plugin/Magento/Framework/Mail/TransportInterfacePlugin.php
+++ b/Plugin/Magento/Framework/Mail/TransportInterfacePlugin.php
@@ -33,18 +33,17 @@ public function aroundSendMessage(
{
if (!$this->scopeConfig->isSetFlag('system/smtp/disable', ScopeInterface::SCOPE_STORE)) {
$proceed();
- return;
}
if ($this->emailcatcher->developmentAdminAllowedEnabled()) {
$emailAddresses = [];
- foreach ($subject->getMessage()->getTo() ?? [] as $to) {
+ foreach ($subject->getMessage()?->getTo() ?? [] as $to) {
$emailAddresses[] = $to->getEmail();
}
- foreach ($subject->getMessage()->getCc() ?? [] as $cc) {
+ foreach ($subject->getMessage()?->getCc() ?? [] as $cc) {
$emailAddresses[] = $cc->getEmail();
}
- foreach ($subject->getMessage()->getBcc() ?? [] as $bcc) {
+ foreach ($subject->getMessage()?->getBcc() ?? [] as $bcc) {
$emailAddresses[] = $bcc->getEmail();
}
if ($this->containsOnlyAdminUsers($emailAddresses)) {
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index 6d5de28..afb6eff 100644
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -54,6 +54,12 @@
1
+
+
+
+ 1
+
+