Change the way we figure out zones in packets, some packet testing, fix Echomail import

This commit is contained in:
Deon George
2021-08-29 23:58:12 +10:00
parent 271f066667
commit 9fb6d191d0
11 changed files with 218 additions and 48 deletions

View File

@@ -10,7 +10,7 @@ use Illuminate\Support\Facades\Redis;
use Symfony\Component\HttpFoundation\File\File;
use App\Classes\FTN as FTNBase;
use App\Models\{Address,Domain,Setup,Software};
use App\Models\{Address,Setup,Software,Zone};
class Packet extends FTNBase implements \Iterator, \Countable
{
@@ -110,11 +110,12 @@ class Packet extends FTNBase implements \Iterator, \Countable
* Open a packet file
*
* @param File $file
* @param Domain|null $domain
* @param Zone|null $zone
* @param bool $use_redis
* @return Packet
* @throws InvalidPacketException
*/
public static function open(File $file,Domain $domain=NULL): self
public static function open(File $file,Zone $zone=NULL,bool $use_redis=TRUE): self
{
Log::debug(sprintf('%s:+ Opening Packet [%s]',self::LOGKEY,$file));
@@ -134,6 +135,8 @@ class Packet extends FTNBase implements \Iterator, \Countable
throw new InvalidPacketException('Not a type 2 packet: '.$version);
$o = new self;
$o->zone = $zone;
$o->use_redis = $use_redis;
$o->name = (string)$file;
$o->header = unpack(self::unpackheader(self::v2header),$header);
@@ -151,6 +154,10 @@ class Packet extends FTNBase implements \Iterator, \Countable
else if (! strlen($x))
throw new InvalidPacketException('No message in packet: '.bin2hex($x));
// If zone is null, we'll take the zone from the packet
if (! $o->zone)
$o->zone = Zone::where('zone_id',$o->fz)->where('default',TRUE)->single();
$buf_ptr = 0;
$message = '';
$readbuf = '';
@@ -174,7 +181,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
$last .= substr($readbuf,0,2);
if (($end=strpos($last,"\x00\x02\x00",$buf_ptr)) !== FALSE) {
$o->parseMessage(substr($message,0,$end-2),$domain);
$o->parseMessage(substr($message,0,$end-2));
$last = '';
$message = '';
$buf_ptr = 1+$end;
@@ -217,13 +224,13 @@ class Packet extends FTNBase implements \Iterator, \Countable
}
// Look for the next message
$o->parseMessage($message,$domain);
$o->parseMessage($message);
$message = '';
}
// If our message is still set, then we have an unprocessed message
if ($message)
$o->parseMessage($message,$domain);
$o->parseMessage($message);
return $o;
}
@@ -413,12 +420,11 @@ class Packet extends FTNBase implements \Iterator, \Countable
* Parse a message in a mail packet
*
* @param string $message
* @param Domain|null $domain
* @throws InvalidPacketException
*/
private function parseMessage(string $message,Domain $domain=NULL): void
private function parseMessage(string $message): void
{
$msg = Message::parseMessage($message,$domain);
$msg = Message::parseMessage($message,$this->zone);
// If the message is invalid, we'll ignore it
if ($msg->errors && (
@@ -432,8 +438,9 @@ class Packet extends FTNBase implements \Iterator, \Countable
} else {
if ($this->use_redis) {
Redis::set($msg->msgid ?: sprintf('%s %s',$msg->fftn,Carbon::now()->timestamp),serialize($msg));
$this->messages->push($msg->msgid);
$key = $msg->msgid ?: sprintf('%s %s',$msg->fftn,Carbon::now()->timestamp);
Redis::set($key,serialize($msg));
$this->messages->push($key);
} else {
$this->messages->push($msg);