fix: reduce vars in favor for db

This commit is contained in:
paulwer 2024-05-19 06:55:15 +02:00
parent 9c9c4a998c
commit ef60992843
4 changed files with 23 additions and 36 deletions

View File

@ -117,10 +117,8 @@ use Laracasts\Presenter\PresentableTrait;
* @property bool $inbound_mailbox_allow_vendors * @property bool $inbound_mailbox_allow_vendors
* @property bool $inbound_mailbox_allow_clients * @property bool $inbound_mailbox_allow_clients
* @property bool $inbound_mailbox_allow_unknown * @property bool $inbound_mailbox_allow_unknown
* @property string|null $inbound_mailbox_whitelist_domains * @property string|null $inbound_mailbox_whitelist
* @property string|null $inbound_mailbox_whitelist_senders * @property string|null $inbound_mailbox_blacklist
* @property string|null $inbound_mailbox_blacklist_domains
* @property string|null $inbound_mailbox_blacklist_senders
* @property int $deleted_at * @property int $deleted_at
* @property string $smtp_username * @property string $smtp_username
* @property string $smtp_password * @property string $smtp_password
@ -375,10 +373,8 @@ class Company extends BaseModel
'inbound_mailbox_allow_vendors', 'inbound_mailbox_allow_vendors',
'inbound_mailbox_allow_clients', 'inbound_mailbox_allow_clients',
'inbound_mailbox_allow_unknown', 'inbound_mailbox_allow_unknown',
'inbound_mailbox_whitelist_domains', 'inbound_mailbox_whitelist',
'inbound_mailbox_whitelist_senders', 'inbound_mailbox_blacklist',
'inbound_mailbox_blacklist_domains',
'inbound_mailbox_blacklist_senders',
'smtp_host', 'smtp_host',
'smtp_port', 'smtp_port',
'smtp_encryption', 'smtp_encryption',

View File

@ -34,10 +34,8 @@ class InboundMailEngine
use GeneratesCounter, SavesDocuments; use GeneratesCounter, SavesDocuments;
private ?bool $isUnknownRecipent = null; private ?bool $isUnknownRecipent = null;
private array $globalBlacklistDomains = []; private array $globalBlacklist = [];
private array $globalBlacklistSenders = []; 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
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
public function __construct() public function __construct()
{ {
} }
@ -78,17 +76,17 @@ class InboundMailEngine
$domain = array_pop($parts); $domain = array_pop($parts);
// global blacklist // global blacklist
if (in_array($from, $this->globalWhitelistDomains)) { if (in_array($from, $this->globalWhitelist)) {
return false; 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); nlog('E-Mail blocked, because the domain was found on globalBlocklistDomains: ' . $from);
return true; return true;
} }
if (in_array($domain, $this->globalWhitelistSenders)) { if (in_array($from, $this->globalBlacklist)) {
return false;
}
if (in_array($from, $this->globalBlacklistSenders)) {
nlog('E-Mail blocked, because the email was found on globalBlocklistEmails: ' . $from); nlog('E-Mail blocked, because the email was found on globalBlocklistEmails: ' . $from);
return true; return true;
} }
@ -210,17 +208,15 @@ class InboundMailEngine
$domain = array_pop($parts); $domain = array_pop($parts);
// whitelists // whitelists
$email_whitelist = explode(",", $company->inbound_mailbox_whitelist_senders); $whitelist = explode(",", $company->inbound_mailbox_whitelist);
if (in_array($email->from, $email_whitelist)) if (in_array($email->from, $whitelist))
return true; return true;
$domain_whitelist = explode(",", $company->inbound_mailbox_whitelist_domains); if (in_array($domain, $whitelist))
if (in_array($domain, $domain_whitelist))
return true; return true;
$email_blacklist = explode(",", $company->inbound_mailbox_blacklist_senders); $blacklist = explode(",", $company->inbound_mailbox_blacklist);
if (in_array($email->from, $email_blacklist)) if (in_array($email->from, $blacklist))
return false; return false;
$domain_blacklist = explode(",", $company->inbound_mailbox_blacklist_domains); if (in_array($domain, $blacklist))
if (in_array($domain, $domain_blacklist))
return false; return false;
// allow unknown // allow unknown

View File

@ -210,10 +210,8 @@ class CompanyTransformer extends EntityTransformer
'inbound_mailbox_allow_vendors' => (bool) $company->inbound_mailbox_allow_vendors, 'inbound_mailbox_allow_vendors' => (bool) $company->inbound_mailbox_allow_vendors,
'inbound_mailbox_allow_clients' => (bool) $company->inbound_mailbox_allow_clients, 'inbound_mailbox_allow_clients' => (bool) $company->inbound_mailbox_allow_clients,
'inbound_mailbox_allow_unknown' => (bool) $company->inbound_mailbox_allow_unknown, 'inbound_mailbox_allow_unknown' => (bool) $company->inbound_mailbox_allow_unknown,
'inbound_mailbox_blacklist_domains' => $company->inbound_mailbox_blacklist_domains, 'inbound_mailbox_blacklist' => $company->inbound_mailbox_blacklist,
'inbound_mailbox_blacklist_senders' => $company->inbound_mailbox_blacklist_senders, 'inbound_mailbox_whitelist' => $company->inbound_mailbox_whitelist,
'inbound_mailbox_whitelist_domains' => $company->inbound_mailbox_whitelist_domains,
'inbound_mailbox_whitelist_senders' => $company->inbound_mailbox_whitelist_senders,
'smtp_host' => (string) $company->smtp_host ?? '', 'smtp_host' => (string) $company->smtp_host ?? '',
'smtp_port' => (int) $company->smtp_port ?? 25, 'smtp_port' => (int) $company->smtp_port ?? 25,
'smtp_encryption' => (string) $company->smtp_encryption ?? 'tls', 'smtp_encryption' => (string) $company->smtp_encryption ?? 'tls',

View File

@ -1,6 +1,5 @@
<?php <?php
use App\Models\Company;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@ -18,10 +17,8 @@ return new class extends Migration {
$table->boolean("inbound_mailbox_allow_vendors")->default(false); $table->boolean("inbound_mailbox_allow_vendors")->default(false);
$table->boolean("inbound_mailbox_allow_clients")->default(false); $table->boolean("inbound_mailbox_allow_clients")->default(false);
$table->boolean("inbound_mailbox_allow_unknown")->default(false); $table->boolean("inbound_mailbox_allow_unknown")->default(false);
$table->text("inbound_mailbox_whitelist_domains")->nullable(); $table->text("inbound_mailbox_whitelist")->nullable();
$table->text("inbound_mailbox_whitelist_senders")->nullable(); $table->text("inbound_mailbox_blacklist")->nullable();
$table->text("inbound_mailbox_blacklist_domains")->nullable();
$table->text("inbound_mailbox_blacklist_senders")->nullable();
}); });
} }