Better catching bad TZUTC in messages, continue parsing mail bundles in an archive if a packet has an error
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 36s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m48s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s

This commit is contained in:
Deon George 2024-10-22 17:08:48 +11:00
parent eb61c5ea6e
commit 86a15872b8
4 changed files with 246 additions and 206 deletions

View File

@ -89,7 +89,7 @@ class Message extends FTNBase
public const AREATAG_LEN = 35; //
private array $header; // Message Header
private int $tzutc = 0; // TZUTC that needs to be converted to be used by Carbon @see self::kludges
private Collection $kludges; // TZUTC that needs to be converted to be used by Carbon @see self::kludges
private Echomail|Netmail $mo; // The object storing this packet message
private Address $us; // Our address for this message
@ -294,6 +294,7 @@ class Message extends FTNBase
public function __construct(Zone $zone)
{
$this->zone = $zone;
$this->kludges = collect();
}
public function __get($key)
@ -476,11 +477,25 @@ class Message extends FTNBase
break;
case 'tzutc':
return $this->kludges->get($key);
default:
throw new \Exception('Unknown key: '.$key);
}
}
public function __set(string $key,mixed $value): void
{
switch ($key) {
case 'tzutc':
if (! is_numeric($value))
throw new InvalidPacketException('TZUTC is not numeric '.$value);
$this->kludges->put($key,$value);
}
}
/**
* Export an FTN message, ready for sending.
*
@ -654,7 +669,9 @@ class Message extends FTNBase
// First find our kludge lines
$ptr_start = 0;
$ptr_end = 0;
try {
while (substr($message,$ptr_start,1) === "\x01") {
$ptr_end = strpos($message,"\r",$ptr_start);
@ -797,6 +814,15 @@ class Message extends FTNBase
$o->kludges = [$m[1],$m[2]];
}
} catch (\Exception $e) {
Log::error(sprintf('%s:! Error parsing message, now at offset [0x%02x] (%s)',
self::LOGKEY,
$ptr_start,
$e->getMessage()),['dump'=>hex_dump($message)]);
throw new InvalidPacketException('Error parsing message');
}
return $o;
}

View File

@ -174,6 +174,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable
|| (($end=strpos($msgbuf,"\x00".self::PACKED_END,$leader)) !== FALSE))
{
// 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));
$msgbuf = substr($msgbuf,$end+3);

View File

@ -83,6 +83,11 @@ class File extends FileBase implements \Iterator
/* METHODS */
public function isArchive(): bool
{
return $this->isArchive;
}
/**
* Determine if the file is a mail packet
*

View File

@ -67,8 +67,10 @@ class PacketProcess implements ShouldQueue
$f = new File($fs->path($this->filename));
$processed = FALSE;
$bad_archive = FALSE;
foreach ($f as $packet) {
try {
$pkt = Packet::process($packet,Arr::get(stream_get_meta_data($packet),'uri'),$f->itemSize(),$this->do);
// Check that the packet is from a system that is defined in the DB
@ -153,9 +155,15 @@ class PacketProcess implements ShouldQueue
if ($count === $pkt->count())
$processed = TRUE;
} catch (\Exception $e) {
Log::error(sprintf('%s:! Got an exception [%s] processing packet',self::LOGKEY,$e->getMessage()));
$bad_archive = TRUE;
}
}
if (! $processed) {
if ((! $processed) || $bad_archive) {
Log::alert(sprintf('%s:- Not deleting packet [%s], it doesnt seem to be processed?',self::LOGKEY,$this->filename));
} else {