diff --git a/app/Classes/File.php b/app/Classes/File.php index cdb7910..1d122bd 100644 --- a/app/Classes/File.php +++ b/app/Classes/File.php @@ -30,7 +30,7 @@ class File extends FileBase implements \Iterator case NULL: case 'bin': - if ((strcasecmp($this->getExtension(),'pkt') === 0) || ($path instanceof UploadedFile && (strcasecmp($path->getClientOriginalExtension(),'pkt') === 0))) { + if ($this->isPacket() || ($path instanceof UploadedFile && (strcasecmp($path->getClientOriginalExtension(),'pkt') === 0))) { $this->canHandle = TRUE; break; }; @@ -81,6 +81,16 @@ class File extends FileBase implements \Iterator /* METHODS */ + /** + * Determine if the file is a mail packet + * + * @return bool + */ + private function isPacket(): bool + { + return (strcasecmp($this->getExtension(),'pkt') === 0); + } + public function itemName(): string { return ($this->isArchive && $this->valid()) ? Arr::get(stream_get_meta_data($this->current()),'uri') : $this->getFilename(); @@ -90,4 +100,36 @@ class File extends FileBase implements \Iterator { return $this->isArchive ? Arr::get($this->zipfile,'size') : $this->getSize(); } + + /** + * Return the name of the file, without a node ID prefix + * + * @return string + */ + public function rawName(): string + { + return preg_replace('/^[0-9A-F]{4}-/','',$this->getFilename()); + } + + /** + * Return the packet name + * + * @return string|null + * @throws \Exception + */ + public function pktName(): ?string + { + if ($this->isArchive) { + $this->zipfile = $this->z->statIndex($this->counter,\ZipArchive::FL_UNCHANGED); + + $f = $this->z->getStream($this->zipfile['name']); + if (! $f) + throw new \Exception(sprintf('%s:Failed getting ZipArchive::stream (%s)',self::LOGKEY,$this->z->getStatusString())); + + return preg_replace('/.pkt$/i','',Arr::get(stream_get_meta_data($f),'uri')); + + } else { + return $this->isPacket() ? preg_replace('/.pkt$/i','',$this->rawName()) : NULL; + } + } } \ No newline at end of file diff --git a/app/Classes/File/Receive.php b/app/Classes/File/Receive.php index e55cdd3..5f2cf72 100644 --- a/app/Classes/File/Receive.php +++ b/app/Classes/File/Receive.php @@ -150,9 +150,9 @@ final class Receive extends Item try { // Dispatch job. if ($queue) - MessageProcess::dispatch($msg); + MessageProcess::dispatch($msg,$f->pktName()); else - MessageProcess::dispatchSync($msg); + MessageProcess::dispatchSync($msg,$f->pktName()); } catch (Exception $e) { Log::error(sprintf('%s:! Got error dispatching message [%s] (%d:%s-%s).',self::LOGKEY,$msg->msgid,$e->getLine(),$e->getFile(),$e->getMessage())); diff --git a/app/Console/Commands/PacketProcess.php b/app/Console/Commands/PacketProcess.php index 787824c..ea66ce1 100644 --- a/app/Console/Commands/PacketProcess.php +++ b/app/Console/Commands/PacketProcess.php @@ -48,7 +48,7 @@ class PacketProcess extends Command $this->info(sprintf('Processing message from [%s] with msgid [%s]',$msg->fboss,$msg->msgid)); // Dispatch job. - Job::dispatchSync($msg,$this->option('nobot')); + Job::dispatchSync($msg,$f->pktName(),$this->option('nobot')); } } } diff --git a/app/Jobs/MessageProcess.php b/app/Jobs/MessageProcess.php index d89cb36..73b8c21 100644 --- a/app/Jobs/MessageProcess.php +++ b/app/Jobs/MessageProcess.php @@ -21,12 +21,14 @@ class MessageProcess implements ShouldQueue private Message $msg; private bool $skipbot; + private string $packet; - public function __construct(Message $msg,bool $skipbot=FALSE) + public function __construct(Message $msg,string $packet,bool $skipbot=FALSE) { // Some checks $this->msg = $msg; $this->skipbot = $skipbot; + $this->packet = $packet; } /** @@ -43,6 +45,9 @@ class MessageProcess implements ShouldQueue // @todo Enable checks to reject duplicate // @todo Enable checks to see if this is a file request or file send + $o = $this->create_netmail($this->msg); + $o->recv_pkt = $this->packet; + // Determine if the message is to this system, or in transit if ($ftns->search(function($item) { return $this->msg->tftn == $item->ftn; }) !== FALSE) { // @todo Check if it is a duplicate message @@ -60,13 +65,17 @@ class MessageProcess implements ShouldQueue // We'll ignore messages from *fix users if (in_array(strtolower($this->msg->user_from),['filefix','areafix'])) { - Log::info(sprintf('Ignoring Netmail to the Hub from (%s) [%s] - its from a bot.',$this->msg->user_from,$this->msg->fftn)); - - $o = $this->create_netmail($this->msg); $o->local = TRUE; - $o->save(); + Log::info(sprintf('%s:Ignoring Netmail [%d-%s] to the Hub from (%s) [%s] - its from a bot.', + self::LOGKEY, + $o->id, + $this->msg->msgid, + $this->msg->user_from, + $this->msg->fftn) + ); + $processed = TRUE; } @@ -122,19 +131,19 @@ class MessageProcess implements ShouldQueue // If in transit, store for collection } else { - Log::info(sprintf('%s:Netmail [%s] in transit to (%s) [%s] from (%s) [%s].', - self::LOGKEY, - $this->msg->msgid, - $this->msg->user_to,$this->msg->tftn, - $this->msg->user_from,$this->msg->fftn, - )); - // @todo Check if the message is to a system we know about // @todo In transit loop checking // @todo In transit TRACE response - $o = $this->create_netmail($this->msg); $o->save(); + + Log::info(sprintf('%s:Netmail [%d-%s] in transit to (%s) [%s] from (%s) [%s].', + self::LOGKEY, + $o->id, + $this->msg->msgid, + $this->msg->user_to,$this->msg->tftn, + $this->msg->user_from,$this->msg->fftn, + )); } // Else we are echomail @@ -185,6 +194,7 @@ class MessageProcess implements ShouldQueue // @todo This duplicate message may have gone via a different path, be nice to record it. //$o->path()->sync($o->path->pluck('id')->merge($this->msg->pathaddress)->toArray()); // @todo if we have an export for any of the seenby addresses, remove it + // @todo add received packet details $o->seenby()->sync($o->seenby->pluck('id')->merge($this->msg->seenaddress)->filter()->toArray()); return; diff --git a/app/Models/Address.php b/app/Models/Address.php index e472f25..d845927 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -636,6 +636,7 @@ class Address extends Model public function netmailWaiting(): Collection { return Netmail::whereIn('tftn_id',(($x=$this->children) ? $x->pluck('id') : collect())->push($this->id)) + ->where('local',FALSE) ->whereNull('sent_at') ->get(); }