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