2024-05-17 12:10:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Common Attributes used by message packets (and thus their Models)
|
|
|
|
*/
|
|
|
|
namespace App\Traits;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2024-05-20 11:31:21 +00:00
|
|
|
use Illuminate\Support\MessageBag;
|
2024-05-17 12:10:54 +00:00
|
|
|
|
|
|
|
use App\Classes\FTN\Message;
|
|
|
|
use App\Models\Address;
|
|
|
|
|
|
|
|
trait MessageAttributes
|
|
|
|
{
|
|
|
|
use EncodeUTF8;
|
|
|
|
|
|
|
|
// Items we need to set when creating()
|
|
|
|
public Collection $set;
|
|
|
|
// Validation Errors
|
2024-05-20 11:31:21 +00:00
|
|
|
public ?MessageBag $errors = NULL;
|
2024-05-17 12:10:54 +00:00
|
|
|
|
|
|
|
private const cast_utf8 = [
|
|
|
|
'to',
|
|
|
|
'from',
|
|
|
|
'subject',
|
|
|
|
'msg',
|
|
|
|
'msg_src',
|
|
|
|
'origin',
|
|
|
|
'tearline',
|
|
|
|
'tagline',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
// Init
|
|
|
|
$this->set = collect();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ATTRIBUTES */
|
|
|
|
|
|
|
|
public function getContentAttribute(): string
|
|
|
|
{
|
|
|
|
if ($this->msg_src)
|
2024-05-20 11:31:21 +00:00
|
|
|
return $this->msg_src;
|
2024-05-17 12:10:54 +00:00
|
|
|
|
|
|
|
// If we have a msg_src attribute, we'll use that
|
|
|
|
$result = $this->msg."\r\r";
|
|
|
|
|
|
|
|
if ($this->tagline)
|
|
|
|
$result .= sprintf("%s\r",$this->tagline);
|
|
|
|
|
|
|
|
if ($this->tearline)
|
|
|
|
$result .= sprintf("%s\r",$this->tearline);
|
|
|
|
|
|
|
|
if ($this->origin)
|
|
|
|
$result .= sprintf("%s",$this->origin);
|
|
|
|
|
2024-05-20 11:31:21 +00:00
|
|
|
return rtrim($result,"\r").'xx';
|
2024-05-17 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getDateAttribute(): Carbon
|
|
|
|
{
|
|
|
|
return $this->datetime->utcOffset($this->tzoffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOriginAttribute(string $val=NULL): ?string
|
|
|
|
{
|
2024-05-19 13:28:45 +00:00
|
|
|
if ($this->exists && (! $val))
|
|
|
|
return $val;
|
|
|
|
|
2024-05-17 12:10:54 +00:00
|
|
|
// If $val is not set, then it may be an unsaved object
|
2024-05-19 13:28:45 +00:00
|
|
|
return sprintf(' * Origin: %s',
|
|
|
|
((! $this->exists) && $this->set->has('set_origin'))
|
|
|
|
? $this->set->get('set_origin')
|
|
|
|
: $val);
|
2024-05-17 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getTaglineAttribute(string $val=NULL): ?string
|
|
|
|
{
|
2024-05-19 13:28:45 +00:00
|
|
|
if ($this->exists && (! $val))
|
|
|
|
return $val;
|
|
|
|
|
2024-05-17 12:10:54 +00:00
|
|
|
// If $val is not set, then it may be an unsaved object
|
2024-05-19 13:28:45 +00:00
|
|
|
return sprintf('... %s',
|
|
|
|
((! $this->exists) && $this->set->has('set_tagline'))
|
|
|
|
? $this->set->get('set_tagline')
|
|
|
|
: $val);
|
2024-05-17 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getTearlineAttribute(string $val=NULL): ?string
|
|
|
|
{
|
2024-05-19 13:28:45 +00:00
|
|
|
if ($this->exists && (! $val))
|
|
|
|
return $val;
|
|
|
|
|
2024-05-17 12:10:54 +00:00
|
|
|
// If $val is not set, then it may be an unsaved object
|
2024-05-19 13:28:45 +00:00
|
|
|
return sprintf('--- %s',
|
|
|
|
((! $this->exists) && $this->set->has('set_tearline'))
|
|
|
|
? $this->set->get('set_tearline')
|
|
|
|
: $val);
|
2024-05-17 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* METHODS */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an array of flag descriptions
|
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*
|
|
|
|
* http://ftsc.org/docs/fsc-0001.000
|
|
|
|
* AttributeWord bit meaning
|
|
|
|
* --- --------------------
|
|
|
|
* 0 + Private
|
|
|
|
* 1 + s Crash
|
|
|
|
* 2 Recd
|
|
|
|
* 3 Sent
|
|
|
|
* 4 + FileAttached
|
|
|
|
* 5 InTransit
|
|
|
|
* 6 Orphan
|
|
|
|
* 7 KillSent
|
|
|
|
* 8 Local
|
|
|
|
* 9 s HoldForPickup
|
|
|
|
* 10 + unused
|
|
|
|
* 11 s FileRequest
|
|
|
|
* 12 + s ReturnReceiptRequest
|
|
|
|
* 13 + s IsReturnReceipt
|
|
|
|
* 14 + s AuditRequest
|
|
|
|
* 15 s FileUpdateReq
|
|
|
|
*
|
|
|
|
* s - this bit is supported by SEAdog only
|
|
|
|
* + - this bit is not zeroed before packeting
|
|
|
|
*/
|
|
|
|
public function flags(): Collection
|
|
|
|
{
|
|
|
|
return collect([
|
|
|
|
'private' => $this->isFlagSet(Message::FLAG_PRIVATE),
|
|
|
|
'crash' => $this->isFlagSet(Message::FLAG_CRASH),
|
|
|
|
'recd' => $this->isFlagSet(Message::FLAG_RECD),
|
|
|
|
'sent' => $this->isFlagSet(Message::FLAG_SENT),
|
|
|
|
'fileattach' => $this->isFlagSet(Message::FLAG_FILEATTACH),
|
|
|
|
'intransit' => $this->isFlagSet(Message::FLAG_INTRANSIT),
|
|
|
|
'orphan' => $this->isFlagSet(Message::FLAG_ORPHAN),
|
|
|
|
'killsent' => $this->isFlagSet(Message::FLAG_KILLSENT),
|
|
|
|
'local' => $this->isFlagSet(Message::FLAG_LOCAL),
|
|
|
|
'hold' => $this->isFlagSet(Message::FLAG_HOLD),
|
|
|
|
'unused-10' => $this->isFlagSet(Message::FLAG_UNUSED_10),
|
|
|
|
'filereq' => $this->isFlagSet(Message::FLAG_FREQ),
|
|
|
|
'receipt-req' => $this->isFlagSet(Message::FLAG_RETRECEIPT),
|
|
|
|
'receipt' => $this->isFlagSet(Message::FLAG_ISRETRECEIPT),
|
|
|
|
'audit' => $this->isFlagSet(Message::FLAG_AUDITREQ),
|
|
|
|
'fileupdate' => $this->isFlagSet(Message::FLAG_FILEUPDATEREQ),
|
2024-05-19 13:28:45 +00:00
|
|
|
'pktpasswd' => $this->isFlagSet(Message::FLAG_PKTPASSWD),
|
2024-05-17 12:10:54 +00:00
|
|
|
])->filter();
|
|
|
|
}
|
|
|
|
|
2024-05-19 13:28:45 +00:00
|
|
|
public function isFlagSet($flag): bool
|
2024-05-17 12:10:54 +00:00
|
|
|
{
|
|
|
|
return ($this->flags & $flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return this model as a packet
|
|
|
|
*/
|
|
|
|
public function packet(Address $ao): Message
|
|
|
|
{
|
|
|
|
Log::debug(sprintf('%s:+ Bundling [%s]',self::LOGKEY,$this->id),['type'=>get_class($this)]);
|
|
|
|
|
|
|
|
// For netmails, our tftn is the next hop
|
|
|
|
$this->tftn = $ao;
|
|
|
|
|
|
|
|
// @todo Dont bundle mail to nodes that have been disabled, or addresses that have been deleted
|
|
|
|
return Message::packMessage($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return our path in order
|
|
|
|
*
|
|
|
|
* @param string $display
|
|
|
|
* @param int|NULL $start
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function pathorder(string $display='ftn2d',int $start=NULL): Collection
|
|
|
|
{
|
|
|
|
$result = collect();
|
|
|
|
|
|
|
|
if ($x=$this->path->firstWhere('pivot.parent_id',$start)) {
|
|
|
|
$result->push($x->$display);
|
|
|
|
$result->push($this->pathorder($display,$x->pivot->id));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result->flatten()->filter();
|
|
|
|
}
|
|
|
|
}
|