Sending Mail now dynamically creates packet name, size and mtime
This commit is contained in:
@@ -18,9 +18,6 @@ class Mail extends Item
|
||||
switch ($action) {
|
||||
case self::I_SEND:
|
||||
$this->file = $mail;
|
||||
$this->file_name = sprintf('%s.pkt',$mail->name);
|
||||
$this->file_size = strlen($mail);
|
||||
$this->file_mtime = Carbon::now()->timestamp; // @todo This timestamp should be consistent incase of retries
|
||||
|
||||
break;
|
||||
|
||||
@@ -31,8 +28,21 @@ class Mail extends Item
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
public function __get($key) {
|
||||
switch ($key) {
|
||||
case 'file': return $this->file;
|
||||
default:
|
||||
return parent::__get($key);
|
||||
}
|
||||
}
|
||||
|
||||
public function read(int $start,int $length): string
|
||||
{
|
||||
return substr((string)$this->file,$start,$length);
|
||||
}
|
||||
|
||||
public function youngest(): Carbon
|
||||
{
|
||||
return $this->file->messages->pluck('date')->sort()->last();
|
||||
}
|
||||
}
|
@@ -70,12 +70,18 @@ final class Send extends Item
|
||||
+ $this->packets->sum(function($item) { return $item->size; });
|
||||
|
||||
case 'sendas':
|
||||
return $this->sending ? $this->sending->{$key} : NULL;
|
||||
return $this->sending?->{$key};
|
||||
|
||||
case 'name':
|
||||
// The mtime is the time of the youngest message in the packet for the sending packet
|
||||
case 'mtime':
|
||||
return $this->sending?->youngest()->timestamp;
|
||||
|
||||
// The name is derived from the youngest message in the packet
|
||||
case 'name':
|
||||
return sprintf('%08x',timew($this->sending?->youngest()));
|
||||
|
||||
case 'size':
|
||||
return $this->sending ? $this->sending->{'file_'.$key} : NULL;
|
||||
return strlen($this->sending?->file);
|
||||
|
||||
case 'total_sent':
|
||||
return $this->list
|
||||
@@ -297,7 +303,7 @@ final class Send extends Item
|
||||
* @throws Exception
|
||||
* @todo We need to make this into a transaction, incase the transfer fails.
|
||||
*/
|
||||
public function mail(Address $ao): bool
|
||||
public function mail(Address $ao,bool $update=TRUE): bool
|
||||
{
|
||||
$mail = FALSE;
|
||||
|
||||
@@ -309,7 +315,7 @@ final class Send extends Item
|
||||
}
|
||||
|
||||
// Netmail
|
||||
if ($x=$ao->getNetmail()) {
|
||||
if ($x=$ao->getNetmail($update)) {
|
||||
Log::debug(sprintf('%s: - Netmail(s) added for sending to [%s]',self::LOGKEY,$ao->ftn));
|
||||
|
||||
$this->packets->push(new Mail($x,self::I_SEND));
|
||||
@@ -317,7 +323,7 @@ final class Send extends Item
|
||||
}
|
||||
|
||||
// Echomail
|
||||
if ($x=$ao->getEchomail()) {
|
||||
if ($x=$ao->getEchomail($update)) {
|
||||
Log::debug(sprintf('%s: - Echomail(s) added for sending to [%s]',self::LOGKEY,$ao->ftn));
|
||||
|
||||
$this->packets->push(new Mail($x,self::I_SEND));
|
||||
|
Reference in New Issue
Block a user