Skip to content

Commit 893f6e9

Browse files
author
Timothy Dodd
committed
Refactor email handling and processing architecture
- Removed `IEmailHandler` and `EmailMoveQueue` services. - Introduced `RuleMatcher` dependency in `BatchRuleProcessor`. - Updated `EmailMonitoringService` to directly handle email moves using a `ConcurrentQueue`. - Enhanced `ProcessExistingEmailsAsync` for batch processing. - Made `CheckForNewEmails` asynchronous for better responsiveness. - Integrated move operation functionality into `EmailMover`. - Added new classes `EmailMoveOperation` and `EmailMovedEventArgs` for improved organization.
1 parent 1a5ed58 commit 893f6e9

6 files changed

Lines changed: 97 additions & 329 deletions

File tree

src/MailZort/Program.cs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,11 @@ static async Task Main(string[] args)
3939
services.AddSingleton<MailDb>();
4040
services.AddSingleton<IBatchRuleProcessor, BatchRuleProcessor>();
4141
services.AddSingleton<IEmailMover, EmailMover>();
42-
services.AddSingleton<IEmailHandler, EmailHandler>();
42+
4343
services.AddSingleton<RuleMatcher>();
4444
services.AddSingleton(x => settingHelper);
45-
services.AddSingleton<EmailMoveQueue>(); // Singleton to share state
46-
services.AddSingleton<IEmailMoveQueue>(provider => provider.GetService<EmailMoveQueue>()!);
4745
// Register the background service
4846
services.AddHostedService<EmailMonitoringService>();
49-
50-
// Register your email handler service
51-
services.AddSingleton<IEmailHandler, EmailHandler>();
5247
})
5348
.ConfigureLogging(logging =>
5449
{
@@ -58,34 +53,6 @@ static async Task Main(string[] args)
5853
})
5954
.Build();
6055

61-
// Get services and wire up events
62-
var emailService = host.Services.GetServices<IHostedService>()
63-
.OfType<EmailMonitoringService>()
64-
.FirstOrDefault();
65-
66-
var emailHandler = host.Services.GetRequiredService<IEmailHandler>();
67-
68-
if (emailService != null)
69-
{
70-
emailService.EmailReceived += emailHandler.HandleEmailReceived;
71-
emailService.ProcessingProgress += emailHandler.HandleProcessingProgress;
72-
73-
// Wire up the new batch processing event if the handler supports it
74-
if (emailHandler is EmailHandler batchEmailHandler)
75-
{
76-
batchEmailHandler.BatchProcessingCompleted += (sender, args) =>
77-
{
78-
emailHandler.HandleBatchProcessing(sender, args);
79-
};
80-
}
81-
82-
Console.WriteLine("✅ Event handlers wired up successfully");
83-
}
84-
else
85-
{
86-
Console.WriteLine("⚠️ EmailMonitoringService not found - events not wired");
87-
}
88-
8956
Console.WriteLine("Starting email monitoring service...");
9057
Console.WriteLine("Press Ctrl+C to stop the service.");
9158

src/MailZort/Services/BatchRuleProcessor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public class BatchRuleProcessor : IBatchRuleProcessor
99
{
1010
private readonly ILogger<BatchRuleProcessor> _logger;
1111
private readonly IEnumerable<Rule> _rules;
12-
private static readonly TimeSpan RegexTimeout = TimeSpan.FromSeconds(5);
1312
private readonly RuleMatcher _ruleMatcher;
1413

1514
public BatchRuleProcessor(ILogger<BatchRuleProcessor> logger, List<Rule> rules, RuleMatcher ruleMatcher)

src/MailZort/Services/EmailHandler.cs

Lines changed: 0 additions & 143 deletions
This file was deleted.

0 commit comments

Comments
 (0)