private void SendServerReady() { var response = ServerStatusCodesConverter.GetTextResponseForStatus(ResponseCodes.SrvReady, _clientController.HostName); _clientController.Write(response); }
public SmtpServerClientProcessor(ITcpClientController clientController, ILogger logger) { _clientController = clientController; EmailParser = new EmailParser(); RequestCommandsConverter = new RequestCommandsConverter(); ServerStatusCodesConverter = new ServerStatusCodesConverter(); Logger = logger; }
private bool HandleHello(MailMessage message, string nextLine) { var responseStatus = _clientController.IsTlsAvailable ? ResponseCodes.SrvHello : ResponseCodes.SrvHelloNoTls; var response = ServerStatusCodesConverter.GetTextResponseForStatus(responseStatus, _clientController.HostName); _clientController.Write(response); return(false); }
private bool HandleMailFrom(MailMessage message, string nextLine) { MailAddress sender; try { sender = EmailParser.ParseEmailFromString(nextLine); } catch { _clientController.Write(ServerStatusCodesConverter.GetTextResponseForStatus(ResponseCodes.MbNameNotAllowed)); return(true); } message.From = sender; _clientController.Write(ServerStatusCodesConverter.GetTextResponseForStatus(ResponseCodes.RqstActOkCompleted)); return(false); }
private bool SwitchToTls(MailMessage message, string nextLine) { _clientController.Write(ServerStatusCodesConverter.GetTextResponseForStatus(ResponseCodes.SrvReady, _clientController.HostName)); try { _clientController.SwitchToTlsProtocol(); } catch (Exception e) { Logger.LogError(string.Format("Exception occurred while switching to TLS:\n{0}", e.Message)); if (e.InnerException != null) { Logger.LogError(string.Format("Inner exception: {0}\n", e.InnerException.Message)); } _clientController.Write(ServerStatusCodesConverter.GetTextResponseForStatus(ResponseCodes.AccessDenied)); return(true); } return(false); }
private bool HandleDataSection(MailMessage message, string nextLine) { _clientController.Write(ServerStatusCodesConverter.GetTextResponseForStatus(ResponseCodes.StrtInputEndWith)); var messageData = new StringBuilder(); var strMessage = _clientController.Read(); _clientController.Write(ServerStatusCodesConverter.GetTextResponseForStatus(ResponseCodes.RqstActOkCompleted)); while (!strMessage.Contains("\r\n.\r\n")) //Contains because some times QUIT is added right to the body { messageData.Append(strMessage); strMessage = _clientController.Read(); } messageData.Append(strMessage); var msgDataStr = messageData.ToString(); var headers = EmailParser.ParseHeadersFromDataSection(msgDataStr); var parsedCcList = EmailParser.ParseEmailsFromDataCc(headers); var parsedToList = EmailParser.ParseEmailsFromDataTo(headers); var parsedFromList = EmailParser.ParseEmailsFromDataFrom(headers); var toList = MergeToList(message.To, parsedToList, parsedCcList); message.To = toList; message.CC = parsedCcList; message.From = GetMailAddressesByAddress(message.From, parsedFromList); message.Body = EmailParser.ParseBodyFromDataSection(msgDataStr); message.Subject = EmailParser.ParseSubjectFromDataSection(headers); message.Headers = headers; message.IsBodyHtml = EmailParser.GetIsMailBodyHtml(headers); message.MailMessageDataSection = msgDataStr.Trim(); _clientController.Write(ServerStatusCodesConverter.GetTextResponseForStatus(ResponseCodes.RqstActOkCompleted)); return(ClientHasEndedSendingMail(msgDataStr)); }
private bool HandleMailTo(MailMessage message, string nextLine) { MailAddress recipient; try { recipient = EmailParser.ParseEmailFromString(nextLine); } catch { _clientController.Write(ServerStatusCodesConverter.GetTextResponseForStatus(ResponseCodes.MbNameNotAllowed)); return(true); } if (message.To.All(a => a.Address != recipient.Address)) { message.To.Add(recipient); } _clientController.Write(ServerStatusCodesConverter.GetTextResponseForStatus(ResponseCodes.RqstActOkCompleted)); return(false); }