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)
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;
}