Validation to make sure netmails have an INTL kludge, needed to determine address details. Update Packet View to not trigger validation netmails

This commit is contained in:
Deon George 2024-11-17 21:37:26 +11:00
parent e802fe5030
commit 59af68dca8
3 changed files with 11 additions and 6 deletions

View File

@ -874,6 +874,9 @@ class Message extends FTNBase
);
$validator->after(function($validator) {
if (($this->mo instanceof Netmail) && (! $this->mo->kludges->has('INTL')))
$validator->errors()->add('no-intl','Netmail message is missing INTL KLUDGE.');
if ($this->zone->domain->flatten) {
if (! $this->zone->domain->zones->pluck('zone_id')->contains($this->fz))
$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));

View File

@ -89,10 +89,11 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
* @param string $name
* @param int $size
* @param System|null $so - The system that sent us the packet, used to figure out domains if the packet is for a different zone
* @param bool $process
* @return Packet
* @throws InvalidPacketException
*/
public static function process(mixed $f,string $name,int $size,System $so=NULL): self
public static function process(mixed $f,string $name,int $size,System $so=NULL,bool $process=TRUE): self
{
Log::debug(sprintf('%s:+ Opening Packet [%s] with size [%d]',self::LOGKEY,$name,$size));
@ -183,7 +184,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
{
// Parse our message
Log::debug(sprintf('%s:- Message at offset [%d] in [%s]',self::LOGKEY,$read_ptr-strlen($readbuf),$name));
$o->parseMessage(substr($msgbuf,0,$end));
$o->parseMessage(substr($msgbuf,0,$end),$process);
$msgbuf = substr($msgbuf,$end+3);
continue;
@ -380,16 +381,17 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
* Parse a message in a mail packet
*
* @param string $message
* @throws InvalidPacketException|\Exception
* @param bool $process
* @throws \Exception
*/
private function parseMessage(string $message): void
private function parseMessage(string $message,bool $process): void
{
Log::info(sprintf('%s:+ Processing packet message [%d] bytes',self::LOGKEY,strlen($message)));
$msg = Message::parseMessage($message,$this->zone);
// If the message is invalid, we'll ignore it
if ($msg->errors->count()) {
if ($process && $msg->errors->count()) {
Log::info(sprintf('%s:- Message [%s] has [%d] errors',self::LOGKEY,$msg->msgid ?: 'No ID',$msg->errors->count()));
// If the messages is not for the right zone, we'll ignore it

View File

@ -104,7 +104,7 @@ class HomeController extends Controller
$f = new File($file);
foreach ($f as $packet)
$pkt->push([$f->itemName()=>Packet::process($packet,$f->itemName(),$f->itemSize())]);
$pkt->push([$f->itemName()=>Packet::process($packet,$f->itemName(),$f->itemSize(),NULL,FALSE)]);
} catch (\Exception $e) {
return redirect()->back()->withErrors(sprintf('%s (%s:%d)',$e->getMessage(),$e->getFile(),$e->getLine()));