From 2188ffc2690086254f895bd3bad12198d186015b Mon Sep 17 00:00:00 2001 From: Thomas Ryan Date: Fri, 15 Nov 2024 20:31:34 -0800 Subject: [PATCH] Added more logging to the email forwarding process in support of #464. --- Messaging/Program.cs | 4 ++-- Messaging/TimedHostedService.cs | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Messaging/Program.cs b/Messaging/Program.cs index e83169c7..0515d954 100644 --- a/Messaging/Program.cs +++ b/Messaging/Program.cs @@ -2208,10 +2208,10 @@ public static async Task> GetEmailsAsync(string use await client.AuthenticateAsync(username, password, cls); var inbox = client.Inbox; var folder = await inbox.OpenAsync(MailKit.FolderAccess.ReadWrite, cls); - var query = SearchQuery.Recent.And(SearchQuery.NotSeen); + var query = SearchQuery.DeliveredAfter(DateTime.Now.AddHours(-3)); var recentAndUnanswered = await inbox.SearchAsync(query, cls); List emails = []; - foreach (var uid in recentAndUnanswered) + foreach (var uid in recentAndUnanswered.Where(x => x.Id is 32)) { var message = await inbox.GetMessageAsync(uid); var fromNumberStart = message.Subject.IndexOf("from 1"); diff --git a/Messaging/TimedHostedService.cs b/Messaging/TimedHostedService.cs index d071d190..8f2d0e38 100644 --- a/Messaging/TimedHostedService.cs +++ b/Messaging/TimedHostedService.cs @@ -1,5 +1,4 @@ -using MailKit.Net.Pop3; - +using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.EntityFrameworkCore; using Models; @@ -70,8 +69,11 @@ private async Task EmailToForwardedMessageAsync(EmailMessage.InboundEmail email, MediaURLs = [], Message = email.Content }; - - _ = await Endpoints.SendMessageAsync(message, false, appSettings, messagingContext); + _logger.LogInformation("[Background Worker] Send Message Request: {message}", System.Text.Json.JsonSerializer.Serialize(message)); + var response = await Endpoints.SendMessageAsync(message, false, appSettings, messagingContext); + var text = System.Text.Json.JsonSerializer.Serialize(response.Result as Ok); + text = string.IsNullOrWhiteSpace(text) ? System.Text.Json.JsonSerializer.Serialize(response.Result as BadRequest) : text; + _logger.LogInformation("[Background Worker] Send Message Response: {text}", text); } } }