mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 23:14:33 -04:00
minor adjustment according spam behavior
This commit is contained in:
parent
9a733f06c0
commit
c02a4fb08d
@ -12,6 +12,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Jobs\PostMark\ProcessPostmarkWebhook;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Services\InboundMail\InboundMail;
|
||||
use App\Services\InboundMail\InboundMailEngine;
|
||||
use App\Utils\TempFile;
|
||||
@ -287,10 +288,16 @@ class PostMarkController extends BaseController
|
||||
|
||||
if ($inboundEngine->isInvalidOrBlocked($input["From"], $input["To"])) {
|
||||
Log::info('Failed: Sender is blocked: ' . $input["From"] . " Recipient: " . $input["To"]);
|
||||
$inboundEngine->saveMeta($input["From"], $input["To"]);
|
||||
return response()->json(['message' => 'Blocked.'], 403);
|
||||
}
|
||||
|
||||
$company = MultiDB::findAndSetDbByExpenseMailbox($input["To"]);
|
||||
if (!$company) {
|
||||
Log::info('[PostmarkInboundWebhook] unknown Expense Mailbox occured while handling an inbound email from mailgun: ' . $input["To"]);
|
||||
$inboundEngine->saveMeta($input["From"], $input["To"], true); // important to save this, to protect from spam
|
||||
return;
|
||||
}
|
||||
|
||||
try { // important to save meta if something fails here to prevent spam
|
||||
|
||||
// prepare data for ingresEngine
|
||||
@ -316,7 +323,7 @@ class PostMarkController extends BaseController
|
||||
}
|
||||
|
||||
// perform
|
||||
$inboundEngine->handle($inboundMail);
|
||||
$inboundEngine->handleExpenseMailbox($inboundMail);
|
||||
|
||||
return response()->json(['message' => 'Success'], 200);
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ class ProcessBrevoInboundWebhook implements ShouldQueue
|
||||
|
||||
public $tries = 1;
|
||||
|
||||
private InboundMailEngine $engine = new InboundMailEngine();
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -123,7 +125,7 @@ class ProcessBrevoInboundWebhook implements ShouldQueue
|
||||
foreach ($this->input["Recipients"] as $recipient) {
|
||||
|
||||
// Spam protection
|
||||
if ((new InboundMailEngine())->isInvalidOrBlocked($this->input["From"]["Address"], $recipient)) {
|
||||
if ($this->engine->isInvalidOrBlocked($this->input["From"]["Address"], $recipient)) {
|
||||
Log::info('Failed: Sender is blocked: ' . $this->input["From"]["Address"] . " Recipient: " . $recipient);
|
||||
throw new \Error('Sender is blocked');
|
||||
}
|
||||
@ -132,7 +134,7 @@ class ProcessBrevoInboundWebhook implements ShouldQueue
|
||||
$company = MultiDB::findAndSetDbByExpenseMailbox($recipient);
|
||||
if (!$company) {
|
||||
Log::info('[ProcessBrevoInboundWebhook] unknown Expense Mailbox occured while handling an inbound email from brevo: ' . $recipient);
|
||||
(new InboundMailEngine())->saveMeta($this->input["From"]["Address"], $recipient); // important to save this, to protect from spam
|
||||
// $this->engine->saveMeta($this->input["From"]["Address"], $recipient, true); // @turbo124 disabled, because recipents contains all recipients, and will likly result in false bans?! => normally important to save this, to protect from spam
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -186,11 +188,11 @@ class ProcessBrevoInboundWebhook implements ShouldQueue
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
(new InboundMailEngine())->saveMeta($this->input["From"]["Address"], $recipient); // important to save this, to protect from spam
|
||||
$this->engine->saveMeta($this->input["From"]["Address"], $recipient); // important to save this, to protect from spam
|
||||
throw $e;
|
||||
}
|
||||
|
||||
(new InboundMailEngine())->handle($inboundMail);
|
||||
$this->engine->handleExpenseMailbox($inboundMail);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ class ProcessMailgunInboundWebhook implements ShouldQueue
|
||||
|
||||
public $tries = 1;
|
||||
|
||||
private InboundMailEngine $engine = new InboundMailEngine();
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
* $input consists of 3 informations: sender/from|recipient/to|messageUrl
|
||||
@ -170,7 +172,7 @@ class ProcessMailgunInboundWebhook implements ShouldQueue
|
||||
// $messageId = explode("|", $this->input)[2]; // used as base in download function
|
||||
|
||||
// Spam protection
|
||||
if ((new InboundMailEngine())->isInvalidOrBlocked($from, $to)) {
|
||||
if ($this->engine->isInvalidOrBlocked($from, $to)) {
|
||||
Log::info('Failed: Sender is blocked: ' . $from . " Recipient: " . $to);
|
||||
throw new \Error('Sender is blocked');
|
||||
}
|
||||
@ -179,7 +181,7 @@ class ProcessMailgunInboundWebhook implements ShouldQueue
|
||||
$company = MultiDB::findAndSetDbByExpenseMailbox($to);
|
||||
if (!$company) {
|
||||
Log::info('[ProcessMailgunInboundWebhook] unknown Expense Mailbox occured while handling an inbound email from mailgun: ' . $to);
|
||||
(new InboundMailEngine())->saveMeta($from, $to); // important to save this, to protect from spam
|
||||
$this->engine->saveMeta($from, $to, true); // important to save this, to protect from spam
|
||||
return;
|
||||
}
|
||||
|
||||
@ -276,11 +278,11 @@ class ProcessMailgunInboundWebhook implements ShouldQueue
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
(new InboundMailEngine())->saveMeta($from, $to); // important to save this, to protect from spam
|
||||
$this->engine->saveMeta($from, $to); // important to save this, to protect from spam
|
||||
throw $e;
|
||||
}
|
||||
|
||||
// perform
|
||||
(new InboundMailEngine())->handle($inboundMail);
|
||||
$this->engine->handleExpenseMailbox($inboundMail);
|
||||
}
|
||||
}
|
||||
|
@ -46,21 +46,20 @@ class InboundMailEngine
|
||||
* if there is not a company with an matching mailbox, we only do monitoring
|
||||
* reuse this method to add more mail-parsing behaviors
|
||||
*/
|
||||
public function handle(InboundMail $email)
|
||||
public function handleExpenseMailbox(InboundMail $email)
|
||||
{
|
||||
if ($this->isInvalidOrBlocked($email->from, $email->to))
|
||||
return;
|
||||
|
||||
$isUnknownRecipent = true;
|
||||
|
||||
// Expense Mailbox => will create an expense
|
||||
$company = MultiDB::findAndSetDbByExpenseMailbox($email->to);
|
||||
if ($company) {
|
||||
$isUnknownRecipent = false;
|
||||
$this->createExpense($company, $email);
|
||||
if (!$company) {
|
||||
$this->saveMeta($email->from, $email->to, true);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->saveMeta($email->from, $email->to, $isUnknownRecipent);
|
||||
$this->createExpense($company, $email);
|
||||
$this->saveMeta($email->from, $email->to);
|
||||
}
|
||||
|
||||
// SPAM Protection
|
||||
|
Loading…
x
Reference in New Issue
Block a user