Remove processed packets if there were no issues
This commit is contained in:
parent
6027ce52ab
commit
7cd3b814bb
@ -45,3 +45,4 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
|
||||
FIDO_DIR=fido
|
||||
FIDO_PACKET_KEEP=
|
||||
|
@ -695,7 +695,7 @@ class Message extends FTNBase
|
||||
if ($domain) {
|
||||
$validator->after(function($validator) {
|
||||
if (! Address::findFTN($this->fftn))
|
||||
$validator->errors()->add('from',sprintf('Undefined Node [%s] sent packet.',$this->fftn));
|
||||
$validator->errors()->add('from',sprintf('Undefined Node [%s] sent message.',$this->fftn));
|
||||
if (! Address::findFTN($this->tftn))
|
||||
$validator->errors()->add('to',sprintf('Undefined Node [%s] for destination.',$this->fftn));
|
||||
});
|
||||
|
@ -56,6 +56,7 @@ class Packet extends FTNBase
|
||||
public File $file; // Packet filename
|
||||
public Collection $messages; // Messages in the Packet
|
||||
private string $name; // Packet name
|
||||
public bool $hasErrors = FALSE; // Packet has validation errors
|
||||
|
||||
public function __construct(Address $o=NULL)
|
||||
{
|
||||
@ -85,7 +86,6 @@ class Packet extends FTNBase
|
||||
|
||||
// PKT Header
|
||||
$header = fread($f,self::HEADER_LEN);
|
||||
Log::debug(sprintf("%s:\n%s",self::LOGKEY,hex_dump($header)));
|
||||
|
||||
// Could not read header
|
||||
if (strlen($header) != self::HEADER_LEN)
|
||||
@ -346,6 +346,15 @@ class Packet extends FTNBase
|
||||
*/
|
||||
public function parseMessage(string $message,Domain $domain=NULL): void
|
||||
{
|
||||
$msg = Message::parseMessage($message,$domain);
|
||||
|
||||
// If the message is invalid, we'll ignore it
|
||||
if ($msg->errors && $msg->errors->messages()->has('from')) {
|
||||
$this->hasErrors = TRUE;
|
||||
Log::error(sprintf('%s:%s Skipping...',self::LOGKEY,join('|',$msg->errors->messages()->get('from'))));
|
||||
|
||||
} else {
|
||||
$this->messages->push(Message::parseMessage($message,$domain));
|
||||
}
|
||||
}
|
||||
}
|
@ -100,7 +100,8 @@ final class Receive extends Item
|
||||
case self::IS_PKT:
|
||||
Log::info(sprintf('%s: - Processing mail packet [%s]',__METHOD__,$this->file));
|
||||
|
||||
foreach (Packet::open(new File($this->file),$this->ao->zone->domain)->messages as $msg) {
|
||||
$po = Packet::open(new File($this->file),$this->ao->zone->domain);
|
||||
foreach ($po->messages as $msg) {
|
||||
Log::info(sprintf('%s: - Mail from [%s] to [%s]',__METHOD__,$msg->fftn,$msg->tftn));
|
||||
|
||||
// @todo Quick check that the packet should be processed by us.
|
||||
@ -109,6 +110,16 @@ final class Receive extends Item
|
||||
// Dispatch job.
|
||||
ProcessPacket::dispatchSync($msg);
|
||||
}
|
||||
|
||||
if ($po->hasErrors) {
|
||||
Log::info(sprintf('%s: - Not deleting packet [%s], as it has validation errors',__METHOD__,$this->file));
|
||||
|
||||
// If we want to keep the packet, we could do that logic here
|
||||
} elseif (! config('app.packet_keep')) {
|
||||
Log::debug(sprintf('%s: - Deleting processed packet [%s]',__METHOD__,$this->file));
|
||||
unlink($this->file);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -16,6 +16,7 @@ return [
|
||||
'name' => env('APP_NAME', 'Laravel'),
|
||||
'id' => env('APP_SETUP_ID', 1),
|
||||
'fido' => env('FIDO_DIR', 'fido'),
|
||||
'packet_keep' => env('FIDO_PACKET_KEEP', FALSE),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user