Some message optimisation, added Echomail processing

This commit is contained in:
Deon George
2021-07-31 00:35:52 +10:00
parent 6f26bc4c71
commit d937547599
15 changed files with 476 additions and 134 deletions

View File

@@ -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;

View File

@@ -157,6 +157,10 @@ class Packet extends FTNBase
$message = '';
}
// If our message is still set, then we have an unprocessed message
if ($message)
$o->parseMessage($message,$domain);
return $o;
}
@@ -300,7 +304,7 @@ class Packet extends FTNBase
*
* @param Message $o
*/
public function addNetmail(Message $o): void
public function addMail(Message $o): void
{
$this->messages->push($o);
}
@@ -354,7 +358,7 @@ class Packet extends FTNBase
Log::error(sprintf('%s:%s Skipping...',self::LOGKEY,join('|',$msg->errors->messages()->get('from'))));
} else {
$this->messages->push(Message::parseMessage($message,$domain));
$this->messages->push($msg);
}
}
}

View File

@@ -28,6 +28,7 @@ final class Ping extends Process
return FALSE;
Log::info(sprintf('Processing PING message from (%s) [%s]',$msg->user_from,$msg->fftn));
$ftns = Setup::findOrFail(config('app.id'))->system->match($msg->fftn_o->zone);
$reply = sprintf("Your ping was received here on %s and it looks like you sent it on %s. If that is correct, then it took %s to get here.\r",
$msg->date->toDateTimeString(),
@@ -45,13 +46,18 @@ final class Ping extends Process
$o->to = $msg->user_from;
$o->from = Setup::PRODUCT_NAME;
$o->subject = 'Ping Reply';
$o->fftn_id = ($x=$msg->tftn_o) ? $x->id : NULL;
$o->tftn_id = ($x=$msg->fftn_o) ? $x->id : NULL;
$o->msg = static::format_msg($reply,self::$logo);
$o->reply = $msg->msgid;
$o->datetime = Carbon::now();
$o->tzoffset = $o->datetime->utcOffset();
$o->reply = $msg->msgid;
$o->fftn_id = $ftns->id;
$o->tftn_id = ($x=$msg->fftn_o) ? $x->id : NULL;
$o->flags = Message::FLAG_LOCAL;
$o->cost = 0;
$o->msg = static::format_msg($reply,self::$logo);
$o->tagline = 'My ping pong opponent was not happy with my serve. He kept returning it.';
$o->tearline = sprintf('--- %s (%s)',Setup::PRODUCT_NAME,(new Setup)->version);
$o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
$o->save();
return TRUE;

View File

@@ -0,0 +1,77 @@
<?php
namespace App\Classes\FTN\Process;
use Carbon\Carbon;
use Carbon\CarbonInterface;
use Illuminate\Support\Facades\Log;
use App\Classes\FTN\{Message,Process};
use App\Models\{Echomail,Setup};
/**
* Process messages to Test
*
* @package App\Classes\FTN\Process
*/
final class Test extends Process
{
private static array $logo = [
'Ú¿ÚÄ¿ÚĿڿ',
' ³ ³ÄÙÀÄ¿ ³ ',
' Á ÀÄÙÀÄÙ Á '
];
private const testing = ['test','testing'];
public static function handle(Message $msg): bool
{
if ((strtolower($msg->user_to) !== 'all') || ! in_array(strtolower($msg->subject),self::testing))
return FALSE;
Log::info(sprintf('Processing TEST message from (%s) [%s]',$msg->user_from,$msg->fftn));
$ftns = Setup::findOrFail(config('app.id'))->system->match($msg->fftn_o->zone);
$reply = sprintf("Your test was received here on %s and it looks like you sent it on %s. If that is correct, then it took %s to get here.\r",
$msg->date->toDateTimeString(),
Carbon::now()->toDateTimeString(),
$msg->date->diffForHumans(['parts'=>3,'syntax'=>CarbonInterface::DIFF_ABSOLUTE])
);
$reply .= "\r";
$reply .= "\r";
$reply .= "------------------------------ BEING MESSAGE ------------------------------\r";
$reply .= sprintf("TO: %s\r",$msg->user_to);
$reply .= sprintf("SUBJECT: %s\r",$msg->subject);
$reply .= $msg->message."\r";
$reply .= "------------------------------ CONTROL LINES ------------------------------\r";
$reply .= sprintf("DATE: %s\r",$msg->date->format('Y-m-d H:i:s'));
$reply .= sprintf("MSGID: %s\r",$msg->msgid);
foreach ($msg->kludge as $k=>$v)
$reply .= sprintf("@%s: %s\n",strtoupper($k),$v);
foreach ($msg->via as $via)
$reply .= sprintf("VIA: %s\n",$via);
$reply .= "------------------------------ END MESSAGE ------------------------------\r";
$o = new Echomail;
$o->to = $msg->user_from;
$o->from = Setup::PRODUCT_NAME;
$o->subject = 'Test Reply';
$o->datetime = Carbon::now();
$o->tzoffset = $o->datetime->utcOffset();
$o->echoarea = $msg->echoarea;
$o->reply = $msg->msgid;
$o->fftn_id = $ftns->id;
$o->flags = Message::FLAG_LOCAL;
$o->msg = static::format_msg($reply,self::$logo);
$o->tagline = 'I ate a clock yesterday, it was very time-consuming.';
$o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
$o->origin = sprintf('%s (%s)',Setup::PRODUCT_NAME,$ftns->ftn4d);
$o->save();
return TRUE;
}
}