Initial netmail import
This commit is contained in:
@@ -54,11 +54,11 @@ class FtnPkt extends Command
|
||||
$this->warn(sprintf('-- From: %s(%s)->%s(%s), Type: %s, Size: %d, FQFA: %s',
|
||||
$o->from,
|
||||
$o->src,
|
||||
$o->to,
|
||||
$o->dst,
|
||||
$o->description(),
|
||||
strlen($o->message),
|
||||
$o->fqfa
|
||||
$o->to,
|
||||
$o->dst,
|
||||
$o->description(),
|
||||
strlen($o->message),
|
||||
$o->fqfa
|
||||
));
|
||||
|
||||
if ($o->unknown->count())
|
||||
|
@@ -5,13 +5,13 @@ namespace App\Console\Commands;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use App\Traits\{GetNode,ParseNodes};
|
||||
use App\Traits\{GetNode,ParseNodes,ParseZNFPDomain};
|
||||
use App\Classes\FTNPacket;
|
||||
use App\Models\{Echomail,Kludge,Seenby,Zone};
|
||||
use App\Models\{Echomail,Netmail,Zone};
|
||||
|
||||
class ImportPacket extends Command
|
||||
{
|
||||
use GetNode,ParseNodes;
|
||||
use GetNode,ParseNodes,ParseZNFPDomain;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
@@ -41,6 +41,7 @@ class ImportPacket extends Command
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
@@ -48,57 +49,133 @@ class ImportPacket extends Command
|
||||
|
||||
foreach ($pkt->messages as $o)
|
||||
{
|
||||
$eo = new Echomail;
|
||||
|
||||
$eo->pkt_from = $this->get_node($pkt->sz,$pkt->sn,$pkt->sf,$pkt->sp)->id;
|
||||
$eo->pkt_to = $this->get_node($pkt->dz,$pkt->dn,$pkt->df,$pkt->dp)->id;
|
||||
$eo->pkt = $pkt->filename;
|
||||
$eo->pkt_date = $pkt->date;
|
||||
|
||||
$eo->flags = $o->flags;
|
||||
$eo->cost = $o->cost;
|
||||
$eo->from_user = $o->from;
|
||||
$eo->from_ftn = $this->get_node($pkt->sz,$o->fn,$o->ff,$pkt->sp)->id;
|
||||
$eo->to_user = $o->to;
|
||||
$eo->subject = $o->subject;
|
||||
$eo->date = Carbon::createFromFormat('d M y H:i:s',$o->date,($o->tzutc >= 0 ? '+' : '').substr_replace($o->tzutc,':',2,0));
|
||||
$eo->tz = $o->tzutc;
|
||||
|
||||
$eo->area = $o->echoarea;
|
||||
$eo->msgid = $o->msgid;
|
||||
$eo->replyid = $o->replyid;
|
||||
$eo->message = $o->message;
|
||||
|
||||
$eo->origin = $o->origin;
|
||||
//$eo->original = (string)$o;
|
||||
|
||||
$eo->save();
|
||||
|
||||
foreach ($o->kludge as $k=>$v)
|
||||
switch ($o->type())
|
||||
{
|
||||
$eo->kludges()->attach($k,['value'=>json_encode($v)]);
|
||||
}
|
||||
case 'echomail':
|
||||
$date = Carbon::createFromFormat('d M y H:i:s',$o->date,($o->tzutc >= 0 ? '+' : '').substr_replace($o->tzutc,':',2,0));
|
||||
|
||||
foreach ($o->unknown as $v)
|
||||
{
|
||||
$eo->kludges()->attach('UNKNOWN',['value'=>json_encode($v)]);
|
||||
}
|
||||
// See if we already have this message.
|
||||
$eo = Echomail::firstOrNew([
|
||||
'date'=>$date,
|
||||
'from_ftn'=>$this->get_node($o->fz,$o->fn,$o->ff,$o->fp)->id,
|
||||
'msgid'=>$o->msgid,
|
||||
]);
|
||||
|
||||
foreach ($o->seenby as $v)
|
||||
{
|
||||
foreach ($this->parse_nodes(Zone::findOrFail($pkt->sz),$v) as $no)
|
||||
{
|
||||
$eo->seenbys()->attach($no->id);
|
||||
}
|
||||
}
|
||||
if (md5(utf8_decode($eo->message)) == md5($o->message))
|
||||
{
|
||||
$this->warn(sprintf('Duplicate message: %s@%s with id: %s',$o->from,$o->fqfa,$o->msgid));
|
||||
continue;
|
||||
}
|
||||
|
||||
$seq = 0;
|
||||
foreach ($o->path as $v)
|
||||
{
|
||||
foreach ($this->parse_nodes(Zone::findOrFail($pkt->sz),$v) as $no)
|
||||
{
|
||||
$eo->paths()->attach($no->id,['sequence'=>$seq++]);
|
||||
}
|
||||
$eo->pkt_from = $this->get_node($pkt->sz,$pkt->sn,$pkt->sf,$pkt->sp)->id;
|
||||
$eo->pkt_to = $this->get_node($pkt->dz,$pkt->dn,$pkt->df,$pkt->dp)->id;
|
||||
$eo->pkt = $pkt->filename;
|
||||
$eo->pkt_date = $pkt->date;
|
||||
|
||||
$eo->flags = $o->flags;
|
||||
$eo->cost = $o->cost;
|
||||
$eo->from_user = utf8_encode($o->from);
|
||||
$eo->to_user = utf8_encode($o->to);
|
||||
$eo->subject = utf8_encode($o->subject);
|
||||
$eo->tz = $o->tzutc;
|
||||
|
||||
$eo->area = $o->echoarea;
|
||||
$eo->replyid = $o->replyid;
|
||||
$eo->message = utf8_encode($o->message);
|
||||
|
||||
$eo->origin = utf8_encode($o->origin);
|
||||
//$eo->original = (string)$o;
|
||||
|
||||
$eo->save();
|
||||
|
||||
foreach ($o->kludge as $k=>$v)
|
||||
{
|
||||
$eo->kludges()->attach($k,['value'=>json_encode($v)]);
|
||||
}
|
||||
|
||||
foreach ($o->unknown as $v)
|
||||
{
|
||||
$eo->kludges()->attach('UNKNOWN',['value'=>json_encode($v)]);
|
||||
}
|
||||
|
||||
foreach ($o->seenby as $v)
|
||||
{
|
||||
foreach ($this->parse_nodes(Zone::findOrFail($pkt->sz),$v) as $no)
|
||||
{
|
||||
$eo->seenbys()->attach($no->id);
|
||||
}
|
||||
}
|
||||
|
||||
$seq = 0;
|
||||
foreach ($o->path as $v)
|
||||
{
|
||||
foreach ($this->parse_nodes(Zone::findOrFail($pkt->sz),$v) as $no)
|
||||
{
|
||||
$eo->paths()->attach($no->id,['sequence'=>$seq++]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'netmail':
|
||||
$date = Carbon::createFromFormat('d M y H:i:s',$o->date,($o->tzutc >= 0 ? '+' : '').substr_replace($o->tzutc,':',2,0));
|
||||
|
||||
// See if we already have this message.
|
||||
$no = Netmail::firstOrNew([
|
||||
'date'=>$date,
|
||||
'from_ftn'=>$this->get_node($o->fz,$o->fn,$o->ff,$o->fp)->id,
|
||||
'msgid'=>$o->msgid,
|
||||
]);
|
||||
|
||||
if (md5(utf8_decode($no->message)) == md5($o->message))
|
||||
{
|
||||
$this->warn(sprintf('Duplicate message: %s@%s with id: %s',$o->from,$o->fqfa,$o->msgid));
|
||||
//continue;
|
||||
}
|
||||
|
||||
$no->pkt_from = $this->get_node($pkt->sz,$pkt->sn,$pkt->sf,$pkt->sp)->id;
|
||||
$no->pkt_to = $this->get_node($pkt->dz,$pkt->dn,$pkt->df,$pkt->dp)->id;
|
||||
$no->pkt = $pkt->filename;
|
||||
$no->pkt_date = $pkt->date;
|
||||
|
||||
$no->flags = $o->flags;
|
||||
$no->cost = $o->cost;
|
||||
$no->from_user = utf8_encode($o->from);
|
||||
$no->to_user = utf8_encode($o->to);
|
||||
$no->to_ftn = $this->get_node($o->tz,$o->tn,$o->tf,$o->tp)->id;
|
||||
$no->subject = utf8_encode($o->subject);
|
||||
$no->tz = $o->tzutc;
|
||||
|
||||
$no->replyid = $o->replyid;
|
||||
$no->message = utf8_encode($o->message);
|
||||
|
||||
$no->origin = utf8_encode($o->origin);
|
||||
|
||||
$no->save();
|
||||
|
||||
foreach ($o->kludge as $k=>$v)
|
||||
{
|
||||
$no->kludges()->attach($k,['value'=>json_encode($v)]);
|
||||
}
|
||||
|
||||
foreach ($o->unknown as $v)
|
||||
{
|
||||
$no->kludges()->attach('UNKNOWN',['value'=>json_encode($v)]);
|
||||
}
|
||||
|
||||
$seq = 0;
|
||||
foreach ($o->via as $v)
|
||||
{
|
||||
dump($v);
|
||||
$data = preg_split('/\s/',$v);
|
||||
$ftno = $this->parse_znfp_domain($data[0]);
|
||||
unset($data[0]);
|
||||
|
||||
$no->paths()->attach($ftno->id,['sequence'=>$seq++,'value'=>json_encode($data)]);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
abort(500,'Unknown type: '.$o->type());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user