Dont process incomplete files
This commit is contained in:
parent
8996b3d09b
commit
393600f96f
@ -32,6 +32,7 @@ class Item
|
||||
|
||||
public bool $sent = FALSE;
|
||||
public bool $received = FALSE;
|
||||
public bool $incomplete = FALSE;
|
||||
|
||||
/**
|
||||
* @throws FileNotFoundException
|
||||
|
@ -84,8 +84,10 @@ final class Receive extends Item
|
||||
if (! $this->f)
|
||||
throw new Exception('No file to close');
|
||||
|
||||
if ($this->file_pos != $this->receiving->file_size)
|
||||
if ($this->file_pos != $this->receiving->file_size) {
|
||||
Log::warning(sprintf('%s: - Closing [%s], but missing [%d] bytes',__METHOD__,$this->receiving->file_name,$this->receiving->file_size-$this->file_pos));
|
||||
$this->receiving->incomplete = TRUE;
|
||||
}
|
||||
|
||||
$this->receiving->received = TRUE;
|
||||
|
||||
@ -96,44 +98,47 @@ final class Receive extends Item
|
||||
$this->file_pos = 0;
|
||||
$this->f = NULL;
|
||||
|
||||
// If the packet has been received but not the right size, dont process it any more.
|
||||
|
||||
// If we received a packet, we'll dispatch a job to process it
|
||||
switch ($this->receiving->file_type) {
|
||||
case self::IS_PKT:
|
||||
Log::info(sprintf('%s: - Processing mail packet [%s]',__METHOD__,$this->file));
|
||||
if (! $this->receiving->incomplete)
|
||||
switch ($this->receiving->file_type) {
|
||||
case self::IS_PKT:
|
||||
Log::info(sprintf('%s: - Processing mail packet [%s]',__METHOD__,$this->file));
|
||||
|
||||
try {
|
||||
$po = Packet::open(new File($this->file),$this->ao->zone->domain);
|
||||
try {
|
||||
$po = Packet::open(new File($this->file),$this->ao->zone->domain);
|
||||
|
||||
} catch (InvalidPacketException $e) {
|
||||
Log::error(sprintf('%s: - Not deleting packet [%s], as it generated an exception',__METHOD__,$this->file));
|
||||
} catch (InvalidPacketException $e) {
|
||||
Log::error(sprintf('%s: - Not deleting packet [%s], as it generated an exception',__METHOD__,$this->file));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
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.
|
||||
// @todo validate that the packet's zone is in the domain.
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
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.
|
||||
// @todo validate that the packet's zone is in the domain.
|
||||
|
||||
// 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:
|
||||
Log::debug(sprintf('%s: - Leaving file [%s] in the inbound dir',__METHOD__,$this->file));
|
||||
}
|
||||
default:
|
||||
Log::debug(sprintf('%s: - Leaving file [%s] in the inbound dir',__METHOD__,$this->file));
|
||||
}
|
||||
|
||||
$this->receiving = NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user