Add packet name for incoming netmails, dont send back messages to sender for areafix messages

This commit is contained in:
Deon George 2023-01-24 22:37:41 +11:00
parent bc19f9aa82
commit 63e3397aee
5 changed files with 70 additions and 17 deletions

View File

@ -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;
}
}
}

View File

@ -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()));

View File

@ -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'));
}
}
}

View File

@ -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;

View File

@ -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();
}