diff --git a/smtpproxy.net/Email.cs b/smtpproxy.net/Email.cs index 1abe342..ef7695c 100644 --- a/smtpproxy.net/Email.cs +++ b/smtpproxy.net/Email.cs @@ -1,29 +1,47 @@ -using System.Collections.Generic; - -namespace smtpproxy.net; - -public class Email -{ - public string FromIP; - - public string sHELO; - - public string sMAIL; - - public string sDATA; - - public List sRCPTs; - - public string GetRecipientEmail(string sRCPTTo) - { - return sRCPTTo.ToLower().Replace("rcpt to:", "").Replace("<", "") - .Replace(">", "") - .Replace("\r", "") - .Replace("\n", ""); - } - - public Email() - { - sRCPTs = new List(); - } -} +using System; +using System.Collections.Generic; + +namespace smtpproxy.net +{ + public class Email + { + public string FromIP { get; set; } + public string sHELO { get; set; } + public string sMAIL { get; set; } + public string sDATA { get; set; } + public List sRCPTs { get; set; } + + public Email() + { + FromIP = string.Empty; + sHELO = string.Empty; + sMAIL = string.Empty; + sDATA = string.Empty; + sRCPTs = new List(); + } + + public string GetRecipientEmail(string sRCPTTo) + { + if (string.IsNullOrEmpty(sRCPTTo)) + return string.Empty; + + string cleaned = sRCPTTo + .Replace("\r", "") + .Replace("\n", "") + .Replace("<", "") + .Replace(">", "") + .Trim(); + + if (cleaned.StartsWith("rcpt to:", StringComparison.OrdinalIgnoreCase)) + { + cleaned = cleaned.Substring(8).Trim(); + } + else if (cleaned.StartsWith("rcpt to", StringComparison.OrdinalIgnoreCase)) + { + cleaned = cleaned.Substring(7).Trim(); + } + + return cleaned.ToLowerInvariant(); + } + } +} \ No newline at end of file