示例#1
0
        public void TestFiles(string fileName)
        {
            string filePath = Path.Combine("Mail\\TestFiles", fileName);
            string mailtext = File.ReadAllText(filePath);

            Message message = null;

            Assert.DoesNotThrow(() => message = Message.Load(mailtext));

            if (SMIMEStandard.IsContentMultipartSignature(message.ParsedContentType))
            {
                SignedEntity signedEntity = null;

                Assert.DoesNotThrow(() => signedEntity = SignedEntity.Load(message));
                message.Headers = message.Headers.SelectNonMimeHeaders();
                message.UpdateBody(signedEntity.Content); // this will merge in content + content specific mime headers
            }

            Message extracted = null;

            Assert.DoesNotThrow(() => extracted = WrappedMessage.ExtractInner(message));

            Header to = null;

            Assert.DoesNotThrow(() => to = extracted.To);

            MailAddressCollection addresses = null;

            Assert.DoesNotThrow(() => addresses = MailParser.ParseAddressCollection(to));
            Assert.True(addresses.Count > 0);

            Assert.DoesNotThrow(() => MailParser.ParseMailAddress(extracted.From));
        }
示例#2
0
        public void TestEndToEnd(string messageText)
        {
            CDO.Message message = this.LoadMessage(messageText);

            string originalSubject     = message.Subject;
            string originalContentType = message.GetContentType();

            //
            // Outgoing
            //
            Assert.DoesNotThrow(() => m_handler.ProcessCDOMessage(message));

            message = this.LoadMessage(message); // re-load the message
            base.VerifyOutgoingMessage(message);
            //
            // Incoming
            //
            Assert.DoesNotThrow(() => m_handler.ProcessCDOMessage(message));

            message = this.LoadMessage(message); // re-load the message
            base.VerifyIncomingMessage(message);

            Assert.True(message.Subject.Equals(originalSubject));
            Assert.True(MimeStandard.Equals(message.GetContentType(), originalContentType));

            Message mailMessage = MailParser.ParseMessage(message.GetMessageText());
            string  header      = mailMessage.Headers.GetValue(SmtpAgent.XHeaders.Receivers);

            Assert.DoesNotThrow(() => MailParser.ParseAddressCollection(header));
            MailAddressCollection addresses = MailParser.ParseAddressCollection(header);

            Assert.True(addresses.Count > 0);
        }
        public void TestAddressCollectionFolding(int addressCount, string source)
        {
            MailAddressCollection addresses = null;

            Assert.DoesNotThrow(() => addresses = MailParser.ParseAddressCollection(source));

            string foldedText = null;

            Assert.DoesNotThrow(() => foldedText = addresses.ToStringWithFolding());
            Assert.True(!string.IsNullOrEmpty(foldedText));

            string[] foldedParts = null;
            Assert.DoesNotThrow(() => foldedParts = foldedText.Split(new string[] { MailStandard.CRLF }, StringSplitOptions.None));
            this.CheckParts(foldedParts, addressCount);
        }
示例#4
0
 /// <summary>
 /// Parse a string representation of an address list
 /// </summary>
 /// <param name="addresses">The string representation, as in a <c>To:</c> header</param>
 /// <returns>The collection corresponding to the address list.</returns>
 public static DirectAddressCollection Parse(string addresses)
 {
     return(MailParser.ParseAddressCollection <DirectAddress, DirectAddressCollection>(addresses, x => new DirectAddress(x)));
 }
示例#5
0
 public void ParseAddressCollectionFail(string source)
 {
     Assert.Throws <FormatException>(() => MailParser.ParseAddressCollection(source));
 }
示例#6
0
 public void ParseAddressCollection(int expectedCount, string source)
 {
     Assert.Equal(expectedCount, MailParser.ParseAddressCollection(source).Count);
 }
示例#7
0
 /// <summary>
 /// Gets the mail addresses contained in the <c>Disposition-Notification-To</c> header, which indicates where
 /// the original UA requested notification be sent.
 /// </summary>
 /// <param name="message">The message to get the destination from.</param>
 /// <returns>a MailAddressCollection, or null if no header was found</returns>
 public static MailAddressCollection GetNotificationDestinationAddresses(this Message message)
 {
     return(MailParser.ParseAddressCollection(message.Headers[MDNStandard.Headers.DispositionNotificationTo]));
 }