Changeset View
Changeset View
Standalone View
Standalone View
src/app/Policy/Greylist/Request.php
Show First 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | public function shouldDefer() | ||||
// TODO: determine if the sender (individual) is a whitelist | // TODO: determine if the sender (individual) is a whitelist | ||||
// TODO: determine if the sender is a penpal of any of the recipients. First recipient wins. | // TODO: determine if the sender is a penpal of any of the recipients. First recipient wins. | ||||
if (!$enabled) { | if (!$enabled) { | ||||
return false; | return false; | ||||
} | } | ||||
// determine if the sender, net and recipient combination has existed before, for each recipient | $defer = true; | ||||
// any one recipient matching should supersede the other recipients not having matched | |||||
$connect = Connect::where( | |||||
[ | |||||
'sender_local' => $this->senderLocal, | |||||
'sender_domain' => $this->senderDomain, | |||||
'recipient_hash' => $this->recipientHash, | |||||
'net_id' => $this->netID, | |||||
'net_type' => $this->netType, | |||||
] | |||||
) | |||||
->whereDate('updated_at', '>=', $this->timestamp->copy()->subMonthsWithoutOverflow(1)) | |||||
->orderBy('updated_at') | |||||
->first(); | |||||
$deferIfPermit = true; | // Retrieve the entry for the sender/recipient/net combination | ||||
if ($connect = $this->findConnectsCollection()->first()) { | |||||
machniak: We could skip the query if we know there's no entries, i.e. see line 87. | |||||
if ($connect) { | |||||
$connect->connect_count += 1; | $connect->connect_count += 1; | ||||
// TODO: The period of time for which the greylisting persists is configurable. | // TODO: The period of time for which the greylisting persists is configurable. | ||||
if ($connect->created_at < $this->timestamp->copy()->subMinutes(5)) { | if ($connect->created_at < $this->timestamp->copy()->subMinutes(5)) { | ||||
$deferIfPermit = false; | $defer = false; | ||||
$connect->greylisting = false; | $connect->greylisting = false; | ||||
} | } | ||||
$connect->save(); | $connect->save(); | ||||
} else { | } else { | ||||
Connect::create( | Connect::create( | ||||
[ | [ | ||||
'sender_local' => $this->senderLocal, | 'sender_local' => $this->senderLocal, | ||||
'sender_domain' => $this->senderDomain, | 'sender_domain' => $this->senderDomain, | ||||
'net_id' => $this->netID, | 'net_id' => $this->netID, | ||||
'net_type' => $this->netType, | 'net_type' => $this->netType, | ||||
'recipient_hash' => $this->recipientHash, | 'recipient_hash' => $this->recipientHash, | ||||
'recipient_id' => $this->recipientID, | 'recipient_id' => $this->recipientID, | ||||
'recipient_type' => $this->recipientType, | 'recipient_type' => $this->recipientType, | ||||
'created_at' => $this->timestamp, | 'created_at' => $this->timestamp, | ||||
'updated_at' => $this->timestamp | 'updated_at' => $this->timestamp | ||||
] | ] | ||||
); | ); | ||||
} | } | ||||
return $deferIfPermit; | return $defer; | ||||
} | } | ||||
private function findConnectsCollection() | private function findConnectsCollection() | ||||
{ | { | ||||
$collection = Connect::where( | $collection = Connect::where( | ||||
[ | [ | ||||
'sender_local' => $this->senderLocal, | 'sender_local' => $this->senderLocal, | ||||
'sender_domain' => $this->senderDomain, | 'sender_domain' => $this->senderDomain, | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |
We could skip the query if we know there's no entries, i.e. see line 87.