Some message optimisation, added Echomail processing
This commit is contained in:
@@ -7,26 +7,15 @@ use Jenssegers\Mongodb\Eloquent\Model;
|
||||
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
|
||||
|
||||
use App\Classes\FTN\Message;
|
||||
use App\Interfaces\Packet;
|
||||
use App\Traits\UseMongo;
|
||||
|
||||
class Netmail extends Model
|
||||
class Netmail extends Model implements Packet
|
||||
{
|
||||
use SoftDeletes;
|
||||
use SoftDeletes,UseMongo;
|
||||
|
||||
//protected $connection = 'mongodb';
|
||||
protected $dates = ['datetime','sent_at'];
|
||||
|
||||
/**
|
||||
* Resolve a connection instance.
|
||||
* We need to do this, because our relations are in pgsql and somehow loading a relation changes this models
|
||||
* connection information. Using protected $connection is not enough.
|
||||
*
|
||||
* @param string|null $connection
|
||||
*/
|
||||
public static function resolveConnection($connection = null)
|
||||
{
|
||||
return static::$resolver->connection('mongodb');
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function fftn()
|
||||
@@ -44,49 +33,47 @@ class Netmail extends Model
|
||||
->belongsTo(Address::class);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getMsgAttribute($value): string
|
||||
{
|
||||
return utf8_decode($value);
|
||||
}
|
||||
|
||||
public function setMsgAttribute($value): void
|
||||
{
|
||||
$this->attributes['msg'] = utf8_encode($value);
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
/**
|
||||
* Return this model as a packet
|
||||
*/
|
||||
public function packet(): Message
|
||||
public function packet(Address $ao): Message
|
||||
{
|
||||
$o = new Message;
|
||||
|
||||
// @todo Dont bundle mail to nodes that have been disabled, or addresses that have been deleted
|
||||
$o = new Message;
|
||||
|
||||
$o->header = [
|
||||
'onode' => $this->fftn->node_id,
|
||||
'dnode' => $this->tftn->node_id,
|
||||
'dnode' => $ao->node_id,
|
||||
'onet' => $this->fftn->host_id,
|
||||
'dnet' => $this->tftn->host_id,
|
||||
'dnet' => $ao->host_id,
|
||||
'flags' => 0, // @todo?
|
||||
'cost' => 0,
|
||||
'date'=>$this->created_at->format('d M y H:i:s'),
|
||||
'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;
|
||||
$o->message = $this->msg;
|
||||
if ($this->tagline)
|
||||
$o->message .= "\r... ".$this->tagline."\r";
|
||||
|
||||
$o->tearline .= $this->tearline;
|
||||
// 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)
|
||||
$o->message .= $this->tagline;
|
||||
|
||||
if ($this->tearline)
|
||||
$o->tearline .= $this->tearline;
|
||||
|
||||
// VIA kludge
|
||||
$via = $this->via ?: collect();
|
||||
@@ -103,12 +90,6 @@ class Netmail extends Model
|
||||
|
||||
$o->via = $via;
|
||||
|
||||
// INTL kludge
|
||||
// @todo Point handling FMPT/TOPT
|
||||
$o->intl = sprintf('%s %s',$this->tftn->ftn3d,$this->fftn->ftn3d);
|
||||
|
||||
// TZUTC
|
||||
$o->kludge->put('tzutc',str_replace('+','',$this->created_at->getOffsetString('')));
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
Reference in New Issue
Block a user