Changeset View
Changeset View
Standalone View
Standalone View
src/app/Policy/Greylist/Request.php
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | public function shouldDefer() | ||||
if (strpos($this->sender, '@') !== false) { | if (strpos($this->sender, '@') !== false) { | ||||
list($this->senderLocal, $this->senderDomain) = explode('@', $this->sender); | list($this->senderLocal, $this->senderDomain) = explode('@', $this->sender); | ||||
} | } | ||||
if (strlen($this->senderLocal) > 255) { | if (strlen($this->senderLocal) > 255) { | ||||
$this->senderLocal = substr($this->senderLocal, 0, 255); | $this->senderLocal = substr($this->senderLocal, 0, 255); | ||||
} | } | ||||
$entry = $this->findConnectsCollectionRecent()->orderBy('updated_at')->first(); | // Purge all old information if we have no recent entries | ||||
if (!$this->findConnectsCollectionRecent()->exists()) { | |||||
if (!$entry) { | |||||
// purge all entries to avoid a unique constraint violation. | |||||
$this->findConnectsCollection()->delete(); | $this->findConnectsCollection()->delete(); | ||||
$entry = Connect::create( | |||||
[ | |||||
'sender_local' => $this->senderLocal, | |||||
'sender_domain' => $this->senderDomain, | |||||
'net_id' => $this->netID, | |||||
'net_type' => $this->netType, | |||||
'recipient_hash' => $this->recipientHash, | |||||
'recipient_id' => $this->recipientID, | |||||
'recipient_type' => $this->recipientType, | |||||
'connect_count' => 1, | |||||
'created_at' => $this->timestamp, | |||||
'updated_at' => $this->timestamp | |||||
] | |||||
); | |||||
} | } | ||||
// See if the recipient opted-out of the feature | // See if the recipient opted-out of the feature | ||||
$enabled = true; | $enabled = true; | ||||
if ($recipient) { | if ($recipient) { | ||||
$enabled = $recipient->getSetting('greylist_enabled') !== 'false'; | $enabled = $recipient->getSetting('greylist_enabled') !== 'false'; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public function shouldDefer() | ||||
$count = Connect::where( | $count = Connect::where( | ||||
[ | [ | ||||
'sender_domain' => $this->senderDomain, | 'sender_domain' => $this->senderDomain, | ||||
'net_id' => $this->netID, | 'net_id' => $this->netID, | ||||
'net_type' => $this->netType | 'net_type' => $this->netType | ||||
] | ] | ||||
) | ) | ||||
->whereDate('updated_at', '>=', $cutoffDate) | ->whereDate('updated_at', '>=', $cutoffDate) | ||||
->limit(5)->count(); | ->limit(4)->count(); | ||||
// Automatically create a whitelist if we have at least 5 messages from the sender | // Automatically create a whitelist if we have at least 5 (4 existing plus this) messages from the sender | ||||
if ($count >= 5) { | if ($count >= 4) { | ||||
$this->whitelist = Whitelist::create( | $this->whitelist = Whitelist::create( | ||||
[ | [ | ||||
'sender_domain' => $this->senderDomain, | 'sender_domain' => $this->senderDomain, | ||||
'net_id' => $this->netID, | 'net_id' => $this->netID, | ||||
'net_type' => $this->netType, | 'net_type' => $this->netType, | ||||
'created_at' => $this->timestamp, | 'created_at' => $this->timestamp, | ||||
'updated_at' => $this->timestamp | 'updated_at' => $this->timestamp | ||||
] | ] | ||||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |