Limit to max messages in a packet, currently hard coded to 50

This commit is contained in:
Deon George 2022-12-03 00:22:56 +11:00
parent 170f5c87ed
commit 14349adeab
3 changed files with 41 additions and 5 deletions

View File

@ -544,10 +544,18 @@ class Address extends Model
if ($echomail) if ($echomail)
return $this->getPacket($echomail); return $this->getPacket($echomail);
$s = Setup::findOrFail(config('app.id'));
if (($x=$this->echomailWaiting()) if (($x=$this->echomailWaiting())
->count()) ->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); $pkt = $this->getPacket($x);
@ -593,12 +601,13 @@ class Address extends Model
/** /**
* Return a packet of mail * Return a packet of mail
* *
* @param Collection $c of message models (Echomail/Netmail) * @param Collection $msgs of message models (Echomail/Netmail)
* @return Packet|null * @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 we dont match on the address, we cannot pack mail for that system
if (! $ao) if (! $ao)
@ -607,8 +616,14 @@ class Address extends Model
$o = new Packet($ao,$this); $o = new Packet($ao,$this);
// $oo = Netmail/Echomail Model // $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)); $o->addMail($oo->packet($this));
}
return $o; return $o;
} }

View File

@ -44,6 +44,8 @@ class Setup extends Model
public const PRODUCT_VERSION_MAJ = 0; public const PRODUCT_VERSION_MAJ = 0;
public const PRODUCT_VERSION_MIN = 0; public const PRODUCT_VERSION_MIN = 0;
public const MAX_MSGS_PKT = 50;
public const hexdigitslower = '0123456789abcdef'; public const hexdigitslower = '0123456789abcdef';
// Our non model attributes and values // Our non model attributes and values
@ -81,6 +83,9 @@ class Setup extends Model
case 'do_prevent': case 'do_prevent':
return $this->internal[$key] ?? FALSE; return $this->internal[$key] ?? FALSE;
case 'max_msgs_pkt':
return self::MAX_MSGS_PKT;
case 'version': case 'version':
return File::exists('VERSION') ? chop(File::get('VERSION')) : 'dev'; return File::exists('VERSION') ? chop(File::get('VERSION')) : 'dev';

View File

@ -1,3 +1,4 @@
<!-- $o = Setup::class -->
@php @php
use App\Models\Setup; use App\Models\Setup;
@endphp @endphp
@ -171,6 +172,21 @@ use App\Models\Setup;
</div> </div>
<div class="row"> <div class="row">
<div class="col-6">
<h3>Echomail Settings</h3>
<div class="form-group row pt-0">
<div class="col-2">
<input class="form-control text-end" type="text" id="msgs_pkt" name="msgs_pkt" value="{{ old('msgs_pkt',$o->max_msgs_pkt) }}" disabled>
</div>
<div class="col-10">
<label class="col-form-label pt-2" for="msgs_pkt">Max Messages per Packet</label>
</div>
</div>
</div>
</div>
<div class="row pt-5">
<div class="col-2"> <div class="col-2">
<a href="{{ url('ftn/domain') }}" class="btn btn-danger">Cancel</a> <a href="{{ url('ftn/domain') }}" class="btn btn-danger">Cancel</a>
</div> </div>