diff --git a/app/Classes/FTN/Message.php b/app/Classes/FTN/Message.php index 695c975..b9a6389 100644 --- a/app/Classes/FTN/Message.php +++ b/app/Classes/FTN/Message.php @@ -233,7 +233,7 @@ class Message extends FTNBase $o->mo->from = $o->header['user_from']; $o->mo->subject = $o->header['subject']; - $o->mo->datetime = $o->datetime; + $o->mo->datetime = $o->datetime->clone()->utc(); $o->mo->tzoffset = $o->datetime->utcOffset(); $o->mo->flags = $o->header['flags']; $o->mo->cost = $o->header['cost']; diff --git a/app/Classes/FTN/Packet.php b/app/Classes/FTN/Packet.php index 2d93f33..9e83c50 100644 --- a/app/Classes/FTN/Packet.php +++ b/app/Classes/FTN/Packet.php @@ -361,7 +361,7 @@ abstract class Packet extends FTNBase implements \Iterator, \Countable $this->content .= "\00\00"; - $this->messages = $msgs->map(fn($item)=>$item->only(['id','datetime'])); + $this->messages = $msgs->map(fn($item)=>$item->only(['id','date'])); return $this; } diff --git a/app/Classes/FTN/Packet/FSC39.php b/app/Classes/FTN/Packet/FSC39.php index 783728a..b83f4d5 100644 --- a/app/Classes/FTN/Packet/FSC39.php +++ b/app/Classes/FTN/Packet/FSC39.php @@ -65,7 +65,7 @@ final class FSC39 extends Packet */ protected function header(Collection $msgs): string { - $oldest = $this->messages->sortBy('datetime')->last(); + $oldest = $this->messages->sortBy('date')->last(); return pack(collect(self::HEADER)->pluck(1)->join(''), $this->fftn_p->node_id, // Orig Node diff --git a/app/Classes/FTN/Packet/FSC48.php b/app/Classes/FTN/Packet/FSC48.php index 809cfff..09fbe3b 100644 --- a/app/Classes/FTN/Packet/FSC48.php +++ b/app/Classes/FTN/Packet/FSC48.php @@ -65,7 +65,7 @@ final class FSC48 extends Packet */ protected function header(Collection $msgs): string { - $oldest = $msgs->sortBy('datetime')->last(); + $oldest = $msgs->sortBy('date')->last(); return pack(collect(self::HEADER)->pluck(1)->join(''), $this->fftn_p->node_id, // Orig Node diff --git a/app/Classes/File/Mail.php b/app/Classes/File/Mail.php index 23ff70d..55441a2 100644 --- a/app/Classes/File/Mail.php +++ b/app/Classes/File/Mail.php @@ -116,6 +116,6 @@ final class Mail extends Send private function youngest(): Carbon { - return $this->f->messages->pluck('datetime')->sort()->last(); + return $this->f->messages->pluck('date')->sort()->last(); } } \ No newline at end of file diff --git a/app/Console/Commands/PacketInfo.php b/app/Console/Commands/PacketInfo.php index dad84fe..cb7f078 100644 --- a/app/Console/Commands/PacketInfo.php +++ b/app/Console/Commands/PacketInfo.php @@ -68,7 +68,7 @@ class PacketInfo extends Command echo "\n"; try { - $this->warn(sprintf('- Date : %s (%s)',$msg->datetime,$msg->datetime->tz->toOffsetName())); + $this->warn(sprintf('- Date : %s (%s)',$msg->date,$msg->date->tz->toOffsetName())); $this->warn(sprintf(' - Errors : %s',$msg->errors->count() ? 'YES' : 'No')); $this->warn(sprintf(' - Flags : %s',$msg->flags()->keys()->join(', '))); $this->warn(sprintf(' - Cost : %d',$msg->cost)); @@ -97,7 +97,7 @@ class PacketInfo extends Command } foreach ($pkt->errors as $msg) { - $this->error(sprintf('- Date: %s',$msg->date)); + $this->error(sprintf('- Date: %s',$msg->datetime)); $this->error(sprintf(' - FLAGS: %s',$msg->flags()->filter()->keys()->join(', '))); $this->error(sprintf(' - From: %s (%s)',$msg->from,$msg->fftn)); $this->error(sprintf(' - To: %s (%s)',$msg->to,$msg->tftn)); diff --git a/app/Jobs/MessageProcess.php b/app/Jobs/MessageProcess.php index 37342cc..1ed6482 100644 --- a/app/Jobs/MessageProcess.php +++ b/app/Jobs/MessageProcess.php @@ -228,16 +228,18 @@ class MessageProcess implements ShouldQueue if ($this->mo->msgid) { $o = Echomail::where('msgid',$this->mo->msgid) ->where('fftn_id',$this->mo->fftn->id) - ->where('datetime','>=',$this->mo->date->subYears(3)) + ->where('datetime','>=',$this->mo->date->clone()->subYears(3)) ->where('datetime','<=',$this->mo->date) + ->dontCache() ->single(); Log::debug(sprintf('%s:- Checking for duplicate from host id [%d].',self::LOGKEY,$this->mo->fftn->id)); if ($o) { // @todo Actually update seenby - Log::alert(sprintf('%s:! Duplicate echomail [%s] in [%s] from (%s) [%s] to (%s) - updating seenby.', + Log::alert(sprintf('%s:! Duplicate echomail [%d] (%s) in [%s] from (%s) [%s] to (%s) - updating seenby.', self::LOGKEY, + $o->id, $this->mo->msgid, $this->mo->echoarea->name, $this->mo->from,$this->mo->fftn->ftn, @@ -284,6 +286,7 @@ class MessageProcess implements ShouldQueue $o = Echomail::where('msg_crc',$xx=md5($this->mo->msg_crc)) ->where('fftn_id',$this->mo->fftn->id) ->where('datetime','>',Carbon::now()->subWeek()) + ->dontCache() ->get(); if ($o->count()) diff --git a/app/Models/System.php b/app/Models/System.php index 62b393c..13ed10a 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -269,7 +269,8 @@ class System extends Model */ public function packet(Address $ao,string $password=NULL): Packet { - // @todo Check that the address is one of the system's addresses + if ($ao->system_id !== $this->id) + throw new \Exception('Packet for [%s] is not for system [%d]',$ao->ftn,$this->id); return (new (collect(Packet::PACKET_TYPES) diff --git a/app/Notifications/Echomails.php b/app/Notifications/Echomails.php index ef88962..f00b5a3 100644 --- a/app/Notifications/Echomails.php +++ b/app/Notifications/Echomails.php @@ -8,7 +8,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; use App\Classes\FTN\Message; -use App\Models\{Echoarea,Echomail,Setup}; +use App\Models\{Echoarea,Echomail,Netmail,Setup}; abstract class Echomails extends Notification //implements ShouldQueue { @@ -53,8 +53,8 @@ abstract class Echomails extends Notification //implements ShouldQueue $o->echoarea_id = $eo->id; - $o->datetime = Carbon::now(); - $o->tzoffset = $o->datetime->utcOffset(); + $o->datetime = Carbon::now()->utc(); + $o->tzoffset = Carbon::now()->utcOffset(); $o->flags = (Message::FLAG_LOCAL); @@ -62,4 +62,13 @@ abstract class Echomails extends Notification //implements ShouldQueue return $o; } + + protected function sourceSummary(Echomail|Netmail $o,string $item=NULL): string + { + return sprintf("Your %s was received here on [%s] and it looks like you sent it on [%s].", + $item ?: sprintf('%s with ID [%s] to [%s]',$o instanceof Netmail ? 'Netmail' : 'Echomail',$o->msgid,$o->to), + Carbon::now()->utc()->toDateTimeString(), + $o->date->utc()->toDateTimeString(), + ); + } } \ No newline at end of file diff --git a/app/Notifications/Netmails.php b/app/Notifications/Netmails.php index 9613b56..a8f1b79 100644 --- a/app/Notifications/Netmails.php +++ b/app/Notifications/Netmails.php @@ -8,7 +8,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; use App\Classes\FTN\Message; -use App\Models\{Netmail,Setup,System}; +use App\Models\{Echomail,Netmail,Setup}; abstract class Netmails extends Notification //implements ShouldQueue { @@ -57,8 +57,8 @@ abstract class Netmails extends Notification //implements ShouldQueue $o->to = $ao->system->sysop; $o->from = Setup::PRODUCT_NAME; - $o->datetime = Carbon::now(); - $o->tzoffset = $o->datetime->utcOffset(); + $o->datetime = Carbon::now()->utc(); + $o->tzoffset = Carbon::now()->utcOffset(); $o->fftn_id = our_address($ao)->id; $o->tftn_id = $ao->id; @@ -69,4 +69,13 @@ abstract class Netmails extends Notification //implements ShouldQueue return $o; } + + protected function sourceSummary(Echomail|Netmail $o,string $item=NULL): string + { + return sprintf("Your %s was received here on [%s] and it looks like you sent it on [%s].", + $item ?: sprintf('%s with ID [%s] to [%s]',$o instanceof Netmail ? 'Netmail' : 'Echomail',$o->msgid,$o->to), + Carbon::now()->utc()->toDateTimeString(), + $o->date->utc()->toDateTimeString(), + ); + } } \ No newline at end of file diff --git a/app/Notifications/Netmails/EchoareaNoWrite.php b/app/Notifications/Netmails/EchoareaNoWrite.php index d599b09..522fa62 100644 --- a/app/Notifications/Netmails/EchoareaNoWrite.php +++ b/app/Notifications/Netmails/EchoareaNoWrite.php @@ -48,14 +48,7 @@ class EchoareaNoWrite extends Netmails // Message $msg = $this->page(FALSE,'nowrite'); - $msg->addText( - sprintf("Your echomail with ID [%s] to [%s] here was received here on [%s] and it looks like you sent it on [%s].\r\r", - $this->mo->msgid, - $this->mo->to, - Carbon::now()->utc()->toDateTimeString(), - $this->mo->date->utc()->toDateTimeString(), - ) - ); + $msg->addText($this->sourceSummary($this->mo)."\r\r"); $msg->addText(sprintf("It appears that you do not have permission to post in [%s] using the address [%s], so the message from your system was rejected.\r\r",$this->mo->echoarea->name,$ao->ftn)); $msg->addText("Please contact the ZC if you think this is a mistake.\r\r"); diff --git a/app/Notifications/Netmails/EchoareaNotExist.php b/app/Notifications/Netmails/EchoareaNotExist.php index 30b7ffa..adbe0c2 100644 --- a/app/Notifications/Netmails/EchoareaNotExist.php +++ b/app/Notifications/Netmails/EchoareaNotExist.php @@ -50,14 +50,7 @@ class EchoareaNotExist extends Netmails // Message $msg = $this->page(FALSE,'nothere'); - $msg->addText( - sprintf("Your echomail with ID [%s] to [%s] here was received here on [%s] and it looks like you sent it on [%s].\r\r", - $this->mo->msgid, - $this->mo->to, - Carbon::now()->utc()->toDateTimeString(), - $this->mo->date->utc()->toDateTimeString(), - ) - ); + $msg->addText($this->sourceSummary($this->mo)."\r\r"); $msg->addText(sprintf("It appears that the echoarea [%s] that this message is for doesnt exist, so the message from your system was rejected.\r\r",$this->mo->set->get('set_echoarea'))); $msg->addText("Please contact the ZC if you think this is a mistake.\r\r"); diff --git a/app/Notifications/Netmails/EchoareaNotSubscribed.php b/app/Notifications/Netmails/EchoareaNotSubscribed.php index 3f0ac04..3c7775e 100644 --- a/app/Notifications/Netmails/EchoareaNotSubscribed.php +++ b/app/Notifications/Netmails/EchoareaNotSubscribed.php @@ -48,14 +48,7 @@ class EchoareaNotSubscribed extends Netmails // Message $msg = $this->page(FALSE,'nosub'); - $msg->addText( - sprintf("Your echomail with ID [%s] to [%s] here was received here on [%s] and it looks like you sent it on [%s].\r\r", - $this->mo->msgid, - $this->mo->to, - Carbon::now()->utc()->toDateTimeString(), - $this->mo->date->utc()->toDateTimeString(), - ) - ); + $msg->addText($this->sourceSummary($this->mo)."\r\r"); $msg->addText(sprintf("It appears that you havent been previously subscribed to this echoarea using the address [%s].\r\r",$ao->ftn)); diff --git a/app/Notifications/Netmails/EchomailBadAddress.php b/app/Notifications/Netmails/EchomailBadAddress.php index 6b38d3d..a558448 100644 --- a/app/Notifications/Netmails/EchomailBadAddress.php +++ b/app/Notifications/Netmails/EchomailBadAddress.php @@ -48,14 +48,7 @@ class EchomailBadAddress extends Netmails // Message $msg = $this->page(FALSE,'badmsg'); - $msg->addText( - sprintf("Your echomail with ID [%s] to [%s] here was received here on [%s] and it looks like you sent it on [%s].\r\r", - $this->mo->msgid, - $this->mo->to, - Carbon::now()->utc()->toDateTimeString(), - $this->mo->date->utc()->toDateTimeString(), - ) - ); + $msg->addText($this->sourceSummary($this->mo)."\r\r"); $msg->addText(sprintf("The address in this echomail [%s] is the wrong address for this domain [%s].\r\r",$this->mo->fftn,$ao->zone->domain->name)); diff --git a/app/Notifications/Netmails/NetmailHubNoUser.php b/app/Notifications/Netmails/NetmailHubNoUser.php index 7fd9277..ffe5b46 100644 --- a/app/Notifications/Netmails/NetmailHubNoUser.php +++ b/app/Notifications/Netmails/NetmailHubNoUser.php @@ -50,14 +50,7 @@ class NetmailHubNoUser extends Netmails // Message $msg = $this->page(FALSE,'Reject'); - $msg->addText( - sprintf("Your netmail with ID [%s] to [%s] here was received here on [%s] and it looks like you sent it on [%s].\r\r", - $this->mo->msgid, - $this->mo->to, - Carbon::now()->utc()->toDateTimeString(), - $this->mo->date->utc()->toDateTimeString(), - ) - ); + $msg->addText($this->sourceSummary($this->mo)."\r\r"); $msg->addText("This hub is not attended, so no user will be able to read your message. You may like to try and contact them another way.\r\r"); diff --git a/app/Traits/MessageAttributes.php b/app/Traits/MessageAttributes.php index bc5becd..84b19c7 100644 --- a/app/Traits/MessageAttributes.php +++ b/app/Traits/MessageAttributes.php @@ -59,9 +59,15 @@ trait MessageAttributes return ($this->msg_src) ? $this->msg_src : $this->rebuildMessage(); } + /** + * This is used to build our data in a timezone date, so that when exported, we include the right TZUTC + * + * @return Carbon + */ public function getDateAttribute(): Carbon { - return $this->datetime->utcOffset($this->tzoffset); + // Datetime is in utc, and tzoffset describes what that local time is + return $this->datetime->clone()->utcOffset($this->tzoffset); } public function getOriginAttribute(string $val=NULL): ?string diff --git a/resources/views/widgets/message.blade.php b/resources/views/widgets/message.blade.php index 64cb1cf..89cc805 100644 --- a/resources/views/widgets/message.blade.php +++ b/resources/views/widgets/message.blade.php @@ -8,7 +8,7 @@ use App\Models\{Echomail,Netmail}; TO: {!! Message::tr($msg->to) !!} @if ($msg instanceof Netmail)({{ $msg->tftn->ftn }})@endif