1- /* MessageRelayStore.cs – tested .NET 8 + MailKit 4.11 – July 8 2025 */
1+ /* MessageRelayStore.cs – .NET 8 + MailKit 4.11 – FINAL */
22using System ;
33using System . Buffers ;
44using System . Collections ;
5+ using System . Collections . Generic ;
56using System . IO ;
67using System . Net ;
78using System . Reflection ;
89using System . Threading ;
910using System . Threading . Tasks ;
1011using Microsoft . Extensions . Logging ;
12+ using MailKit ;
1113using MailKit . Net . Smtp ;
1214using MailKit . Security ;
13- using MailKit ;
1415using MimeKit ;
1516using NetTools ;
1617using 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