From 7da09a1a9e712687b23292a711c1cf8af15e7404 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 22 Oct 2024 19:17:03 +1100 Subject: [PATCH] Better handling of badly addressed packets for netmails --- app/Classes/FTN/Message.php | 10 ++++++++-- app/Classes/FTN/Packet.php | 3 +-- app/Models/Netmail.php | 6 ++++++ app/Notifications/Netmails/NetmailBadAddress.php | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index 6d96125..1569738 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -878,11 +878,17 @@ class Message extends FTNBase $validator->after(function($validator) { if ($this->zone->domain->flatten) { if (! $this->zone->domain->zones->pluck('zone_id')->contains($this->fz)) - $validator->errors()->add('invalid-zone',sprintf('Message zone [%d] doesnt match any zone in domain for packet zone [%d].',$this->fz,$this->zone->zone_id)); + $validator->errors()->add('invalid-zone',sprintf('Message from zone [%d] doesnt match any zone in domain for packet zone [%d].',$this->fz,$this->zone->zone_id)); + + if (! $this->zone->domain->zones->pluck('zone_id')->contains($this->tz)) + $validator->errors()->add('invalid-zone',sprintf('Message to zone [%d] doesnt match any zone in domain for packet zone [%d].',$this->fz,$this->zone->zone_id)); } else { if ($this->zone->zone_id !== $this->fz) - $validator->errors()->add('invalid-zone',sprintf('Message zone [%d] doesnt match packet zone [%d].',$this->fz,$this->zone->zone_id)); + $validator->errors()->add('invalid-zone',sprintf('Message from zone [%d] doesnt match packet zone [%d].',$this->fz,$this->zone->zone_id)); + + if ($this->zone->zone_id !== $this->tz) + $validator->errors()->add('invalid-zone',sprintf('Message to zone [%d] doesnt match packet zone [%d].',$this->tz,$this->zone->zone_id)); } if (! $this->fftn) diff --git a/app/Classes/FTN/Packet.php b/app/Classes/FTN/Packet.php index b7da2ed..544c78a 100644 --- a/app/Classes/FTN/Packet.php +++ b/app/Classes/FTN/Packet.php @@ -386,9 +386,8 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable // If the messages is not for the right zone, we'll ignore it if ($msg->errors->has('invalid-zone')) { - Log::alert(sprintf('%s:! Message [%s] is from an invalid zone [%s], packet is from [%s] - ignoring it',self::LOGKEY,$msg->msgid,$msg->set_fftn,$this->fz)); + Log::alert(sprintf('%s:! Message [%s] is from|to an invalid zone [%s|%s], packet is from [%s] - ignoring it',self::LOGKEY,$msg->msgid,$msg->get_fftn,$msg->get_tftn,$this->fz)); - // @todo $msg might not be echomail if (! $msg->kludges->get('RESCANNED')) Notification::route('netmail',$this->fftn)->notify(($msg instanceof Echomail) ? new EchomailBadAddress($msg) : new NetmailBadAddress($msg)); diff --git a/app/Models/Netmail.php b/app/Models/Netmail.php index b84796c..8ff8262 100644 --- a/app/Models/Netmail.php +++ b/app/Models/Netmail.php @@ -46,6 +46,12 @@ final class Netmail extends Model implements Packet public function __get($key) { switch ($key) { + case 'get_fftn': + return $this->set->get('set_fftn') ?: $this->fftn->ftn; + + case 'get_tftn': + return $this->set->get('set_tftn') ?: $this->tftn->ftn; + case 'set_fftn': case 'set_tftn': case 'set_path': diff --git a/app/Notifications/Netmails/NetmailBadAddress.php b/app/Notifications/Netmails/NetmailBadAddress.php index 84624a1..556b3ef 100644 --- a/app/Notifications/Netmails/NetmailBadAddress.php +++ b/app/Notifications/Netmails/NetmailBadAddress.php @@ -49,7 +49,7 @@ class NetmailBadAddress extends Netmails $msg->addText($this->sourceSummary($this->mo)."\r\r"); - $msg->addText(sprintf("The address in this netmail [%s] is the wrong address for the domain [%s].\r\r",$this->mo->set_fftn,$ao->zone->domain->name)); + $msg->addText(sprintf("The from [%s] or to [%s] address in this netmail is the wrong address for the domain [%s].\r\r",$this->mo->get_fftn,$this->mo->get_tftn,$ao->zone->domain->name)); $msg->addText("This netmail has been rejected and not stored here - so no downstream node will receive it. If you think this is a mistake, please let me know.\r\r");