示例#1
0
 /// <summary>
 /// Tests if this message contains a wrapped RFC 5322 message
 /// </summary>
 /// <param name="message">The message to test</param>
 /// <returns><c>true</c> if the message contains a wrapped RFC 5322 message, <c>false</c> otherwise</returns>
 public static bool IsWrapped(Message message)
 {
     if (message == null)
     {
         return false;
     }
     
     return message.HasMediaType(MailStandard.MediaType.WrappedMessage);
 }
示例#2
0
        public static void Send(this Health.Direct.Common.Mail.Message message, string smtpServer, int port)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (string.IsNullOrEmpty(smtpServer))
            {
                throw new ArgumentException("smtpServer");
            }

            CDO.Message cdoMessage = LoadCDOMessageFromText(MimeSerializer.Default.Serialize(message));
            cdoMessage.Send(smtpServer, port);
        }
示例#3
0
        public void ShouldDoBasicRoundTrip()
        {
            Message m = new Message();
            m.To = new Header("To", "*****@*****.**");
            m.Subject = new Header("Subject", "Hello, world!");
            m.Body = new Body("This is a test.");

            string messageText = MimeSerializer.Default.Serialize(m);
            Message m2 = MailParser.ParseMessage(messageText);
            // TODO: Perhaps body is inserting a CRLF?
            Assert.Equal("This is a test.", m2.Body.Text.Trim());
            Assert.Equal("*****@*****.**", m2.To.Value);
            Assert.Equal("Hello, world!", m2.Subject.Value);
        }
示例#4
0
        /// <summary>
        /// Creates a wrapped message, copying headers
        /// </summary>
        /// <param name="message">A string containing the RFC 5322 message to wrap</param>
        /// <param name="headersToCopy">The headers that will be copied into the wrapped message</param>
        /// <returns></returns>
        public static Message Create(string message, string[] headersToCopy)
        {
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentException("value was null or empty", "message");
            }
            
            Message wrappedMessage = new Message();
            wrappedMessage.Headers.Add(MimeSerializer.Default.DeserializeHeaders(message), headersToCopy);
            wrappedMessage.Body = new Body(message);
            wrappedMessage.ContentType = MailStandard.MediaType.WrappedMessage;

            return wrappedMessage;
        }
示例#5
0
 /// <summary>
 /// Creates a wrapped message, copying headers
 /// </summary>
 /// <param name="message">The message to wrap</param>
 /// <param name="headersToCopy">The headers that will be copied into the wrapped message</param>
 /// <returns></returns>
 public static Message Create(Message message, string[] headersToCopy)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     
     Message wrappedMessage = new Message();
     if (message.HasHeaders)
     {
         wrappedMessage.Headers.Add(message.Headers, headersToCopy);
     }            
     wrappedMessage.Body = new Body(MimeSerializer.Default.Serialize(message));
     wrappedMessage.ContentType = MailStandard.MediaType.WrappedMessage;
     
     return wrappedMessage;
 }
示例#6
0
 internal void ProcessEndToEnd(SmtpAgent agent, Message msg, out OutgoingMessage outgoing, out IncomingMessage incoming)
 {
     outgoing = agent.SecurityAgent.ProcessOutgoing(new MessageEnvelope(msg));
     incoming = agent.SecurityAgent.ProcessIncoming(new MessageEnvelope(outgoing.SerializeMessage()));            
 }
示例#7
0
 public void TestIsTimelyAndRequired_MDNOptionForTimely_assertTrue()
 {
     Message message = new Message("*****@*****.**", "*****@*****.**", "Test message");
     message.Headers.Add(MDNStandard.Headers.DispositionNotificationOptions, MDNStandard.DispositionOption_TimelyAndReliable);
     Assert.True(message.IsTimelyAndReliable());
 }
示例#8
0
 public void TestIsTimelyAndRequired_NoMNDOptionDetails_assertFalse()
 {
     Message message = new Message();
     message.From = new Header("from", "*****@*****.**");
     Assert.False(message.IsTimelyAndReliable());
 }
示例#9
0
 public void TestIsTimelyAndRequired_nullMimeMessage_assertFalse()
 {
     Message message = new Message();
     Assert.False(message.IsTimelyAndReliable());
 }
示例#10
0
 public static void Send(this Health.Direct.Common.Mail.Message message, string smtpServer)
 {
     message.Send(smtpServer, -1);
 }
示例#11
0
        public void CheckDate()
        {
            Message m = new Message();
            m.To = new Header("To", "*****@*****.**");
            m.Subject = new Header("Subject", "Hello, world!");
            m.Body = new Body("This is a test.");
            
            m.Timestamp();
            Assert.True(m.HasHeader(MailStandard.Headers.Date));

            string messageText = MimeSerializer.Default.Serialize(m);
            Message m2 = MailParser.ParseMessage(messageText);
            Assert.True(m.HasHeader(MailStandard.Headers.Date));
        }
示例#12
0
 /// <summary>
 /// Creates a detatched signed entity from a message and a collection of signing certificate
 /// </summary>
 /// <remarks>
 /// Cryptography is performed only on the Mime portions of the message, not the RFC822 headers
 /// Some mail readers ignore the epilogue when calculating signatures!
 /// </remarks>
 /// <param name="message">The <see cref="Message"/> entity to sign</param>
 /// <param name="signingCertificates">The certificates with which to sign.</param>
 /// <returns>A <see cref="SignedEntity"/> instance holding the signatures.</returns>
 public SignedEntity Sign(Message message, X509Certificate2Collection signingCertificates)
 {
     return Sign(message.ExtractEntityForSignature(m_includeEpilogue), signingCertificates);
 }
示例#13
0
 /// <summary>
 /// Decrypts a <see cref="Message"/> with a certificate
 /// </summary>
 /// <param name="message">The <see cref="Message"/> to decrypt</param>
 /// <param name="decryptingCertificate">The <see cref="X509Certificate2"/> that encrypted the message</param>
 /// <returns>A <see cref="MimeEntity"/> holding the decrypted message</returns>
 public MimeEntity Decrypt(Message message, X509Certificate2 decryptingCertificate)
 {
     return Decrypt(message.ExtractMimeEntity(), decryptingCertificate);
 }
示例#14
0
        /// <summary>
        /// Extracts the inner message of a wrapped message as an unwrapped message
        /// </summary>
        /// <param name="message">The wrapped message</param>
        /// <returns>The unwrapped message</returns>
        /// <exception cref="MimeException">If this is not a wrapped message</exception>
        public static Message ExtractInner(Message message)
        {
            if (!IsWrapped(message))
            {
                throw new MimeException(MimeError.ContentTypeMismatch);
            }
            
            if (!message.HasBody)
            {
                throw new MimeException(MimeError.MissingBody);
            }

            StringSegment innerMessageText = DecodeBody(message);
            return MimeSerializer.Default.Deserialize<Message>(innerMessageText);
        }
示例#15
0
        static StringSegment DecodeBody(Message message)
        {
            StringSegment innerMessageText = message.Body.SourceText;
            TransferEncoding encoding = message.GetTransferEncoding();
            switch (encoding)
            {
                default:
                    throw new MimeException(MimeError.TransferEncodingNotSupported);

                case TransferEncoding.SevenBit:
                    break; // Nothing to do

                case TransferEncoding.QuotedPrintable:
                    string decodedText = QuotedPrintableDecoder.Decode(innerMessageText);
                    innerMessageText = new StringSegment(decodedText);
                    break;
                
                case TransferEncoding.Base64:
                    byte[] bytes = Convert.FromBase64String(innerMessageText.ToString());
                    string textFromBytes = Encoding.ASCII.GetString(bytes);
                    innerMessageText = new StringSegment(textFromBytes);
                    break;                    
            }
            
            return innerMessageText;
        }