Enable netmail forwarding for users that receive messages directed at clrghouz

This commit is contained in:
2023-08-02 22:42:59 +10:00
parent b6082b6ae5
commit f281575b15
8 changed files with 243 additions and 40 deletions

View File

@@ -12,8 +12,8 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use App\Classes\FTN\Message;
use App\Models\{Address,Echoarea,Echomail,Netmail,Setup};
use App\Notifications\Netmails\{EchoareaNotExist,EchoareaNotSubscribed,EchoareaNoWrite,Reject};
use App\Models\{Address,Echoarea,Echomail,Netmail,Setup,User};
use App\Notifications\Netmails\{EchoareaNotExist,EchoareaNotSubscribed,EchoareaNoWrite,NetmailForward,Reject};
class MessageProcess implements ShouldQueue
{
@@ -124,7 +124,7 @@ class MessageProcess implements ShouldQueue
// If the message is to a bot, we'll process it
if (! $this->skipbot)
foreach (config('process.robots') as $class) {
if ($processed = $class::handle($this->msg)) {
if ($processed=$class::handle($this->msg)) {
$o->flags |= Message::FLAG_RECD;
$o->save();
@@ -139,20 +139,46 @@ class MessageProcess implements ShouldQueue
}
}
// We'll ignore messages from *fix users
if (in_array(strtolower($this->msg->user_from),['filefix','areafix'])) {
$o->flags |= Message::FLAG_RECD;
$o->save();
if (! $processed) {
// Check if the netmail is to a user, with netmail forwarding enabled
$uo = User::active()
->where(function($query) {
return $query->whereRaw(sprintf("LOWER(name)='%s'",strtolower($this->msg->user_to)))
->orWhereRaw(sprintf("LOWER(alias)='%s'",strtolower($this->msg->user_to)));
})
->whereNotNull('system_id')
->single();
Log::alert(sprintf('%s:! Ignoring Netmail [%s] to the Hub from (%s:%s) - its from a bot [%d]',
self::LOGKEY,
$this->msg->msgid,
$this->msg->user_from,
$this->msg->fftn,
$o->id,
));
if ($uo && ($ao=$uo->system->match($this->msg->tftn_o->zone)?->pop())) {
$note = "+--[ FORWARDED MESSAGE ]----------------------------------+\r";
$note .= "+ This message has been forwarded to you, it was originally sent to you\r";
$note .= sprintf("+ at [%s]\r",$this->msg->tftn_o->ftn);
$note .= "+---------------------------------------------------------+\r\r";
$o->msg = $note.$this->msg->message;
$o->tftn_id = $ao->id;
$o->flags |= Message::FLAG_INTRANSIT;
$o->save();
$processed = TRUE;
$processed = TRUE;
// Dont send an advisement to an areabot
if (! in_array(strtolower($this->msg->user_from),config('app.areabots')))
Notification::route('netmail',$this->msg->fftn_o)->notify(new NetmailForward($this->msg,$ao));
// We'll ignore messages from *fix users
} elseif (in_array(strtolower($this->msg->user_from),config('app.areabots'))) {
$o->flags |= Message::FLAG_RECD;
$o->save();
Log::alert(sprintf('%s:! Ignoring Netmail [%s] to the Hub from (%s:%s) - its from a bot [%d]',
self::LOGKEY,
$this->msg->msgid,
$this->msg->user_from,
$this->msg->fftn,
$o->id,
));
$processed = TRUE;
}
}
// If not processed, no users here!