clrghouz/app/Traits/MessagePath.php
Deon George b5047c52f0
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 40s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m51s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s
Fix for processing inbound ping netmail messages
2024-05-31 21:57:21 +10:00

55 lines
1.6 KiB
PHP

<?php
/**
* Add show the message detail
*/
namespace App\Traits;
use App\Models\{Echomail,Netmail};
trait MessagePath
{
protected function message_path(Echomail|Netmail $mo): string
{
$reply = "This is your original message:\r\r";
$reply .= "+------------------------------------[ BEGIN MESSAGE ]-+\r";
$reply .= sprintf("TO: %s\r",$mo->to);
$reply .= sprintf("SUBJECT: %s\r",$mo->subject);
$reply .= str_replace("\r---","\r#--",$mo->msg)."\r";
$reply .= "+------------------------------------[ CONTROL LINES ]-+\r";
$reply .= sprintf("DATE: %s\r",$mo->date->format('Y-m-d H:i:s'));
if ($mo->msgid)
$reply .= sprintf("MSGID: %s\r",$mo->msgid);
if ($mo->replyid)
$reply .= sprintf("REPLY: %s\r",$mo->replyid);
foreach ($mo->kludges as $k=>$v)
$reply .= sprintf("%s %s\r",$k,$v);
$reply .= "+---------------------------------------------[ PATH ]-+\r";
if ($mo->path->count())
if ($mo instanceof Netmail) {
// Incoming processed message havent converted the path into a collection of addresses yet
foreach ($mo->path as $o)
$reply .= sprintf("VIA: %s\r",(is_string($o) ? $o : $mo->via($o)));
} elseif ($mo instanceof Echomail) {
// Rejected echomails dont have a collection of Address::class for paths
foreach ($mo->path as $o)
$reply .= sprintf("VIA: %s\r",(is_string($o) ? $o : $o->ftn));
} else {
throw new \Exception('Message object is not an Netmail or Echomail?');
}
else
$reply .= "No path information? This would be normal if this message came directly to the hub\r";
$reply .= "+--------------------------------------[ END MESSAGE ]-+\r\r";
return $reply;
}
}