示例#1
0
        /// <summary>
        /// Parse each header type for each line in the email message.
        /// </summary>
        /// <param name="lines">The array of lines in the email message.</param>
        /// <returns>The start of the message body.</returns>
        private long ParseHeader(string[] lines)
        {
            // Get the total number of lines
            // and set the body start count to
            // zero.
            int  numberOfLines = lines.Length;
            long bodyStart     = 0;

            // For each line in the email message
            // parse all headers required.
            for (int i = 0; i < numberOfLines; i++)
            {
                // Get the current email line.
                string currentLine = lines[i].Replace("\n", "");

                // Get the current line header type.
                Nequeo.Net.Mail.MesssageHeaderType lineType = GetHeaderType(currentLine);

                // Get each haeder type.
                switch (lineType)
                {
                case Nequeo.Net.Mail.MesssageHeaderType.From:
                    // From email message.
                    _from = EmailMessageParse.From(currentLine);
                    break;

                case Nequeo.Net.Mail.MesssageHeaderType.Subject:
                    // Subject of the message.
                    _subject = EmailMessageParse.Subject(currentLine);
                    break;

                case Nequeo.Net.Mail.MesssageHeaderType.To:
                    // To email message.
                    _to = EmailMessageParse.To(currentLine);
                    break;

                case Nequeo.Net.Mail.MesssageHeaderType.ReplyTo:
                    // Reply to email message.
                    _replyTo = EmailMessageParse.ReplyTo(currentLine);
                    break;

                case Nequeo.Net.Mail.MesssageHeaderType.Date:
                    // Date received message.
                    _date = EmailMessageParse.Date(currentLine);
                    break;

                case Nequeo.Net.Mail.MesssageHeaderType.Organization:
                    // The orginization that sent the message.
                    _organization = EmailMessageParse.Organization(currentLine);
                    break;

                case Nequeo.Net.Mail.MesssageHeaderType.ReturnPath:
                    // The email address return path.
                    _returnPath = EmailMessageParse.ReturnPath(currentLine);
                    break;

                case Nequeo.Net.Mail.MesssageHeaderType.Received:
                    // The computers that sent and recevied the message.
                    _received += EmailMessageParse.Received(currentLine);
                    break;

                case Nequeo.Net.Mail.MesssageHeaderType.Cc:
                    // The carbon copy email address.
                    _cc = EmailMessageParse.Cc(currentLine);
                    break;

                case Nequeo.Net.Mail.MesssageHeaderType.Bcc:
                    // The blind carbon copy email address.
                    _bcc = EmailMessageParse.Bcc(currentLine);
                    break;

                case Nequeo.Net.Mail.MesssageHeaderType.Priority:
                    // The email message priority.
                    _priority = EmailMessageParse.Priority(currentLine);
                    break;

                case Nequeo.Net.Mail.MesssageHeaderType.Importance:
                    // The importance of the message.
                    _importance = EmailMessageParse.Importance(currentLine);
                    break;

                case Nequeo.Net.Mail.MesssageHeaderType.ContentType:
                    // The content type of the message
                    // that has been specified (text, html etc..).
                    _contentType = EmailMessageParse.ContentType(currentLine);

                    // Is multi part, that is are
                    // attachments included.
                    _isMultipart = EmailMessageParse.IsMultipart(_contentType);

                    // If multipart.
                    if (_isMultipart)
                    {
                        // Boundary has been found
                        // for the attachments.
                        if (_contentType.Substring(_contentType.Length - 1, 1).Equals(";"))
                        {
                            // Increament the line index by one
                            // move to the next line.
                            ++i;

                            // Get the boundary data from the message.
                            _multipartBoundary = EmailMessageParse.MultipartBoundary(lines[i].Replace("\n", ""));
                        }
                        else
                        {
                            // Boundary definition is on same
                            // line as Content-Type.
                            _multipartBoundary = EmailMessageParse.MultipartBoundary(_contentType);
                        }
                    }

                    break;

                case Nequeo.Net.Mail.MesssageHeaderType.EndOfHeader:
                    // The end of all message headers has been
                    // found so the next data is the body of the
                    // message increment the body start index.
                    bodyStart = i + 1;
                    break;
                }

                // If the body index is greater than
                // zero then end of headers has been
                // for and the body of the message
                // has started, break out of the loop.
                if (bodyStart > 0)
                {
                    break;
                }
            }

            // Return the start of the body.
            return(bodyStart);
        }