Page MenuHomePhorge

D5754.1774812424.diff
No OneTemporary

Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None

D5754.1774812424.diff

diff --git a/src/app/Policy/Greylist.php b/src/app/Policy/Greylist.php
--- a/src/app/Policy/Greylist.php
+++ b/src/app/Policy/Greylist.php
@@ -25,6 +25,11 @@
protected $whitelist;
protected $request = [];
+ public const CONNECTION_MIN_AGE_MINUTES = 5;
+ public const CONNECTION_MAX_AGE_DAYS = 7;
+ public const CONNECTION_WHITELIST_THRESHOLD = 5;
+ public const CONNECTION_WHITELIST_MAX_AGE_MONTHS = 1;
+
/**
* Class constructor
*
@@ -122,7 +127,7 @@
$connect = $this->findConnectsCollection()->first();
// Purge all old information if we have no recent entry
- if ($connect && $connect->updated_at < $this->timestamp->copy()->subDays(7)) {
+ if ($connect && $connect->updated_at < $this->timestamp->copy()->subDays(self::CONNECTION_MAX_AGE_DAYS)) {
$this->findConnectsCollection()->delete();
$connect = null;
}
@@ -143,12 +148,12 @@
->where('net_type', $this->netType)
->first();
- $cutoffDate = $this->timestamp->copy()->subDays(7)->startOfDay();
+ $cutoffDate = $this->timestamp->copy()->subDays(self::CONNECTION_MAX_AGE_DAYS)->startOfDay();
DB::beginTransaction();
// Whitelist older than a month, delete it
- if ($this->whitelist && $this->whitelist->updated_at < $this->timestamp->copy()->subMonthsWithoutOverflow(1)) {
+ if ($this->whitelist && $this->whitelist->updated_at < $this->timestamp->copy()->subMonthsWithoutOverflow(self::CONNECTION_WHITELIST_MAX_AGE_MONTHS)) {
$this->whitelist->delete();
$this->whitelist = null;
}
@@ -172,7 +177,7 @@
->update(['greylisting' => false, 'updated_at' => $this->timestamp]);
$enabled = false;
- } elseif ($all->count() >= 4) {
+ } elseif ($all->count() >= (self::CONNECTION_WHITELIST_THRESHOLD - 1)) {
// Automatically create a whitelist if we have at least 5 (4 existing plus this) messages from the sender
$this->whitelist = Whitelist::create([
'sender_domain' => $this->senderDomain,
@@ -202,7 +207,7 @@
$connect->connect_count++;
// 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(self::CONNECTION_MIN_AGE_MINUTES)) {
$defer = false;
$connect->greylisting = false;
diff --git a/src/tests/Feature/Policy/GreylistTest.php b/src/tests/Feature/Policy/GreylistTest.php
--- a/src/tests/Feature/Policy/GreylistTest.php
+++ b/src/tests/Feature/Policy/GreylistTest.php
@@ -86,7 +86,7 @@
$this->assertNull($whitelist);
- for ($i = 0; $i < 5; $i++) {
+ for ($i = 0; $i < Greylist::CONNECTION_WHITELIST_THRESHOLD; $i++) {
$request = new Greylist([
'sender' => "someone{$i}@sender.domain",
'recipient' => $this->domainOwner->email,
@@ -102,8 +102,9 @@
$this->assertNotNull($whitelist);
+ $i = Greylist::CONNECTION_WHITELIST_THRESHOLD;
$request = new Greylist([
- 'sender' => "someone5@sender.domain",
+ 'sender' => "someone{$i}@sender.domain",
'recipient' => $this->domainOwner->email,
'client_address' => $this->clientAddress,
'client_name' => 'some.mx',
@@ -116,7 +117,7 @@
Greylist\Whitelist::where('sender_domain', 'sender.domain')->delete();
// Test a stale whitelist
- for ($i = 0; $i < 5; $i++) {
+ for ($i = 0; $i < Greylist::CONNECTION_WHITELIST_THRESHOLD; $i++) {
$request = new Greylist([
'sender' => "someone{$i}@sender.domain",
'recipient' => $this->domainOwner->email,
@@ -132,8 +133,9 @@
$this->assertNotNull($whitelist);
+ $i = Greylist::CONNECTION_WHITELIST_THRESHOLD;
$request = new Greylist([
- 'sender' => "someone5@sender.domain",
+ 'sender' => "someone{$i}@sender.domain",
'recipient' => $this->domainOwner->email,
'client_address' => $this->clientAddress,
'client_name' => 'some.mx',
@@ -142,7 +144,7 @@
$this->assertFalse($request->shouldDefer());
- $whitelist->updated_at = Carbon::now()->subMonthsWithoutOverflow(2);
+ $whitelist->updated_at = Carbon::now()->subMonthsWithoutOverflow(Greylist::CONNECTION_WHITELIST_MAX_AGE_MONTHS + 1);
$whitelist->save(['timestamps' => false]);
$this->assertTrue($request->shouldDefer());
@@ -162,7 +164,7 @@
'net_type' => IP4Net::class,
]);
- $connect->created_at = Carbon::now()->subMinutes(6);
+ $connect->created_at = Carbon::now()->subMinutes(Greylist::CONNECTION_MIN_AGE_MINUTES + 1);
$connect->save();
$request = new Greylist([
@@ -254,7 +256,7 @@
$this->assertTrue($request->shouldDefer());
- $connect->created_at = Carbon::now()->subMinutes(6);
+ $connect->created_at = Carbon::now()->subMinutes(Greylist::CONNECTION_MIN_AGE_MINUTES + 1);
$connect->save();
$this->assertFalse($request->shouldDefer());
@@ -399,7 +401,7 @@
$whitelist = Greylist\Whitelist::where('sender_domain', 'sender.domain')->first();
$this->assertNull($whitelist);
- for ($i = 0; $i < 5; $i++) {
+ for ($i = 0; $i < Greylist::CONNECTION_WHITELIST_THRESHOLD; $i++) {
$request = new Greylist([
'sender' => "someone{$i}@sender.domain",
'recipient' => $this->testSharedFolder->email,
@@ -414,8 +416,9 @@
$whitelist = Greylist\Whitelist::where('sender_domain', 'sender.domain')->first();
$this->assertNotNull($whitelist);
+ $i = Greylist::CONNECTION_WHITELIST_THRESHOLD;
$request = new Greylist([
- 'sender' => "someone5@sender.domain",
+ 'sender' => "someone{$i}@sender.domain",
'recipient' => $this->testSharedFolder->email,
'client_address' => $this->clientAddress,
'client_name' => 'some.mx',
@@ -431,7 +434,7 @@
$whitelist = Greylist\Whitelist::where('sender_domain', 'sender.domain')->first();
$this->assertNull($whitelist);
- for ($i = 0; $i < 5; $i++) {
+ for ($i = 0; $i < Greylist::CONNECTION_WHITELIST_THRESHOLD; $i++) {
$request = new Greylist([
'sender' => "someone{$i}@sender.domain",
'recipient' => $this->testResource->email,
@@ -446,8 +449,9 @@
$whitelist = Greylist\Whitelist::where('sender_domain', 'sender.domain')->first();
$this->assertNotNull($whitelist);
+ $i = Greylist::CONNECTION_WHITELIST_THRESHOLD;
$request = new Greylist([
- 'sender' => "someone5@sender.domain",
+ 'sender' => "someone{$i}@sender.domain",
'recipient' => $this->testResource->email,
'client_address' => $this->clientAddress,
'client_name' => 'some.mx',

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 29, 7:27 PM (3 d, 15 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18735768
Default Alt Text
D5754.1774812424.diff (7 KB)

Event Timeline