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