Skip to content

Commit 699eb97

Browse files
authored
Update MessageRelayStore.cs
1 parent 7470731 commit 699eb97

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/SmtpRelay/MessageRelayStore.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
/* MessageRelayStore.cs – tested .NET 8 + MailKit 4.11 – July 8 2025 */
1+
/* MessageRelayStore.cs – .NET 8 + MailKit 4.11 – FINAL */
22
using System;
33
using System.Buffers;
44
using System.Collections;
5+
using System.Collections.Generic;
56
using System.IO;
67
using System.Net;
78
using System.Reflection;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using Microsoft.Extensions.Logging;
12+
using MailKit;
1113
using MailKit.Net.Smtp;
1214
using MailKit.Security;
13-
using MailKit;
1415
using MimeKit;
1516
using NetTools;
1617
using SmtpServer;
@@ -41,11 +42,13 @@ public override async Task<SmtpResponse> SaveAsync(
4142
}
4243
_log.LogInformation("Incoming relay request from {IP}", clientIp);
4344

45+
// rebuild MimeMessage
4446
using var ms = new MemoryStream();
4547
foreach (var seg in buf) ms.Write(seg.Span);
4648
ms.Position = 0;
4749
var message = MimeMessage.Load(ms);
4850

51+
// logs beside service EXE
4952
var logDir = Path.Combine(AppContext.BaseDirectory, "logs");
5053
Directory.CreateDirectory(logDir);
5154
var protoPath = Path.Combine(logDir, $"smtp-{DateTime.Now:yyyyMMdd}.log");
@@ -59,7 +62,8 @@ public override async Task<SmtpResponse> SaveAsync(
5962

6063
await smtp.ConnectAsync(
6164
_cfg.SmartHost, _cfg.SmartHostPort,
62-
_cfg.UseStartTls ? SecureSocketOptions.StartTlsWhenAvailable : SecureSocketOptions.None,
65+
_cfg.UseStartTls ? SecureSocketOptions.StartTlsWhenAvailable
66+
: SecureSocketOptions.None,
6367
cancel);
6468

6569
if (!string.IsNullOrWhiteSpace(_cfg.Username))
@@ -93,8 +97,8 @@ public MinimalProtocolLogger(string path)
9397
}
9498

9599
/* MailKit 4.11+ requirement */
96-
public IAuthenticationSecretDetector AuthenticationSecretDetector { get; set; } =
97-
new NoSecretDetector();
100+
public IAuthenticationSecretDetector AuthenticationSecretDetector { get; set; }
101+
= new NoSecretDetector();
98102

99103
public void LogConnect(Uri uri) =>
100104
_sw.WriteLine($"[{DateTime.Now:HH:mm:ss}] CONNECT {uri}");
@@ -120,10 +124,12 @@ public void LogServer(byte[] buffer, int offset, int count)
120124

121125
public void Dispose() { _sw.Flush(); _sw.Dispose(); }
122126

127+
/* no-op detector – returns empty list */
123128
private sealed class NoSecretDetector : IAuthenticationSecretDetector
124129
{
125130
public bool IsSecret(string text) => false;
126-
public bool DetectSecrets(byte[] buffer, int offset, int count) => false;
131+
public IList<AuthenticationSecret> DetectSecrets(byte[] buffer, int offset, int count)
132+
=> Array.Empty<AuthenticationSecret>();
127133
}
128134
}
129135

0 commit comments

Comments
 (0)