Some message optimisation, added Echomail processing
This commit is contained in:
@@ -23,6 +23,7 @@ class Message extends FTNBase
|
||||
{
|
||||
private const cast_utf8 = [
|
||||
'message',
|
||||
'message_src',
|
||||
];
|
||||
|
||||
// Single value kludge items
|
||||
@@ -30,10 +31,10 @@ class Message extends FTNBase
|
||||
'chrs' => 'CHRS: ',
|
||||
'charset' => 'CHARSET: ',
|
||||
'codepage' => 'CODEPAGE: ',
|
||||
'mid' => 'MID: ',
|
||||
'pid' => 'PID: ',
|
||||
'replyid' => 'REPLY: ',
|
||||
'tid' => 'TID: ',
|
||||
'tzutc' => 'TZUTC: ',
|
||||
];
|
||||
|
||||
// Flags for messages
|
||||
@@ -72,20 +73,29 @@ class Message extends FTNBase
|
||||
private const SUBJECT_LEN = 71; // FTS-0001.016 Subject: upto 72 chars null terminated
|
||||
private const AREATAG_LEN = 35; //
|
||||
|
||||
private ?ValidatorResult $errors = NULL; // Packet validation
|
||||
private ?ValidatorResult $errors; // Packet validation
|
||||
private array $header; // Message Header
|
||||
private Collection $kludge; // Hold kludge items
|
||||
|
||||
private string $user_from; // User message is From
|
||||
private string $user_to; // User message is To
|
||||
private string $subject; // Message subject
|
||||
|
||||
private string $msgid; // MSG ID
|
||||
private string $reply; // Reply ID
|
||||
|
||||
private string $echoarea; // FTS-0004.001
|
||||
private string $intl; // Netmail details
|
||||
private string $message; // The actual message content
|
||||
|
||||
private string $message; // The parsed message content
|
||||
private string $message_src; // The actual message part
|
||||
|
||||
private string $tagline;
|
||||
private string $tearline;
|
||||
private string $origin; // FTS-0004.001
|
||||
|
||||
private int $tzutc;
|
||||
|
||||
private array $zone; // Zone the message belongs to. (src/dst - for netmail)
|
||||
private array $point; // Point the message belongs to (Netmail)
|
||||
|
||||
@@ -145,17 +155,26 @@ class Message extends FTNBase
|
||||
$this->domain = $domain;
|
||||
|
||||
$this->kludge = collect();
|
||||
|
||||
$this->msgid = '';
|
||||
$this->reply = '';
|
||||
|
||||
$this->echoarea = '';
|
||||
$this->intl = '';
|
||||
|
||||
$this->tearline = '';
|
||||
$this->tagline = '';
|
||||
$this->origin = '';
|
||||
|
||||
$this->tzutc = 0;
|
||||
|
||||
$this->zone = [];
|
||||
$this->point = [];
|
||||
|
||||
$this->path = collect();
|
||||
$this->seenby = collect();
|
||||
$this->via = collect();
|
||||
$this->unknown = collect();
|
||||
$this->zone = [];
|
||||
$this->point = [];
|
||||
$this->tearline = '';
|
||||
$this->origin = '';
|
||||
$this->msgid = '';
|
||||
$this->echoarea = '';
|
||||
$this->intl = '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,25 +268,35 @@ class Message extends FTNBase
|
||||
|
||||
case 'date':
|
||||
return Carbon::createFromFormat('d M y H:i:s O',
|
||||
sprintf('%s %s',chop(Arr::get($this->header,$key)),(! is_null($x=$this->kludge->get('tzutc')) && ($x < 0)) ? $x : '+'.($x ?: '0000')));
|
||||
sprintf('%s %s%04d',chop(Arr::get($this->header,$key)),($this->tzutc < 0) ? '-' : '+',abs($this->tzutc)));
|
||||
|
||||
case 'flags':
|
||||
case 'cost':
|
||||
return Arr::get($this->header,$key);
|
||||
|
||||
case 'message':
|
||||
case 'tearline':
|
||||
case 'origin':
|
||||
case 'subject':
|
||||
case 'tzutc':
|
||||
|
||||
case 'user_to':
|
||||
case 'user_from':
|
||||
case 'subject':
|
||||
case 'echoarea':
|
||||
|
||||
case 'msgid':
|
||||
case 'reply':
|
||||
|
||||
case 'message':
|
||||
case 'message_src':
|
||||
|
||||
case 'tearline':
|
||||
case 'tagline':
|
||||
case 'origin':
|
||||
|
||||
case 'kludge':
|
||||
case 'path':
|
||||
case 'seenby':
|
||||
case 'via':
|
||||
case 'msgid':
|
||||
|
||||
case 'errors':
|
||||
case 'echoarea':
|
||||
return $this->{$key};
|
||||
|
||||
default:
|
||||
@@ -278,16 +307,25 @@ class Message extends FTNBase
|
||||
public function __set($key,$value)
|
||||
{
|
||||
switch ($key) {
|
||||
case 'echoarea':
|
||||
case 'flags':
|
||||
case 'header':
|
||||
case 'intl':
|
||||
case 'message':
|
||||
case 'tearline':
|
||||
case 'origin':
|
||||
case 'msgid':
|
||||
case 'subject':
|
||||
case 'tzutc':
|
||||
|
||||
case 'user_from':
|
||||
case 'user_to':
|
||||
case 'subject':
|
||||
|
||||
case 'msgid':
|
||||
case 'reply':
|
||||
|
||||
case 'echoarea':
|
||||
case 'intl':
|
||||
|
||||
case 'message':
|
||||
|
||||
case 'tagline':
|
||||
case 'tearline':
|
||||
case 'origin':
|
||||
case 'via':
|
||||
$this->{$key} = $value;
|
||||
break;
|
||||
@@ -403,28 +441,46 @@ class Message extends FTNBase
|
||||
$return .= $this->user_from."\00";
|
||||
$return .= $this->subject."\00";
|
||||
|
||||
if ($this->isNetmail())
|
||||
$return .= sprintf("\01INTL %s\r",$this->intl);
|
||||
else
|
||||
$return .= "AREA:".$this->echoarea."\r";
|
||||
if (! $this->isNetmail())
|
||||
$return .= sprintf("AREA:%s\r",$this->echoarea);
|
||||
|
||||
// Add some kludges
|
||||
$return .= sprintf("\01MSGID: %s\r",$this->msgid);
|
||||
// If the message is local, then our kludges are not in the msg itself, we'll add them
|
||||
if ($this->isFlagSet(self::FLAG_LOCAL)) {
|
||||
if ($this->isNetmail())
|
||||
$return .= sprintf("\01INTL %s\r",$this->intl);
|
||||
|
||||
foreach ($this->_kludge as $k=>$v) {
|
||||
if ($x=$this->kludge->get($k))
|
||||
$return .= sprintf("\01%s%s\r",$v,$x);
|
||||
$return .= sprintf("\01TZUTC: %s\r",str_replace('+','',$this->date->getOffsetString('')));
|
||||
|
||||
// Add some kludges
|
||||
$return .= sprintf("\01MSGID: %s\r",$this->msgid);
|
||||
|
||||
if ($this->reply)
|
||||
$return .= sprintf("\01REPLY: %s\r",$this->reply);
|
||||
|
||||
foreach ($this->_kludge as $k=>$v) {
|
||||
if ($x=$this->kludge->get($k))
|
||||
$return .= sprintf("\01%s%s\r",$v,$x);
|
||||
}
|
||||
|
||||
$return .= $this->message."\r";
|
||||
if ($this->tagline)
|
||||
$return .= sprintf("... %s\r",$this->tagline);
|
||||
if ($this->tearline)
|
||||
$return .= sprintf("--- %s\r",$this->tearline);
|
||||
if ($this->origin)
|
||||
$return .= sprintf(" * Origin: %s\r",$this->origin);
|
||||
|
||||
} else {
|
||||
dump([__METHOD__=>'NOT LOCAL']);
|
||||
$return .= $this->message."\r";
|
||||
}
|
||||
|
||||
$return .= $this->message."\r";
|
||||
if ($this->tearline)
|
||||
$return .= $this->tearline."\r";
|
||||
if ($this->origin)
|
||||
$return .= $this->origin."\r";
|
||||
|
||||
if ($this->isNetmail()) {
|
||||
foreach ($this->via as $v)
|
||||
$return .= sprintf("\01Via %s\r",$v);
|
||||
|
||||
} else {
|
||||
// @todo Add echomail SEEN-BY and PATH
|
||||
}
|
||||
|
||||
$return .= "\00";
|
||||
@@ -543,14 +599,17 @@ class Message extends FTNBase
|
||||
$message = preg_replace("/\n\r/","\r",$message);
|
||||
|
||||
// Split out the <SOH> lines
|
||||
$result = collect(explode("\01",$message))->filter();
|
||||
$result = collect(explode("\x01",$message))->filter();
|
||||
|
||||
$this->message = '';
|
||||
$this->message_src = '';
|
||||
$srcpos = 0;
|
||||
|
||||
foreach ($result as $v) {
|
||||
// Search for \r - if that is the end of the line, then its a kludge
|
||||
$x = strpos($v,"\r");
|
||||
$t = '';
|
||||
$srcpos += 1+$x+1; // SOH+text+\r
|
||||
|
||||
// If there are more characters, then put the kludge back into the result, so that we process it.
|
||||
if ($x != strlen($v)-1) {
|
||||
@@ -559,6 +618,10 @@ class Message extends FTNBase
|
||||
$this->message .= substr($v,$x+1,$y-$x-1);
|
||||
$this->parseOrigin(substr($v,$y));
|
||||
|
||||
// Capture the raw message, in case we send it on
|
||||
// length = src, remove current 1+$x+1, add soh, $y + origin_start + origin_length + 0d
|
||||
$this->message_src .= substr($message,0,$srcpos-(1+$x+1)+1+$y+12+strlen($this->origin)+1);
|
||||
|
||||
// If this is netmail, the FQFA will have been set by the INTL line, we can skip the rest of this
|
||||
$matches = [];
|
||||
|
||||
@@ -573,8 +636,9 @@ class Message extends FTNBase
|
||||
$ftn = Address::parseFTN($matches[1]);
|
||||
|
||||
// We'll double check our FTN
|
||||
if (($ftn['n'] !== $this->fn) || ($ftn['f'] !== $this->ff))
|
||||
Log::error(sprintf('FTN [%s] doesnt match message header',$matches[1]),['ftn'=>$ftn]);
|
||||
if ($this->isNetmail() && ($ftn['n'] !== $this->fn) || ($ftn['f'] !== $this->ff)) {
|
||||
Log::error(sprintf('FTN [%s] doesnt match message header',$matches[1]),['ftn'=>$ftn,'fn'=>$this->fn,'ff'=>$this->ff]);
|
||||
}
|
||||
|
||||
// http://ftsc.org/docs/fsc-0068.001
|
||||
// MSGID should be the basis of the source
|
||||
@@ -584,6 +648,7 @@ class Message extends FTNBase
|
||||
// The message is the rest?
|
||||
} elseif (strlen($v) > $x+1) {
|
||||
$this->message .= substr($v,$x+1);
|
||||
$this->message_src .= substr($v,$x+1);
|
||||
}
|
||||
|
||||
$v = substr($v,0,$x+1);
|
||||
@@ -636,6 +701,9 @@ class Message extends FTNBase
|
||||
}
|
||||
}
|
||||
|
||||
elseif ($t = $this->kludge('TZUTC: ',$v))
|
||||
$this->tzutc = $t;
|
||||
|
||||
elseif ($t = $this->kludge('MSGID: ',$v))
|
||||
$this->msgid = $t;
|
||||
|
||||
|
Reference in New Issue
Block a user