From 3d9f000fd1d7a6224dc5bc71f1c684ae55e0a3ab Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 12 Apr 2018 23:19:20 +0300 Subject: [PATCH] Make spam limit a factor of the company age --- app/Constants.php | 2 +- app/Models/Traits/SendsEmails.php | 9 +++++++++ app/Ninja/Mailers/ContactMailer.php | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Constants.php b/app/Constants.php index 48342777feda..c36f24965a59 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -158,7 +158,7 @@ if (! defined('APP_NAME')) { define('MAX_DOCUMENT_SIZE', env('MAX_DOCUMENT_SIZE', 10000)); // KB define('MAX_EMAIL_DOCUMENTS_SIZE', env('MAX_EMAIL_DOCUMENTS_SIZE', 10000)); // Total KB define('MAX_ZIP_DOCUMENTS_SIZE', env('MAX_EMAIL_DOCUMENTS_SIZE', 30000)); // Total KB (uncompressed) - define('MAX_EMAILS_SENT_PER_DAY', 500); + define('MAX_EMAILS_SENT_PER_DAY', 300); define('DOCUMENT_PREVIEW_SIZE', env('DOCUMENT_PREVIEW_SIZE', 300)); // pixels define('DEFAULT_FONT_SIZE', 9); define('DEFAULT_HEADER_FONT', 1); // Roboto diff --git a/app/Models/Traits/SendsEmails.php b/app/Models/Traits/SendsEmails.php index a3a07b58c918..60ac2a5644e6 100644 --- a/app/Models/Traits/SendsEmails.php +++ b/app/Models/Traits/SendsEmails.php @@ -204,4 +204,13 @@ trait SendsEmails return Domain::getEmailFromId($this->domain_id); } + + public function getDailyEmailLimit() + { + $limit = MAX_EMAILS_SENT_PER_DAY; + + $limit += $this->created_at->diffInMonths() * 100; + + return min($limit, 1000); + } } diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index 5fdab98dff01..9901f5e3e594 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -381,7 +381,7 @@ class ContactMailer extends Mailer // http://stackoverflow.com/questions/1375501/how-do-i-throttle-my-sites-api-users $day = 60 * 60 * 24; - $day_limit = MAX_EMAILS_SENT_PER_DAY; + $day_limit = $account->getDailyEmailLimit(); $day_throttle = Cache::get("email_day_throttle:{$key}", null); $last_api_request = Cache::get("last_email_request:{$key}", 0); $last_api_diff = time() - $last_api_request;