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
|
||||
{
|
||||
|
Reference in New Issue
Block a user