From 14349adeab7c73ea4afcf01fbefc76ed0e3aea9d Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 3 Dec 2022 00:22:56 +1100 Subject: [PATCH] Limit to max messages in a packet, currently hard coded to 50 --- app/Models/Address.php | 25 ++++++++++++++++++++----- app/Models/Setup.php | 5 +++++ resources/views/setup.blade.php | 16 ++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/app/Models/Address.php b/app/Models/Address.php index 60cddff..e472f25 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -544,10 +544,18 @@ class Address extends Model if ($echomail) return $this->getPacket($echomail); + $s = Setup::findOrFail(config('app.id')); + if (($x=$this->echomailWaiting()) ->count()) { - Log::debug(sprintf('%s:= Got [%d] echomails for [%s] for sending',self::LOGKEY,$x->count(),$this->ftn)); + // Limit to max messages + Log::info(sprintf('%s:= Got [%d] echomails for [%s] for sending',self::LOGKEY,$x->count(),$this->ftn)); + + if ($x->count() > $s->max_msgs_pkt) { + $x = $x->take($s->max_msgs_pkt); + Log::alert(sprintf('%s:= Only sending [%d] echomails for [%s]',self::LOGKEY,$x->count(),$this->ftn)); + } $pkt = $this->getPacket($x); @@ -593,12 +601,13 @@ class Address extends Model /** * Return a packet of mail * - * @param Collection $c of message models (Echomail/Netmail) + * @param Collection $msgs of message models (Echomail/Netmail) * @return Packet|null */ - private function getPacket(Collection $c): ?Packet + private function getPacket(Collection $msgs): ?Packet { - $ao = Setup::findOrFail(config('app.id'))->system->match($this->zone)->first(); + $s = Setup::findOrFail(config('app.id')); + $ao = $s->system->match($this->zone)->first(); // If we dont match on the address, we cannot pack mail for that system if (! $ao) @@ -607,8 +616,14 @@ class Address extends Model $o = new Packet($ao,$this); // $oo = Netmail/Echomail Model - foreach ($c as $oo) + $c = 0; + foreach ($msgs as $oo) { + // Only bundle up to max messages + if (++$c > $s->max_msgs_pkt) + break; + $o->addMail($oo->packet($this)); + } return $o; } diff --git a/app/Models/Setup.php b/app/Models/Setup.php index 2e80a70..a7e811e 100644 --- a/app/Models/Setup.php +++ b/app/Models/Setup.php @@ -44,6 +44,8 @@ class Setup extends Model public const PRODUCT_VERSION_MAJ = 0; public const PRODUCT_VERSION_MIN = 0; + public const MAX_MSGS_PKT = 50; + public const hexdigitslower = '0123456789abcdef'; // Our non model attributes and values @@ -81,6 +83,9 @@ class Setup extends Model case 'do_prevent': return $this->internal[$key] ?? FALSE; + case 'max_msgs_pkt': + return self::MAX_MSGS_PKT; + case 'version': return File::exists('VERSION') ? chop(File::get('VERSION')) : 'dev'; diff --git a/resources/views/setup.blade.php b/resources/views/setup.blade.php index bfba81f..7e332e4 100644 --- a/resources/views/setup.blade.php +++ b/resources/views/setup.blade.php @@ -1,3 +1,4 @@ + @php use App\Models\Setup; @endphp @@ -171,6 +172,21 @@ use App\Models\Setup;
+
+

Echomail Settings

+ +
+
+ +
+
+ +
+
+
+
+ +