Initial netmail import

This commit is contained in:
Deon George
2019-05-06 22:29:29 +10:00
parent 9ba790e72c
commit 188fd1a2cf
9 changed files with 344 additions and 71 deletions

View File

@@ -31,7 +31,7 @@ class FTNMessage extends FTN
private $unknown = [];
private $fqfa = NULL; // Fully qualified fidonet source where packet originated
private $fqfd = NULL; // Fully qualified fidonet destination address (Netmail)
private $fqda = NULL; // Fully qualified fidonet destination address (Netmail)
// Single value kludge items
private $_kludge = [
@@ -65,28 +65,45 @@ class FTNMessage extends FTN
$result = unpack($this->unpackheader($struct),$header);
$this->fn = array_get($result,'onet');
$this->ff = array_get($result,'onode');
// 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->fn,
$this->ff
$this->psn,
$this->psf
);
$this->tn = array_get($result,'dnet');
$this->tf = array_get($result,'dnode');
// 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->tn,
$this->tf
$this->pdn,
$this->pdf
);
$this->flags = array_get($result,'flags');
$this->cost = array_get($result,'cost');
}
public function __get($k)
{
return isset($this->{$k}) ? $this->{$k} : NULL;
switch ($k)
{
case 'fz': return $this->znfp($this->fqfa,'z');
case 'fn': return $this->znfp($this->fqfa,'n');
case 'ff': return $this->znfp($this->fqfa,'f');
case 'fp': return $this->znfp($this->fqfa,'p');
case 'tz': return $this->znfp($this->fqda,'z');
case 'tn': return $this->znfp($this->fqda,'n');
case 'tf': return $this->znfp($this->fqda,'f');
case 'tp': return $this->znfp($this->fqda,'p');
default:
return isset($this->{$k}) ? $this->{$k} : NULL;
}
}
public function __set($k,$v)
@@ -109,6 +126,26 @@ class FTNMessage extends FTN
}
}
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);
}
}
public function parsemessage(string $message)
{
// Split out the <SOH> lines
@@ -169,7 +206,7 @@ class FTNMessage extends FTN
elseif ($t = $this->kludge('INTL ',$v))
{
$this->intl = $t;
list($this->fqfd,$this->fqfa) = explode(' ',$t);
list($this->fqda,$this->fqfa) = explode(' ',$t);
}
elseif ($t = $this->kludge('MSGID: ',$v))
@@ -244,8 +281,8 @@ class FTNMessage extends FTN
{
switch ($this->type())
{
case 'Echomail': return sprintf('Echomail: '.$this->echoarea);
case 'Netmail': return sprintf('Netmail: %s->%s',$this->fqfa,$this->fqfd);
case 'echomail': return sprintf('Echomail: '.$this->echoarea);
case 'netmail': return sprintf('Netmail: %s->%s',$this->fqfa,$this->fqda);
default:
return 'UNKNOWN';
}
@@ -254,10 +291,10 @@ class FTNMessage extends FTN
public function type()
{
if ($this->echoarea)
return 'Echomail';
return 'echomail';
if ($this->intl)
return 'Netmail';
return 'netmail';
return 'UNKNOWN';
}