diff --git a/app/Console/Commands/SendTestNetmail.php b/app/Console/Commands/SendTestNetmail.php new file mode 100644 index 0000000..43d7651 --- /dev/null +++ b/app/Console/Commands/SendTestNetmail.php @@ -0,0 +1,40 @@ +argument('ftn')); + + Notification::route('netmail',$ao)->notify(new NetmailTest($ao)); + } +} \ No newline at end of file diff --git a/app/Notifications/Channels/NetmailChannel.php b/app/Notifications/Channels/NetmailChannel.php new file mode 100644 index 0000000..2f3c851 --- /dev/null +++ b/app/Notifications/Channels/NetmailChannel.php @@ -0,0 +1,50 @@ +netmail = $o; + } + + /** + * Send the given notification. + * + * @param mixed $notifiable + * @param \Illuminate\Notifications\Notification $notification + * @return \Psr\Http\Message\ResponseInterface|null + */ + public function send($notifiable,Notification $notification) + { + if (! $ao = $notifiable->routeNotificationFor('netmail',$notification)) + return; + + $o = $notification->toNetmail($notifiable); + Log::info(sprintf('%s:Test Netmail created [%s]',self::LOGKEY,$o->id)); + + Job::dispatch($ao); + Log::info(sprintf('%s:Dispatched job to pool address [%s]',self::LOGKEY,$ao->ftn)); + } +} \ No newline at end of file diff --git a/app/Notifications/NetmailTest.php b/app/Notifications/NetmailTest.php new file mode 100644 index 0000000..bb24fa4 --- /dev/null +++ b/app/Notifications/NetmailTest.php @@ -0,0 +1,98 @@ +queue = 'netmail'; + $this->ao = $ao; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['netmail']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return Netmail + * @throws \Exception + */ + public function toNetmail($notifiable): Netmail + { + Log::info(sprintf('%s:Creating test netmail to [%s]',self::LOGKEY,$this->ao->ftn)); + + $so = Setup::findOrFail(config('app.id'))->system; + + $o = new Netmail; + $o->to = $this->ao->system->sysop; + $o->from = Setup::PRODUCT_NAME; + $o->subject = 'Testing 1, 2, 3...'; + $o->datetime = Carbon::now(); + $o->tzoffset = $o->datetime->utcOffset(); + + $o->fftn_id = $so->match($this->ao->zone)->first(); + $o->tftn_id = $this->ao->id; + $o->flags = Message::FLAG_LOCAL; + $o->cost = 0; + + $o->tagline = 'Testing, testing, 1 2 3.'; + $o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID); + + // Message + $msg = new Page; + $msg->addLogo(new ANSI('public/logo/netmail.bin')); + + $header = new Thick; + $header->addText(ANSI::ansi_code([1,37]).'Clearing Houz'); + $msg->addHeader($header,'FTN Mailer and Tosser',TRUE,0xc4); + + $lbc = new Thin; + $lbc->addText('Test'); + $msg->addLeftBoxContent($lbc); + + $msg->addText( + "Hi there,\r\r". + "This is just a test netmail to make sure we can send a message to your system.\r\r". + "There is no need to reply, but if you do, it'll boost my spirits :)\r" + ); + + $o->msg = $msg->render(); + $o->save(); + + return $o; + } +} \ No newline at end of file diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 9ebae38..a354456 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,9 +2,13 @@ namespace App\Providers; +use Illuminate\Notifications\ChannelManager; +use Illuminate\Support\Facades\Notification; use Illuminate\Support\ServiceProvider; use Laravel\Passport\Passport; +use App\Notifications\Channels\NetmailChannel; +use App\Models\Netmail; use App\Traits\SingleOrFail; class AppServiceProvider extends ServiceProvider @@ -19,6 +23,12 @@ class AppServiceProvider extends ServiceProvider public function register() { Passport::ignoreMigrations(); + + Notification::resolved(function (ChannelManager $service) { + $service->extend('netmail', function ($app) { + return new NetmailChannel($app->make(Netmail::class)); + }); + }); } /**