105 lines
2.2 KiB
PHP
105 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Console\Command;
|
|
|
|
use App\Traits\{GetNode,ParseNodes};
|
|
use App\Classes\FTNPacket;
|
|
use App\Models\{Echomail,Kludge,Seenby,Zone};
|
|
|
|
class ImportPacket extends Command
|
|
{
|
|
use GetNode,ParseNodes;
|
|
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'import:pkt {file : Packet File}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Import Mail Packet';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$pkt = new FTNPacket($this->argument('file'));
|
|
|
|
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)
|
|
{
|
|
$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++]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |