use Cubist\Backpack\Magic\Fields\Table;
use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
use Cubist\Net\Util;
+use Cubist\Util\Cache;
use Cubist\Util\Files\Files;
use Cubist\Util\Str;
+use Cubist\Util\Text;
+use Cubist\Util\Url;
// __('!! Équipe')
class TeamEmails extends CubistMagicAbstractModel
}
- public function preSave()
+ public function onSaving(): bool
{
+ $this->refreshServerSettings();
+ return parent::onSaving();
+ }
+ public function refreshServerSettings()
+ {
$maindomain = 'cubedesigners.com';
$mailboxes = json_decode($this->mailboxes, true);
$a = json_decode($this->aliases, true);
$ip = json_decode($this->ip_whitelist, true);
$spam_whitelist = json_decode($this->spam_whitelist, true);
+ $spam_whitelist = self::getWhitelistFromClients($spam_whitelist);
+
$spam_blacklist = json_decode($this->spam_blacklist, true);
$auth_whitelist = json_decode($this->auth_whitelist, true);
}
$spam_wl = [];
foreach ($spam_whitelist as $item) {
- $spam_wl[] = 'whitelist_from ' . $item['email'];
+ $spam_wl[] = 'whitelist_from ' . $item;
}
$auth_wl = [];
$auth_wl[] = $item['domain'];
}
-
$accounts = [];
foreach ($mailboxes as $k => $m) {
if (!isset($m['password'])) {
$email = $m['mailbox'] . '@' . $maindomain;
$password = $m['password'] = trim($m['password']);
if ($m['password'] === '') {
- $user = User::where('email', $email)->first();
+ $user = User::withoutGlobalScopes()->where('email', $email)->first();
if (null === $user) {
$m['password'] = Str::random(12);
} else {
Files::mkdir(storage_path('emailconfig'));
file_put_contents(storage_path('emailconfig/postfix-accounts.cf'), implode("\n", $accountFile));
-
$aliases = [];
foreach ($a as $item) {
$from = trim($item['from']);
if (!isset($aliases[$from])) {
$aliases[$from] = [];
}
- $aliases[$from] = array_merge($aliases[$from], explode(',', str_replace('@' . $maindomain, '', $item['dest'])));
+ $dest = str_replace('@' . $maindomain, '', $item['dest']);
+ if (!is_array($dest)) {
+ $dest = explode(',', $dest);
+ }
+ $aliases[$from] = array_merge($aliases[$from], $dest);
}
ksort($aliases);
$savedAliases = [];
$content = str_replace("\r\n", "\n", $content);
file_put_contents(storage_path('emailconfig/' . $filename), $content);
}
+
+ protected static function getWhitelistFromClients($additional = [])
+ {
+ $res = [];
+ foreach ($additional as $item) {
+ $res[] = $item['email'];
+ }
+ $freeproviders = \Illuminate\Support\Facades\Cache::rememberForever('freeemailproviders', function () {
+ return Text::splitLines(file_get_contents('https://gist.githubusercontent.com/drakodev/e85c1fd6d9ac8634786d6139e0066fa0/raw/1f345fa275fafda8196af754674fcf04d05b7fba/free-disposable-email-providers.txt'));
+ });
+ foreach (User::withoutGlobalScopes()->where('created_ok', '1')->where('enabled', '1')->get() as $user) {
+ $email = trim(mb_strtolower($user->email));
+ $e = explode('@', $email);
+ if (count($e) < 2) {
+ continue;
+ }
+ $domain = $e[1];
+ if (in_array($domain, $freeproviders)) {
+ $res[] = $email;
+ } else {
+ $res[] = '*@' . $domain;
+ }
+ }
+
+ $res = array_unique($res);
+ sort($res);
+ return $res;
+ }
}