From 0e9f61bd244bce2e936e912da95e74a6da298eac Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 21 Oct 2026 12:20:38 +0100 Subject: [PATCH 1/2] fix(api): avoid NRE in MailSender on rdv query notifications The API did not bind the Smtp section and its appsettings lacked Site.Owner, so MailSender threw a NullReferenceException and PostQuery returned 500. Bind Smtp in the API, add Owner/Smtp to the api appsettings template, and log/skip sending when mail configuration is incomplete. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 16 ++++++++++++++++ contrib/template.appsettings-api.json | 12 +++++++++++- src/Yavsc.Api/Program.cs | 2 ++ src/Yavsc.Server/Services/MailSender.cs | 8 +++++++- .../Yavsc.Org.Tests/NonRegression/EMailling.cs | 16 ++++++++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c431a1099..ccb987447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [1.0.8-rc30] - unstable + +### Added + +### Changed + +### Fixed + ## [1.0.8-rc29] - unstable ### Added @@ -19,6 +27,14 @@ * [PostIt] Mise a jour d'Avalonia vers 12.1.4. +### Fixed + +* [Yavsc.Api, Yavsc.Server] Une demande de rendez-vous ne provoque plus + d'erreur 500 (NullReferenceException dans MailSender) : l'API lie + desormais la section Smtp, le modele appsettings-api fournit Site.Owner + et Smtp, et un envoi sans configuration mail complete est journalise + puis ignore. + ## [1.0.8-rc28] - unstable diff --git a/contrib/template.appsettings-api.json b/contrib/template.appsettings-api.json index b364eeef1..afe693a4f 100644 --- a/contrib/template.appsettings-api.json +++ b/contrib/template.appsettings-api.json @@ -6,7 +6,17 @@ "https://preprod-blogs.$DOMAIN" ], "Bills": "bills", - "TempDir": "temp" + "TempDir": "temp", + "Owner": { + "Name": "Paul Schneider", + "EMail": "paul@pschneider.fr" + } + }, + "Smtp": { + "Host": "mercure.pschneider.fr", + "Port": 465, + "UserName": "paul", + "Password": "$SMTP_PASSWORD" }, "Logging": { "LogLevel": { diff --git a/src/Yavsc.Api/Program.cs b/src/Yavsc.Api/Program.cs index 9ea2f7354..03afcf58f 100644 --- a/src/Yavsc.Api/Program.cs +++ b/src/Yavsc.Api/Program.cs @@ -12,6 +12,7 @@ using Yavsc.Models; using Yavsc; using Yavsc.Server.Helpers; using Yavsc.Services; +using Yavsc.Settings; using Yavsc.Server.Hubs; using Yavsc.Api.Services; @@ -71,6 +72,7 @@ internal class Program // Binds the "Site" section (Bills, TempDir, Avatars, …) used by // the document-generation flow and BillingController. services.Configure(builder.Configuration.GetSection("Site")); + services.Configure(builder.Configuration.GetSection("Smtp")); services.AddPodcasts(builder.Configuration); services.AddInvoicing(builder.Configuration); diff --git a/src/Yavsc.Server/Services/MailSender.cs b/src/Yavsc.Server/Services/MailSender.cs index 9a6c60ed9..1a678a549 100644 --- a/src/Yavsc.Server/Services/MailSender.cs +++ b/src/Yavsc.Server/Services/MailSender.cs @@ -104,6 +104,12 @@ namespace Yavsc.Services try { logger.LogInformation($"SendEmail for {email} : {subject}"); + if (string.IsNullOrWhiteSpace(siteSettings?.Owner?.EMail) + || string.IsNullOrWhiteSpace(smtpSettings?.Host)) + { + logger.LogError("Email not sent: mail configuration is incomplete (Site:Owner:EMail and Smtp:Host are required). To={To}, Subject={Subject}", email, subject); + return string.Empty; + } MimeMessage msg = new(); msg.From.Add(BuildMailboxAddress(siteSettings.Owner.Name, siteSettings.Owner.EMail)); msg.To.Add(BuildMailboxAddress(name, email)); @@ -139,7 +145,7 @@ namespace Yavsc.Services } catch (FormatException ex) { - logger.LogError(ex, "Refusing to send email because the recipient or sender address is malformed. To={To}, From={From}", email, siteSettings.Owner.EMail); + logger.LogError(ex, "Refusing to send email because the recipient or sender address is malformed. To={To}, From={From}", email, siteSettings?.Owner?.EMail); logger.LogError(ex.Message); if (ex.InnerException!=null) logger.LogError(ex.InnerException.Message); diff --git a/src/test/Yavsc.Org.Tests/NonRegression/EMailling.cs b/src/test/Yavsc.Org.Tests/NonRegression/EMailling.cs index eed2e9e18..d71e7682d 100644 --- a/src/test/Yavsc.Org.Tests/NonRegression/EMailling.cs +++ b/src/test/Yavsc.Org.Tests/NonRegression/EMailling.cs @@ -121,6 +121,22 @@ namespace Yavsc.Org.Tests Assert.Equal(string.Empty, result); } + [Fact] + public async Task SendEmailAsync_skips_when_owner_is_not_configured() + { + var factory = new RejectingSmtpClientFactory(); + var sender = new MailSender( + Options.Create(new SiteSettings { Authority = "example.com" }), + Options.Create(new SmtpSettings()), + NullLoggerFactory.Instance, + new TestStringLocalizer(), + factory); + + var result = await sender.SendEmailAsync("Alice", "alice@example.com", "Rdv", "hello"); + + Assert.Equal(string.Empty, result); + } + private sealed class RejectingSmtpClientFactory : ISmtpClientFactory { public Yavsc.Interfaces.ISmtpClient CreateClient() => new RejectingSmtpClient(); From 9c0c60ebe77a9b48c9d2d47032605e453005d52e Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 21 Oct 2026 12:24:11 +0100 Subject: [PATCH 2/2] Podcast from Android --- CHANGELOG.md | 3 +++ src/PostIt/PostIt.Android/Application.cs | 2 ++ src/PostIt/PostIt.Browser/Program.cs | 8 +++++++- src/PostIt/PostIt.Desktop/Program.cs | 1 + src/PostIt/PostIt/Services/Platform.cs | 2 ++ src/PostIt/PostIt/ViewModels/Layout/HomePageViewModel.cs | 3 ++- 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccb987447..19874f11a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ ### Fixed +* Podcast availability from Android +* avoid NRE in MailSender on rdv query notifications + ## [1.0.8-rc29] - unstable ### Added diff --git a/src/PostIt/PostIt.Android/Application.cs b/src/PostIt/PostIt.Android/Application.cs index 040b01ca3..d8d758579 100644 --- a/src/PostIt/PostIt.Android/Application.cs +++ b/src/PostIt/PostIt.Android/Application.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.DependencyInjection; using Avalonia.Controls; using Avalonia.Styling; using Yavsc.Api.Client; +using PostIt.Services; [assembly: UsesPermission(Manifest.Permission.AccessFineLocation)] [assembly: UsesPermission(Manifest.Permission.AccessCoarseLocation)] @@ -20,6 +21,7 @@ namespace PostIt.Android { protected Application(nint javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { + Platform.IsPodcastSupported = true; } protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) diff --git a/src/PostIt/PostIt.Browser/Program.cs b/src/PostIt/PostIt.Browser/Program.cs index f91cc4eec..e1d1672aa 100644 --- a/src/PostIt/PostIt.Browser/Program.cs +++ b/src/PostIt/PostIt.Browser/Program.cs @@ -2,15 +2,21 @@ using Avalonia; using Avalonia.Browser; using PostIt; +using PostIt.Services; internal sealed partial class Program { - private static Task Main(string[] args) => BuildAvaloniaApp() + private static Task Main(string[] args) + { + Platform.IsPodcastSupported = false; + + return BuildAvaloniaApp() .WithInterFont() #if DEBUG .WithDeveloperTools() #endif .StartBrowserAppAsync("out"); + } public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure(); diff --git a/src/PostIt/PostIt.Desktop/Program.cs b/src/PostIt/PostIt.Desktop/Program.cs index 1c5aa0c27..af8867141 100644 --- a/src/PostIt/PostIt.Desktop/Program.cs +++ b/src/PostIt/PostIt.Desktop/Program.cs @@ -13,6 +13,7 @@ sealed class Program [STAThread] public static void Main(string[] args) { + Platform.IsPodcastSupported = true; CLIOptionHandler.HandleArgs(args); // Short-circuit 2nd-instance launches (OS handing us the diff --git a/src/PostIt/PostIt/Services/Platform.cs b/src/PostIt/PostIt/Services/Platform.cs index 78646c886..85a5026f5 100644 --- a/src/PostIt/PostIt/Services/Platform.cs +++ b/src/PostIt/PostIt/Services/Platform.cs @@ -57,4 +57,6 @@ public static class Platform /// public static Func> TryGetCurrentLocationAsync { get; set; } = _ => Task.FromResult(CurrentLocationResult.Unavailable()); + + public static bool IsPodcastSupported { get; set; } = false; } diff --git a/src/PostIt/PostIt/ViewModels/Layout/HomePageViewModel.cs b/src/PostIt/PostIt/ViewModels/Layout/HomePageViewModel.cs index d2e023fd4..c801806d2 100644 --- a/src/PostIt/PostIt/ViewModels/Layout/HomePageViewModel.cs +++ b/src/PostIt/PostIt/ViewModels/Layout/HomePageViewModel.cs @@ -12,6 +12,7 @@ using PostIt.ViewModels.Chat; using Yavsc.Abstract.Models.Messaging; using Yavsc.Api.Client; + namespace PostIt.ViewModels; public class HomePageViewModel : ViewModelBase @@ -86,7 +87,7 @@ public class HomePageViewModel : ViewModelBase public IAsyncRelayCommand OpenChat { get; } public IAsyncRelayCommand OpenPodcasts { get; } - public bool SupportsPodcasts => OperatingSystem.IsWindows() || OperatingSystem.IsLinux(); + public bool SupportsPodcasts => Platform.IsPodcastSupported; public IAsyncRelayCommand OpenBlogs { get; } public IAsyncRelayCommand OpenProfile { get; } public IAsyncRelayCommand OpenPerformerConfiguration { get; }