More complete rework of packet parsing and packet generation with 29710c
This commit is contained in:
@@ -978,47 +978,26 @@ class Address extends Model
|
||||
/**
|
||||
* Get echomail for this node
|
||||
*
|
||||
* @param bool $update
|
||||
* @param Collection|null $echomail
|
||||
* @return Packet|null
|
||||
* @throws \Exception
|
||||
* @todo If we export to uplink hubs without our address in the seenby, they should send the message back to
|
||||
* us with their seenby's.
|
||||
*/
|
||||
public function getEchomail(bool $update=TRUE,Collection $echomail=NULL): ?Packet
|
||||
public function getEchomail(): ?Packet
|
||||
{
|
||||
$pkt = NULL;
|
||||
if ($echomail)
|
||||
return $this->getPacket($echomail);
|
||||
if (($num=$this->echomailWaiting())->count()) {
|
||||
$s = Setup::findOrFail(config('app.id'));
|
||||
|
||||
$s = Setup::findOrFail(config('app.id'));
|
||||
|
||||
$num = self::UncollectedEchomail()
|
||||
->select('echomails.id')
|
||||
->where('addresses.id',$this->id)
|
||||
->groupBy(['echomails.id'])
|
||||
->get();
|
||||
|
||||
if ($num->count()) {
|
||||
// Limit to max messages
|
||||
Log::info(sprintf('%s:= Got [%d] echomails for [%s] for sending',self::LOGKEY,$num->count(),$this->ftn));
|
||||
|
||||
// Limit to max messages
|
||||
if ($num->count() > $s->msgs_pkt)
|
||||
Log::notice(sprintf('%s:= Only sending [%d] echomails for [%s]',self::LOGKEY,$s->msgs_pkt,$this->ftn));
|
||||
|
||||
$x = $this->echomailWaiting($s->msgs_pkt);
|
||||
$pkt = $this->getPacket($x);
|
||||
|
||||
if ($pkt && $pkt->count() && $update)
|
||||
DB::table('echomail_seenby')
|
||||
->whereIn('echomail_id',$x->pluck('id'))
|
||||
->where('address_id',$this->id)
|
||||
->whereNull('sent_at')
|
||||
->whereNotNull('export_at')
|
||||
->update(['sent_pkt'=>$pkt->name]);
|
||||
return $this->system->packet($this)->mail($num->take($s->msgs_pkt));
|
||||
}
|
||||
|
||||
return $pkt;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1036,54 +1015,47 @@ class Address extends Model
|
||||
/**
|
||||
* Get netmail for this node (including it's children)
|
||||
*
|
||||
* @param bool $update
|
||||
* @return Packet|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getNetmail(bool $update=FALSE): ?Packet
|
||||
public function getNetmail(): ?Packet
|
||||
{
|
||||
$pkt = NULL;
|
||||
if (($num=$this->netmailAlertWaiting())->count()) {
|
||||
Log::debug(sprintf('%s:= Packaging [%d] netmail alerts to [%s]',self::LOGKEY,$num->count(),$this->ftn));
|
||||
|
||||
$s = Setup::findOrFail(config('app.id'));
|
||||
// Find any message that defines a packet password
|
||||
$pass = $num
|
||||
->map(function($item) {
|
||||
$passpos = strpos($item->subject,':');
|
||||
return (($passpos > 0) && ($passpos < 8)) ? substr($item->subject,0,$passpos) : NULL;
|
||||
})
|
||||
->filter()
|
||||
->pop();
|
||||
|
||||
if (($x=$this->netmailAlertWaiting())->count()) {
|
||||
Log::debug(sprintf('%s:= Packaging [%d] netmail alerts to [%s]',self::LOGKEY,$x->count(),$this->ftn));
|
||||
$passpos = strpos($x->last()->subject,':');
|
||||
Log::debug(sprintf('%s:= Overwriting system packet password with [%s] for [%s]',self::LOGKEY,$pass,$this->ftn));
|
||||
|
||||
if ($passpos > 8)
|
||||
Log::alert(sprintf('%s:! Password would be greater than 8 chars? [%d]',self::LOGKEY,$passpos));
|
||||
|
||||
// @todo Do the strip pass where, if we dont want the password in the netmail
|
||||
|
||||
$pkt = $this->getPacket($x,substr($x->last()->subject,0,$passpos));
|
||||
|
||||
if ($pkt && $pkt->count() && $update)
|
||||
DB::table('netmails')
|
||||
->whereIn('id',$x->pluck('id'))
|
||||
->update(['sent_pkt'=>$pkt->name]);
|
||||
|
||||
return $pkt;
|
||||
return $this->system->packet($this,$pass)->mail(
|
||||
$num->filter(fn($item)=>preg_match("/^{$pass}:/",$item->subject))
|
||||
->transform(function($item) use ($pass) {
|
||||
$item->subject = preg_replace("/^{$pass}:/",'',$item->subject);
|
||||
return $item;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (($x=$this->netmailWaiting())
|
||||
->count())
|
||||
{
|
||||
Log::debug(sprintf('%s:= Got [%d] netmails for [%s] for sending',self::LOGKEY,$x->count(),$this->ftn));
|
||||
if (($num=$this->netmailWaiting())->count()) {
|
||||
$s = Setup::findOrFail(config('app.id'));
|
||||
|
||||
if ($x->count() > $s->msgs_pkt) {
|
||||
$x = $x->take($s->msgs_pkt);
|
||||
Log::alert(sprintf('%s:= Only sending [%d] netmails for [%s]',self::LOGKEY,$x->count(),$this->ftn));
|
||||
}
|
||||
Log::debug(sprintf('%s:= Got [%d] netmails for [%s] for sending',self::LOGKEY,$num->count(),$this->ftn));
|
||||
|
||||
$pkt = $this->getPacket($x);
|
||||
// Limit to max messages
|
||||
if ($num->count() > $s->msgs_pkt)
|
||||
Log::alert(sprintf('%s:= Only sending [%d] netmails for [%s]',self::LOGKEY,$num->count(),$this->ftn));
|
||||
|
||||
if ($pkt && $pkt->count() && $update)
|
||||
DB::table('netmails')
|
||||
->whereIn('id',$x->pluck('id'))
|
||||
->update(['sent_pkt'=>$pkt->name]);
|
||||
return $this->system->packet($this)->mail($num->take($s->msgs_pkt));
|
||||
}
|
||||
|
||||
return $pkt;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1154,6 +1126,7 @@ class Address extends Model
|
||||
*
|
||||
* @return Collection
|
||||
* @throws \Exception
|
||||
* @note The packet password to use is on the subject line for these alerts
|
||||
*/
|
||||
public function netmailAlertWaiting(): Collection
|
||||
{
|
||||
|
@@ -92,7 +92,6 @@ final class Netmail extends Model implements Packet
|
||||
$nodes = collect();
|
||||
|
||||
// Parse PATH
|
||||
// @todo dont save us in the path, we'll add it dynamically when we send out.
|
||||
// <FTN Address> @YYYYMMDD.HHMMSS[.Precise][.Time Zone] <Program Name> <Version> [Serial Number]
|
||||
if ($model->set->has('set_path')) {
|
||||
foreach ($model->set->get('set_path') as $line) {
|
||||
@@ -123,8 +122,8 @@ final class Netmail extends Model implements Packet
|
||||
}
|
||||
|
||||
// If there are no details (Mystic), we'll create a blank
|
||||
} else {
|
||||
$nodes->push(['node'=>$model->set->get('set_sender'),'datetime'=>Carbon::now(),'program'=>sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID)]);
|
||||
} elseif ($model->set->has('set_sender')) {
|
||||
$nodes->push(['node'=>$model->set->get('set_sender'),'datetime'=>Carbon::now(),'program'=>'Unknown']);
|
||||
}
|
||||
|
||||
// Save the Path
|
||||
|
@@ -253,14 +253,18 @@ class System extends Model
|
||||
* Return the packet that this system uses
|
||||
*
|
||||
* @param Address $ao
|
||||
* @param string|null $password
|
||||
* @return Packet
|
||||
*/
|
||||
public function packet(Address $ao): Packet
|
||||
public function packet(Address $ao,string $password=NULL): Packet
|
||||
{
|
||||
// @todo Check that the address is one of the system's addresses
|
||||
|
||||
return (new (collect(Packet::PACKET_TYPES)
|
||||
->get($this->pkt_type ?: config('fido.packet_default'))))->for($ao);
|
||||
return
|
||||
(new (collect(Packet::PACKET_TYPES)
|
||||
->get($this->pkt_type ?: config('fido.packet_default'))))
|
||||
->for($ao)
|
||||
->password($password);
|
||||
}
|
||||
|
||||
public function poll(): ?Job
|
||||
|
Reference in New Issue
Block a user