Skip to content

Commit

Permalink
Added more logging to the email forwarding process in support of #464.
Browse files Browse the repository at this point in the history
  • Loading branch information
uncheckederror committed Nov 16, 2024
1 parent 75a23bf commit 2188ffc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Messaging/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2208,10 +2208,10 @@ public static async Task<ReadOnlyMemory<InboundEmail>> 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<InboundEmail> 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");
Expand Down
10 changes: 6 additions & 4 deletions Messaging/TimedHostedService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using MailKit.Net.Pop3;

using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.EntityFrameworkCore;

using Models;
Expand Down Expand Up @@ -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<SendMessageResponse>);
text = string.IsNullOrWhiteSpace(text) ? System.Text.Json.JsonSerializer.Serialize(response.Result as BadRequest<SendMessageResponse>) : text;
_logger.LogInformation("[Background Worker] Send Message Response: {text}", text);
}
}
}

0 comments on commit 2188ffc

Please sign in to comment.