2021-07-17 05:48:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Classes\File;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
|
|
|
use App\Classes\FTN\Packet;
|
|
|
|
|
|
|
|
class Mail extends Item
|
|
|
|
{
|
|
|
|
private Packet $file;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function __construct(Packet $mail,int $action)
|
|
|
|
{
|
|
|
|
switch ($action) {
|
|
|
|
case self::I_SEND:
|
|
|
|
$this->file = $mail;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new \Exception('Unknown action: '.$action);
|
|
|
|
}
|
2023-07-02 13:40:08 +00:00
|
|
|
|
|
|
|
$this->action = $action;
|
2021-07-17 05:48:07 +00:00
|
|
|
}
|
|
|
|
|
2023-07-14 10:03:09 +00:00
|
|
|
public function __get($key) {
|
|
|
|
switch ($key) {
|
|
|
|
case 'file': return $this->file;
|
|
|
|
default:
|
|
|
|
return parent::__get($key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-17 05:48:07 +00:00
|
|
|
public function read(int $start,int $length): string
|
|
|
|
{
|
|
|
|
return substr((string)$this->file,$start,$length);
|
|
|
|
}
|
2023-07-14 10:03:09 +00:00
|
|
|
|
|
|
|
public function youngest(): Carbon
|
|
|
|
{
|
|
|
|
return $this->file->messages->pluck('date')->sort()->last();
|
|
|
|
}
|
2021-07-17 05:48:07 +00:00
|
|
|
}
|