Start of processing packets - implemented PING Responce to Netmail
This commit is contained in:
84
app/Classes/FTN/Process.php
Normal file
84
app/Classes/FTN/Process.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\FTN;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
abstract class Process
|
||||
{
|
||||
protected const MSG_WIDTH = 79;
|
||||
|
||||
/**
|
||||
* Return TRUE if the process class handled the message.
|
||||
*
|
||||
* @param Message $msg
|
||||
* @return bool
|
||||
*/
|
||||
abstract public static function handle(Message $msg): bool;
|
||||
|
||||
/**
|
||||
* This function will format text to static::MSG_WIDTH, as well as adding the logo.
|
||||
*/
|
||||
protected static function format_msg(string $text): string
|
||||
{
|
||||
$msg = utf8_decode(join("\n",static::msg_header()))."\n";
|
||||
$c = 0;
|
||||
$offset = 0;
|
||||
|
||||
while ($offset < strlen($text)) {
|
||||
$ll = '';
|
||||
|
||||
// Add our logo
|
||||
if ($c<count(static::$logo)) {
|
||||
$line = utf8_decode(Arr::get(static::$logo,$c++));
|
||||
$ll = $line.' ';
|
||||
}
|
||||
|
||||
// Look for a return
|
||||
$return = strpos($text,"\n",$offset);
|
||||
|
||||
if ($return !== FALSE)
|
||||
$return -= $offset;
|
||||
|
||||
if (($return !== FALSE && $return < static::MSG_WIDTH-strlen($ll))) {
|
||||
$subtext = substr($text,$offset,$return);
|
||||
|
||||
} else {
|
||||
$subtext = substr($text,$offset,static::MSG_WIDTH-strlen($ll));
|
||||
|
||||
// Look for a space
|
||||
$space = strrpos($subtext,' ');
|
||||
|
||||
if ($space == FALSE)
|
||||
$space = strlen($subtext);
|
||||
else
|
||||
$subtext = substr($text,$offset,$space);
|
||||
}
|
||||
|
||||
$msg .= $ll.$subtext."\n";
|
||||
$offset += strlen($subtext)+1;
|
||||
}
|
||||
|
||||
// In case our text is shorter than the loo
|
||||
for ($c; $c<count(static::$logo);$c++)
|
||||
$msg .= utf8_decode(Arr::get(static::$logo,$c))."\n";
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Header added to messages
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected static function msg_header(): array
|
||||
{
|
||||
return [
|
||||
' ÜÜÜ Ü ÜÜÜ ÜÜÜ ÜÜÜ Ü ÜÜÜ ÜÜÜ Ü ÜÜÜ Ü Ü ÜÜÜ',
|
||||
' Û ß Û ÛÜÛ ÜÜÛ Û ß Ü Û Û ÛÜÛ ÛßÛ Û Û Û Û Üß',
|
||||
' ÛÜÛ ÛÜÛ ÛÜÜ ÛÜÛ Û Û Û Û ÜÜÛ Û Û ÛÜÛ ÛÜÛ ÛÜÜ',
|
||||
' FTN Mailer and Tosser',
|
||||
'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ'
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user