示例#1
0
        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));
        }