From ef609928439e75e5b04f8979cde45a72fad0361b Mon Sep 17 00:00:00 2001 From: paulwer Date: Sun, 19 May 2024 06:55:15 +0200 Subject: [PATCH] fix: reduce vars in favor for db --- app/Models/Company.php | 12 +++---- .../InboundMail/InboundMailEngine.php | 34 ++++++++----------- app/Transformers/CompanyTransformer.php | 6 ++-- ...2023_12_10_110951_inbound_mail_parsing.php | 7 ++-- 4 files changed, 23 insertions(+), 36 deletions(-) diff --git a/app/Models/Company.php b/app/Models/Company.php index 2ee97801137b..718dc7b47fce 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -117,10 +117,8 @@ use Laracasts\Presenter\PresentableTrait; * @property bool $inbound_mailbox_allow_vendors * @property bool $inbound_mailbox_allow_clients * @property bool $inbound_mailbox_allow_unknown - * @property string|null $inbound_mailbox_whitelist_domains - * @property string|null $inbound_mailbox_whitelist_senders - * @property string|null $inbound_mailbox_blacklist_domains - * @property string|null $inbound_mailbox_blacklist_senders + * @property string|null $inbound_mailbox_whitelist + * @property string|null $inbound_mailbox_blacklist * @property int $deleted_at * @property string $smtp_username * @property string $smtp_password @@ -375,10 +373,8 @@ class Company extends BaseModel 'inbound_mailbox_allow_vendors', 'inbound_mailbox_allow_clients', 'inbound_mailbox_allow_unknown', - 'inbound_mailbox_whitelist_domains', - 'inbound_mailbox_whitelist_senders', - 'inbound_mailbox_blacklist_domains', - 'inbound_mailbox_blacklist_senders', + 'inbound_mailbox_whitelist', + 'inbound_mailbox_blacklist', 'smtp_host', 'smtp_port', 'smtp_encryption', diff --git a/app/Services/InboundMail/InboundMailEngine.php b/app/Services/InboundMail/InboundMailEngine.php index f207d47f216e..c1d2c6820923 100644 --- a/app/Services/InboundMail/InboundMailEngine.php +++ b/app/Services/InboundMail/InboundMailEngine.php @@ -16,7 +16,7 @@ use App\Factory\ExpenseFactory; use App\Jobs\Util\SystemLogger; use App\Libraries\MultiDB; use App\Models\ClientContact; -use App\Models\Company; +use App\Models\Company; use App\Models\SystemLog; use App\Models\VendorContact; use App\Services\InboundMail\InboundMail; @@ -34,10 +34,8 @@ class InboundMailEngine use GeneratesCounter, SavesDocuments; private ?bool $isUnknownRecipent = null; - private array $globalBlacklistDomains = []; - private array $globalBlacklistSenders = []; - private array $globalWhitelistDomains = []; // only for global validation, not for allowing to send something into the company, should be used to disabled blocking for mass-senders - private array $globalWhitelistSenders = []; // only for global validation, not for allowing to send something into the company, should be used to disabled blocking for mass-senders + private array $globalBlacklist = []; + private array $globalWhitelist = []; // only for global validation, not for allowing to send something into the company, should be used to disabled blocking for mass-senders public function __construct() { } @@ -78,17 +76,17 @@ class InboundMailEngine $domain = array_pop($parts); // global blacklist - if (in_array($from, $this->globalWhitelistDomains)) { + if (in_array($from, $this->globalWhitelist)) { return false; } - if (in_array($domain, $this->globalBlacklistDomains)) { + if (in_array($domain, $this->globalWhitelist)) { + return false; + } + if (in_array($domain, $this->globalBlacklist)) { nlog('E-Mail blocked, because the domain was found on globalBlocklistDomains: ' . $from); return true; } - if (in_array($domain, $this->globalWhitelistSenders)) { - return false; - } - if (in_array($from, $this->globalBlacklistSenders)) { + if (in_array($from, $this->globalBlacklist)) { nlog('E-Mail blocked, because the email was found on globalBlocklistEmails: ' . $from); return true; } @@ -210,17 +208,15 @@ class InboundMailEngine $domain = array_pop($parts); // whitelists - $email_whitelist = explode(",", $company->inbound_mailbox_whitelist_senders); - if (in_array($email->from, $email_whitelist)) + $whitelist = explode(",", $company->inbound_mailbox_whitelist); + if (in_array($email->from, $whitelist)) return true; - $domain_whitelist = explode(",", $company->inbound_mailbox_whitelist_domains); - if (in_array($domain, $domain_whitelist)) + if (in_array($domain, $whitelist)) return true; - $email_blacklist = explode(",", $company->inbound_mailbox_blacklist_senders); - if (in_array($email->from, $email_blacklist)) + $blacklist = explode(",", $company->inbound_mailbox_blacklist); + if (in_array($email->from, $blacklist)) return false; - $domain_blacklist = explode(",", $company->inbound_mailbox_blacklist_domains); - if (in_array($domain, $domain_blacklist)) + if (in_array($domain, $blacklist)) return false; // allow unknown diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index 603e2562a27d..475e17fd8714 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -210,10 +210,8 @@ class CompanyTransformer extends EntityTransformer 'inbound_mailbox_allow_vendors' => (bool) $company->inbound_mailbox_allow_vendors, 'inbound_mailbox_allow_clients' => (bool) $company->inbound_mailbox_allow_clients, 'inbound_mailbox_allow_unknown' => (bool) $company->inbound_mailbox_allow_unknown, - 'inbound_mailbox_blacklist_domains' => $company->inbound_mailbox_blacklist_domains, - 'inbound_mailbox_blacklist_senders' => $company->inbound_mailbox_blacklist_senders, - 'inbound_mailbox_whitelist_domains' => $company->inbound_mailbox_whitelist_domains, - 'inbound_mailbox_whitelist_senders' => $company->inbound_mailbox_whitelist_senders, + 'inbound_mailbox_blacklist' => $company->inbound_mailbox_blacklist, + 'inbound_mailbox_whitelist' => $company->inbound_mailbox_whitelist, 'smtp_host' => (string) $company->smtp_host ?? '', 'smtp_port' => (int) $company->smtp_port ?? 25, 'smtp_encryption' => (string) $company->smtp_encryption ?? 'tls', diff --git a/database/migrations/2023_12_10_110951_inbound_mail_parsing.php b/database/migrations/2023_12_10_110951_inbound_mail_parsing.php index 94d647510f34..056096254f4a 100644 --- a/database/migrations/2023_12_10_110951_inbound_mail_parsing.php +++ b/database/migrations/2023_12_10_110951_inbound_mail_parsing.php @@ -1,6 +1,5 @@ boolean("inbound_mailbox_allow_vendors")->default(false); $table->boolean("inbound_mailbox_allow_clients")->default(false); $table->boolean("inbound_mailbox_allow_unknown")->default(false); - $table->text("inbound_mailbox_whitelist_domains")->nullable(); - $table->text("inbound_mailbox_whitelist_senders")->nullable(); - $table->text("inbound_mailbox_blacklist_domains")->nullable(); - $table->text("inbound_mailbox_blacklist_senders")->nullable(); + $table->text("inbound_mailbox_whitelist")->nullable(); + $table->text("inbound_mailbox_blacklist")->nullable(); }); }