2019-05-06 12:29:29 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
use Carbon\Carbon;
|
2021-08-15 09:25:04 +00:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2021-07-15 14:54:23 +00:00
|
|
|
use Jenssegers\Mongodb\Eloquent\Model;
|
|
|
|
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
|
|
|
|
|
|
|
|
use App\Classes\FTN\Message;
|
2021-07-30 14:35:52 +00:00
|
|
|
use App\Interfaces\Packet;
|
|
|
|
use App\Traits\UseMongo;
|
2019-05-06 12:29:29 +00:00
|
|
|
|
2021-08-15 09:25:04 +00:00
|
|
|
final class Netmail extends Model implements Packet
|
2019-05-06 12:29:29 +00:00
|
|
|
{
|
2021-08-15 09:25:04 +00:00
|
|
|
private const LOGKEY = 'MN-';
|
|
|
|
|
2021-07-30 14:35:52 +00:00
|
|
|
use SoftDeletes,UseMongo;
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2021-07-18 12:10:21 +00:00
|
|
|
protected $dates = ['datetime','sent_at'];
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
/* RELATIONS */
|
2019-05-06 12:29:29 +00:00
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
public function fftn()
|
2019-05-06 12:29:29 +00:00
|
|
|
{
|
2021-07-15 14:54:23 +00:00
|
|
|
return $this
|
|
|
|
->setConnection('pgsql')
|
2021-07-17 05:48:07 +00:00
|
|
|
->belongsTo(Address::class)
|
|
|
|
->withTrashed();
|
2019-05-06 12:29:29 +00:00
|
|
|
}
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
public function tftn()
|
2019-05-06 12:29:29 +00:00
|
|
|
{
|
2021-07-15 14:54:23 +00:00
|
|
|
return $this
|
|
|
|
->setConnection('pgsql')
|
|
|
|
->belongsTo(Address::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* METHODS */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return this model as a packet
|
|
|
|
*/
|
2021-07-30 14:35:52 +00:00
|
|
|
public function packet(Address $ao): Message
|
2021-07-15 14:54:23 +00:00
|
|
|
{
|
2021-08-15 09:25:04 +00:00
|
|
|
Log::debug(sprintf('%s:Bundling [%s]',self::LOGKEY,$this->id));
|
|
|
|
|
2021-07-17 05:48:07 +00:00
|
|
|
// @todo Dont bundle mail to nodes that have been disabled, or addresses that have been deleted
|
2021-07-30 14:35:52 +00:00
|
|
|
$o = new Message;
|
2021-07-17 05:48:07 +00:00
|
|
|
|
2021-08-15 09:25:04 +00:00
|
|
|
try {
|
|
|
|
$o->header = [
|
|
|
|
'onode' => $this->fftn->node_id,
|
|
|
|
'dnode' => $ao->node_id,
|
|
|
|
'onet' => $this->fftn->host_id,
|
|
|
|
'dnet' => $ao->host_id,
|
|
|
|
'flags' => 0, // @todo?
|
|
|
|
'cost' => 0,
|
|
|
|
'date'=>$this->datetime->format('d M y H:i:s'),
|
|
|
|
];
|
|
|
|
|
|
|
|
$o->tzutc = $this->datetime->utcOffset($this->tzoffset)->getOffsetString('');
|
|
|
|
$o->user_to = $this->to;
|
|
|
|
$o->user_from = $this->from;
|
|
|
|
$o->subject = $this->subject;
|
|
|
|
|
|
|
|
// INTL kludge
|
|
|
|
// @todo Point handling FMPT/TOPT
|
|
|
|
$o->intl = sprintf('%s %s',$this->tftn->ftn3d,$this->fftn->ftn3d);
|
|
|
|
$o->flags = $this->flags;
|
|
|
|
|
|
|
|
$o->msgid = sprintf('%s %08x',$this->fftn->ftn3d,crc32($this->id));
|
|
|
|
if ($this->reply)
|
|
|
|
$o->reply = $this->reply;
|
|
|
|
|
|
|
|
$o->message = $this->msg;
|
|
|
|
|
|
|
|
if ($this->tagline)
|
2021-08-19 06:59:12 +00:00
|
|
|
$o->message .= '...'.$this->tagline;
|
2021-08-15 09:25:04 +00:00
|
|
|
|
|
|
|
if ($this->tearline)
|
2021-08-19 06:59:12 +00:00
|
|
|
$o->tearline .= '---'.$this->tearline;
|
2021-08-15 09:25:04 +00:00
|
|
|
|
|
|
|
// VIA kludge
|
|
|
|
$via = $this->via ?: collect();
|
|
|
|
$via->push(
|
|
|
|
sprintf('%s @%s.UTC %s %d.%d/%s %s',
|
|
|
|
$this->fftn->ftn3d,
|
|
|
|
Carbon::now()->utc()->format('Ymd.His'),
|
|
|
|
Setup::PRODUCT_NAME,
|
|
|
|
Setup::PRODUCT_VERSION_MAJ,
|
|
|
|
Setup::PRODUCT_VERSION_MIN,
|
|
|
|
(new Setup)->version,
|
|
|
|
Carbon::now()->format('Y-m-d'),
|
|
|
|
));
|
|
|
|
|
|
|
|
$o->via = $via;
|
|
|
|
|
2021-08-16 12:30:34 +00:00
|
|
|
$o->packed = TRUE;
|
|
|
|
|
2021-08-15 09:25:04 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error(sprintf('%s:Error converting netmail [%s] to a message (%d:%s)',self::LOGKEY,$this->id,$e->getLine(),$e->getMessage()));
|
|
|
|
dump($this);
|
|
|
|
}
|
2021-07-15 14:54:23 +00:00
|
|
|
|
|
|
|
return $o;
|
2019-05-06 12:29:29 +00:00
|
|
|
}
|
|
|
|
}
|