Some message optimisation, added Echomail processing

This commit is contained in:
Deon George
2021-07-31 00:35:52 +10:00
parent 6f26bc4c71
commit d937547599
15 changed files with 476 additions and 134 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Carbon\Carbon;
use Exception;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -151,6 +152,26 @@ class Address extends Model
return ($o && $o->system->active) ? $o : NULL;
}
/**
* Get echomail for this node
*
* @return Packet|null
*/
public function getEchomail(): ?Packet
{
if (($x=Echomail::select('*') //where('tftn_id',$this->id)
->where(function($q) {
return $q->whereNull('sent')
->orWhere('sent',FALSE);
}))
->count())
{
return $this->getPacket($x->get());
}
return NULL;
}
/**
* Get netmail for this node (including it's children)
*
@@ -165,23 +186,34 @@ class Address extends Model
}))
->count())
{
$o = new Packet($this);
foreach ($x->get() as $oo) {
$o->addNetmail($oo->packet());
$oo->packet = $o->name;
$oo->sent = TRUE;
$oo->sent_at = Carbon::now();
$oo->save();
}
return $o;
return $this->getPacket($x->get());
}
return NULL;
}
/**
* Return a packet of mail
*
* @param Collection $c
* @return Packet
*/
private function getPacket(Collection $c): Packet
{
$o = new Packet($this);
foreach ($c as $oo) {
$o->addMail($oo->packet($this));
$oo->packet = $o->name;
$oo->sent = TRUE;
$oo->sent_at = Carbon::now();
$oo->save();
}
return $o;
}
/**
* Parse a string and split it out as an FTN array
*

View File

@@ -2,25 +2,77 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Carbon\Exceptions\Exception;
use Jenssegers\Mongodb\Eloquent\Model;
use Jenssegers\Mongodb\Eloquent\SoftDeletes;
class Echomail extends Model
use App\Classes\FTN\Message;
use App\Interfaces\Packet;
use App\Traits\{MsgID,UseMongo};
class Echomail extends Model implements Packet
{
protected $dates = ['date'];
protected $fillable = ['date','msgid','from_ftn'];
use SoftDeletes,MsgID,UseMongo;
public function kludges()
protected $dates = ['datetime'];
/* RELATIONS */
public function fftn()
{
return $this->belongsToMany(Kludge::class);
return $this
->setConnection('pgsql')
->belongsTo(Address::class)
->withTrashed();
}
public function seenbys()
{
return $this->belongsToMany(Seenby::class,NULL,NULL,'node_id');
}
/* METHODS */
public function paths()
/**
* Return this model as a packet
*/
public function packet(Address $ao): Message
{
return $this->belongsToMany(Path::class,NULL,NULL,'node_id');
// @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' => $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;
$o->echoarea = $this->echoarea;
$o->flags = $this->flags;
$o->kludge->put('mid',$this->id);
$o->msgid = $this->msgid;
if ($this->reply)
$o->reply = $this->reply;
$o->message = $this->msg;
if ($this->tagline)
$o->tagline = $this->tagline;
if ($this->tearline)
$o->tearline = $this->tearline;
if ($this->origin)
$o->origin = $this->origin;
// @todo SEENBY
// @todo PATH
return $o;
}
}

View File

@@ -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;
}