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)
|
|
|
|
{
|
|
|
|
$this->action |= $action;
|
|
|
|
|
|
|
|
switch ($action) {
|
|
|
|
case self::I_SEND:
|
|
|
|
$this->file = $mail;
|
2021-07-18 12:10:21 +00:00
|
|
|
$this->file_name = sprintf('%08x.pkt',Carbon::now()->timestamp);
|
2021-07-17 05:48:07 +00:00
|
|
|
$this->file_size = strlen($mail);
|
|
|
|
$this->file_mtime = Carbon::now()->timestamp; // @todo This timestamp should be consistent incase of retries
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new \Exception('Unknown action: '.$action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function read(int $start,int $length): string
|
|
|
|
{
|
|
|
|
return substr((string)$this->file,$start,$length);
|
|
|
|
}
|
|
|
|
}
|