clrghouz/app/Classes/FTN/Process.php

98 lines
2.5 KiB
PHP

<?php
namespace App\Classes\FTN;
use Illuminate\Support\Arr;
/**
* Abstract class to hold the common functions for automatic responding to echomail/netmail messages
*/
abstract class Process
{
private const LOGKEY = 'R--';
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.
*/
public static function format_msg(string $text,array $logo = []): string
{
$msg = utf8_decode(join("\r",static::msg_header()))."\r";
$c = 0;
$offset = 0;
while ($offset < strlen($text)) {
$ll = '';
// Add our logo
if ($c<count($logo)) {
$line = utf8_decode(Arr::get($logo,$c++));
$ll = $line.' ';
}
// Look for a return
$return = strpos($text,"\r",$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."\r";
$offset += strlen($subtext)+1;
}
// In case our text is shorter than the loo
for ($c; $c<count($logo);$c++)
$msg .= utf8_decode(Arr::get($logo,$c))."\r";
$msg .= utf8_decode(join("\r",static::msg_footer()))."\r";
return $msg;
}
/**
* Header added to messages
*
* @return string[]
*/
protected static function msg_header(): array
{
return [
' ÜÜÜ Ü ÜÜÜ ÜÜÜ ÜÜÜ Ü ÜÜÜ ÜÜÜ Ü ÜÜÜ Ü Ü ÜÜÜ',
' Û ß Û ÛÜÛ ÜÜÛ Û ß Ü Û Û ÛÜÛ ÛßÛ Û Û Û Û Üß',
' ÛÜÛ ÛÜÛ ÛÜÜ ÛÜÛ Û Û Û Û ÜÜÛ Û Û ÛÜÛ ÛÜÛ ÛÜÜ',
' FTN Mailer and Tosser',
'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ'
];
}
protected static function msg_footer(): array
{
return [
'ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ'
];
}
}