Work with netmail creation
This commit is contained in:
@@ -6,8 +6,9 @@ use App\Exceptions\InvalidFidoPacketException;
|
||||
|
||||
class FTNMessage extends FTN
|
||||
{
|
||||
private $src = NULL;
|
||||
private $dst = NULL;
|
||||
private $_src = NULL;
|
||||
private $_dst = NULL;
|
||||
|
||||
private $flags = NULL;
|
||||
private $cost = 0;
|
||||
|
||||
@@ -42,7 +43,36 @@ class FTNMessage extends FTN
|
||||
'tid' => 'TID: ',
|
||||
];
|
||||
|
||||
public function __construct(string $header)
|
||||
// Flags for messages
|
||||
const FLAG_PRIVATE = 0b1;
|
||||
const FLAG_CRASH = 0b10;
|
||||
const FLAG_RECD = 0b100;
|
||||
const FLAG_SENT = 0b1000;
|
||||
const FLAG_FILEATTACH = 0b10000;
|
||||
const FLAG_INTRANSIT = 0b100000;
|
||||
const FLAG_ORPHAN = 0b1000000;
|
||||
const FLAG_KILLSENT = 0b10000000;
|
||||
const FLAG_LOCAL = 0b100000000;
|
||||
const FLAG_HOLD = 0b1000000000;
|
||||
const FLAG_UNUSED_10 = 0b10000000000;
|
||||
const FLAG_FREQ = 0b100000000000;
|
||||
const FLAG_RETRECEIPT = 0b1000000000000;
|
||||
const FLAG_ISRETRECEIPT = 0b10000000000000;
|
||||
const FLAG_AUDITREQ = 0b100000000000000;
|
||||
const FLAG_FILEUPDATEREQ = 0b1000000000000000;
|
||||
|
||||
// FTS-0001.016 Message header 12 bytes
|
||||
// node, net, flags, cost
|
||||
private $struct = [
|
||||
'onode'=>[0x00,'v',2],
|
||||
'dnode'=>[0x02,'v',2],
|
||||
'onet'=>[0x04,'v',2],
|
||||
'dnet'=>[0x06,'v',2],
|
||||
'flags'=>[0x08,'v',2],
|
||||
'cost'=>[0x0a,'v',2],
|
||||
];
|
||||
|
||||
public function __construct(string $header=NULL)
|
||||
{
|
||||
// Initialise vars
|
||||
$this->kludge = collect(); // The message kludge lines
|
||||
@@ -52,39 +82,8 @@ class FTNMessage extends FTN
|
||||
$this->_other = collect(); // Temporarily hold attributes we dont process yet.
|
||||
$this->unknown = collect(); // Temporarily hold attributes we have no logic for.
|
||||
|
||||
// FTS-0001.016 Message header 12 bytes
|
||||
// node, net, flags, cost
|
||||
$struct = [
|
||||
'onode'=>[0x00,'v',2],
|
||||
'dnode'=>[0x02,'v',2],
|
||||
'onet'=>[0x04,'v',2],
|
||||
'dnet'=>[0x06,'v',2],
|
||||
'flags'=>[0x08,'v',2],
|
||||
'cost'=>[0x0a,'v',2],
|
||||
];
|
||||
|
||||
$result = unpack($this->unpackheader($struct),$header);
|
||||
|
||||
// For Echomail this is the packet src.
|
||||
$this->psn = array_get($result,'onet');
|
||||
$this->psf = array_get($result,'onode');
|
||||
|
||||
$this->src = sprintf('%s/%s',
|
||||
$this->psn,
|
||||
$this->psf
|
||||
);
|
||||
|
||||
// For Echomail this is the packet dst.
|
||||
$this->pdn = array_get($result,'dnet');
|
||||
$this->pdf = array_get($result,'dnode');
|
||||
|
||||
$this->dst = sprintf('%s/%s',
|
||||
$this->pdn,
|
||||
$this->pdf
|
||||
);
|
||||
|
||||
$this->flags = array_get($result,'flags');
|
||||
$this->cost = array_get($result,'cost');
|
||||
if ($header)
|
||||
$this->parseheader($header);
|
||||
}
|
||||
|
||||
public function __get($k)
|
||||
@@ -110,44 +109,138 @@ class FTNMessage extends FTN
|
||||
{
|
||||
switch ($k)
|
||||
{
|
||||
case 'message':
|
||||
// Remove DOS \n\r
|
||||
$v = preg_replace("/\n\r/","\r",$v);
|
||||
case 'fqfa':
|
||||
case 'fqda':
|
||||
$this->{$k} = $v;
|
||||
|
||||
$this->parsemessage($v);
|
||||
break;
|
||||
|
||||
case 'origin':
|
||||
$this->parseorigin($v);
|
||||
break;
|
||||
if ($this->fqfa AND $this->fqda)
|
||||
$this->intl = sprintf('%s %s',$this->fqda,$this->fqfa);
|
||||
|
||||
default:
|
||||
$this->{$k} = $v;
|
||||
}
|
||||
}
|
||||
|
||||
private function znfp(string $data,string $key)
|
||||
/**
|
||||
* Export an FTN message, ready for sending.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
switch ($key) {
|
||||
case 'z':
|
||||
return substr($data,0,strpos($data,':'));
|
||||
case 'n':
|
||||
$x = strpos($data,':')+1;
|
||||
return substr($data,$x,strpos($data,'/')-$x);
|
||||
case 'f':
|
||||
$x = strpos($data,'/')+1;
|
||||
return substr($data,$x,strpos($data,'.') ?: strlen($data)-$x);
|
||||
case 'p':
|
||||
$x = strpos($data,'.');
|
||||
return $x ? substr($data,$x+1) : 0;
|
||||
$return = '';
|
||||
|
||||
$return .= pack(join('',collect($this->struct)->pluck(1)->toArray()),
|
||||
$this->ff,
|
||||
$this->tf,
|
||||
$this->fn,
|
||||
$this->tn,
|
||||
$this->flags,
|
||||
0 // @todo cost
|
||||
);
|
||||
|
||||
// @todo use pack for this.
|
||||
$return .= $this->date->format('d M y H:i:s')."\00";
|
||||
$return .= $this->to."\00";
|
||||
$return .= $this->from."\00";
|
||||
$return .= $this->subject."\00";
|
||||
$return .= $this->message."\00";
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function description()
|
||||
{
|
||||
switch ($this->type())
|
||||
{
|
||||
case 'echomail': return sprintf('Echomail: '.$this->echoarea);
|
||||
case 'netmail': return sprintf('Netmail: %s->%s',$this->fqfa,$this->fqda);
|
||||
default:
|
||||
abort(500,'Unknown key: '.$key);
|
||||
return 'UNKNOWN';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of flag descriptions
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* 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(int $flags): array
|
||||
{
|
||||
return [
|
||||
'private'=>$this->isFlagSet($flags,self::FLAG_PRIVATE),
|
||||
'crash'=>$this->isFlagSet($flags,self::FLAG_CRASH),
|
||||
'recd'=>$this->isFlagSet($flags,self::FLAG_RECD),
|
||||
'sent'=>$this->isFlagSet($flags,self::FLAG_SENT),
|
||||
'killsent'=>$this->isFlagSet($flags,self::FLAG_KILLSENT),
|
||||
'local'=>$this->isFlagSet($flags,self::FLAG_LOCAL),
|
||||
];
|
||||
}
|
||||
|
||||
private function isFlagSet($value,$flag)
|
||||
{
|
||||
return (($value & $flag) == $flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the head of an FTN message
|
||||
*
|
||||
* @param string $header
|
||||
*/
|
||||
public function parseheader(string $header)
|
||||
{
|
||||
$result = unpack($this->unpackheader($this->struct),$header);
|
||||
|
||||
// For Echomail this is the packet src.
|
||||
$this->psn = array_get($result,'onet');
|
||||
$this->psf = array_get($result,'onode');
|
||||
|
||||
$this->_src = sprintf('%s/%s',
|
||||
$this->psn,
|
||||
$this->psf
|
||||
);
|
||||
|
||||
// For Echomail this is the packet dst.
|
||||
$this->pdn = array_get($result,'dnet');
|
||||
$this->pdf = array_get($result,'dnode');
|
||||
|
||||
$this->_dst = sprintf('%s/%s',
|
||||
$this->pdn,
|
||||
$this->pdf
|
||||
);
|
||||
|
||||
$this->flags = array_get($result,'flags');
|
||||
$this->cost = array_get($result,'cost');
|
||||
}
|
||||
|
||||
public function parsemessage(string $message)
|
||||
{
|
||||
// Remove DOS \n\r
|
||||
$message = preg_replace("/\n\r/","\r",$message);
|
||||
|
||||
// Split out the <SOH> lines
|
||||
$result = collect(explode("\01",$message))->filter();
|
||||
|
||||
@@ -165,7 +258,7 @@ class FTNMessage extends FTN
|
||||
if ($y = strpos($v,"\r * Origin: "))
|
||||
{
|
||||
$this->message .= substr($v,$x+1,$y-$x-1);
|
||||
$this->__set('origin',substr($v,$y));
|
||||
$this->parseorigin(substr($v,$y));
|
||||
$matches = [];
|
||||
|
||||
preg_match('/^.*\((.*)\)$/',$this->origin,$matches);
|
||||
@@ -245,7 +338,7 @@ class FTNMessage extends FTN
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public function parseorigin(string $message)
|
||||
private function parseorigin(string $message)
|
||||
{
|
||||
// Split out each line
|
||||
$result = collect(explode("\r",$message))->filter();
|
||||
@@ -277,17 +370,6 @@ class FTNMessage extends FTN
|
||||
}
|
||||
}
|
||||
|
||||
public function description()
|
||||
{
|
||||
switch ($this->type())
|
||||
{
|
||||
case 'echomail': return sprintf('Echomail: '.$this->echoarea);
|
||||
case 'netmail': return sprintf('Netmail: %s->%s',$this->fqfa,$this->fqda);
|
||||
default:
|
||||
return 'UNKNOWN';
|
||||
}
|
||||
}
|
||||
|
||||
public function type()
|
||||
{
|
||||
if ($this->echoarea)
|
||||
@@ -298,4 +380,24 @@ class FTNMessage extends FTN
|
||||
|
||||
return 'UNKNOWN';
|
||||
}
|
||||
|
||||
private function znfp(string $data,string $key)
|
||||
{
|
||||
switch ($key) {
|
||||
case 'z':
|
||||
return substr($data,0,strpos($data,':'));
|
||||
case 'n':
|
||||
$x = strpos($data,':')+1;
|
||||
return substr($data,$x,strpos($data,'/')-$x);
|
||||
case 'f':
|
||||
$x = strpos($data,'/')+1;
|
||||
return substr($data,$x,strpos($data,'.') ?: strlen($data)-$x);
|
||||
case 'p':
|
||||
$x = strpos($data,'.');
|
||||
return $x ? substr($data,$x+1) : 0;
|
||||
|
||||
default:
|
||||
abort(500,'Unknown key: '.$key);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user