当前位置: 首页>>代码示例>>C#>>正文


C# Message.Save方法代码示例

本文整理汇总了C#中OpenPop.Mime.Message.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Message.Save方法的具体用法?C# Message.Save怎么用?C# Message.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenPop.Mime.Message的用法示例。


在下文中一共展示了Message.Save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MessageToString

        public static string MessageToString(Message message)
        {
            using (var stream = new MemoryStream())
            {
                message.Save(stream);
                stream.Position = 0;
                var reader = new StreamReader(stream);

                return reader.ReadToEnd();
            }
        }
开发者ID:risedphantom,项目名称:TopCrawler,代码行数:11,代码来源:Functions.cs

示例2: SaveAndLoadFullMessage

        //public static void sendEmail(string reciverMail, string senderMail, string subject, string textBody, string mailPassword, string CC)
        //{
        //    SmtpClient c = new SmtpClient(@"smtp.live.com", 25);
        //    MailAddress add = new MailAddress(reciverMail);
        //    MailMessage msg = new MailMessage();
        //    msg.To.Add(add);
        //    msg.From = new MailAddress(senderMail);
        //    msg.IsBodyHtml = true;
        //    msg.Subject = subject;
        //    msg.Body = textBody;
        //    c.Credentials = new System.Net.NetworkCredential(senderMail, mailPassword);
        //    c.EnableSsl = true;
        //    c.Send(msg);
        //}
        /// <summary>
        /// Example showing:
        ///  - how to save a message to a file
        ///  - how to load a message from a file at a later point
        /// </summary>
        /// <param name="mail">The message to save and load at a later point</param>
        /// <returns>The Message, but loaded from the file system</returns>
        public static Message SaveAndLoadFullMessage(Message mail)
        {
            // FileInfo about the location to save/load message
            FileInfo file = new FileInfo("someFile.eml");

            // Save the full message to some file
            mail.Save(file);

            // Now load the message again. This could be done at a later point
            Message loadedMessage = Message.Load(file);

            // use the message again
            return loadedMessage;
        }
开发者ID:karlog100,项目名称:Programmering-3,代码行数:35,代码来源:Mail.cs

示例3: TestFileOverwriteTruncatesFileCorrectly

        public void TestFileOverwriteTruncatesFileCorrectly()
        {
            const string longMessage = "Content-Type: text/plain\r\n" +
                "Content-Disposition: attachment\r\n" +
                "\r\n" +
                "Testing very long...";

            const string smallMessage =
                "Content-Type: text/plain\r\n" +
                "Content-Disposition: attachment\r\n" +
                "\r\n" +
                "Testing";

            const string filename = "test_message_part_save_truncate.testFile";

            FileInfo longTestFile = new FileInfo(filename);
            MessagePart messageLong = new Message(Encoding.ASCII.GetBytes(longMessage)).MessagePart;
            messageLong.Save(longTestFile);
            long longFileSize = longTestFile.Length;

            FileInfo smallTestFile = new FileInfo(filename);
            MessagePart messageSmall = new Message(Encoding.ASCII.GetBytes(smallMessage)).MessagePart;
            messageSmall.Save(smallTestFile);
            long smallFileSize = smallTestFile.Length;

            smallTestFile.Delete();

            Assert.AreNotEqual(longFileSize, smallFileSize);
        }
开发者ID:JoshKeegan,项目名称:hpop,代码行数:29,代码来源:MessagePartTests.cs

示例4: addMessage

        void addMessage(Message message, bool unread, int group, int image)
        {
            //Add the messages to the chosen directory
            messages.Add(message.Headers.MessageId, message);

            ListViewItem newItem = new ListViewItem();

            newItem.Text = message.Headers.From.ToString();
            newItem.SubItems.Add(message.Headers.Subject);
            newItem.SubItems.Add(message.Headers.DateSent.ToString("yyyy-MM-dd HH:mm:ss"));
            newItem.Tag = message.Headers.MessageId;
            newItem.Group = mailView.Groups[group];
            newItem.ImageIndex = image;

            if (unread)
            {

                newItem.Font = new Font(newItem.Font, FontStyle.Bold);
            }

            AddMailToView(newItem);

            if (!File.Exists(Application.UserAppDataPath + "\\Inbox\\" + message.Headers.DateSent.ToString("yyyyMMddHHmmssfffffff") + ".eml"))
            {
                message.Save(new FileInfo(Application.UserAppDataPath + "\\Inbox\\" + message.Headers.DateSent.ToString("yyyyMMddHHmmssfffffff") + ".eml"));
            }
        }
开发者ID:ComputerSimp,项目名称:MailClient,代码行数:27,代码来源:MailClient.cs

示例5: TestFileOverwriteTruncatesFileCorrectly

        public void TestFileOverwriteTruncatesFileCorrectly()
        {
            const string longMessage = "Content-Type: text/plain\r\n" +
                "Content-Disposition: attachment\r\n" +
                "\r\n" +
                "Testing very long...";

            const string smallMessage =
                "Content-Type: text/plain\r\n" +
                "Content-Disposition: attachment\r\n" +
                "\r\n" +
                "Testing";

            FileInfo testFile = new FileInfo("test_message_save_truncate.testFile");

            Message messageLong = new Message(Encoding.ASCII.GetBytes(longMessage));
            messageLong.Save(testFile);

            Message messageSmall = new Message(Encoding.ASCII.GetBytes(smallMessage));
            messageSmall.Save(testFile);

            Message messageLoaded = Message.Load(testFile);

            testFile.Delete();

            // We should now have the small message in the file.
            // IE We should have overwritten the longMessage file with our shortMessage file.
            Assert.AreEqual(messageSmall.RawMessage, messageLoaded.RawMessage);
        }
开发者ID:bitspill,项目名称:Gridcoin-master,代码行数:29,代码来源:MessageTest.cs

示例6: TestSaveAndLoadComplex

        public void TestSaveAndLoadComplex()
        {
            const string rfcExample =
                "From: Nathaniel Borenstein <[email protected]>\r\n" +
                "To: Ned Freed <[email protected]>\r\n" +
                "Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\r\n" +
                "Subject: Sample message\r\n" +
                "MIME-Version: 1.0\r\n" +
                "Content-type: multipart/mixed; boundary=\"simple boundary\"\r\n" +
                "\r\n" +
                "--simple boundary\r\n" +
                "Content-type: multipart/mixed; boundary=\"anotherBoundary\"\r\n" +
                "\r\n" +
                "--anotherBoundary\r\n" +
                "\r\n" +
                "TEXT\r\n" +
                "--anotherBoundary\r\n" +
                "Content-Type: text/html; charset=us-ascii\r\n" +
                "\r\n" +
                "HTML\r\n" +
                "--anotherBoundary--\r\n" +
                "--simple boundary\r\n" +
                "Content-type: text/html; charset=ISO-8859-1\r\n" +
                "\r\n" +
                "MORE HTML\r\n" +
                "--simple boundary--";

            Message message = new Message(Encoding.ASCII.GetBytes(rfcExample));

            {
                System.Collections.Generic.List<MessagePart> parts = message.FindAllMessagePartsWithMediaType("multipart/mixed");

                Assert.NotNull(parts);
                Assert.IsNotEmpty(parts);
                Assert.AreEqual(2, parts.Count);

                MessagePart firstPart = parts[0];
                Assert.IsTrue(firstPart.IsMultiPart);
                Assert.AreEqual("multipart/mixed", firstPart.ContentType.MediaType);
                Assert.AreEqual("simple boundary", firstPart.ContentType.Boundary);

                MessagePart secondPart = parts[1];
                Assert.IsTrue(secondPart.IsMultiPart);
                Assert.AreEqual("multipart/mixed", secondPart.ContentType.MediaType);
                Assert.AreEqual("anotherBoundary", secondPart.ContentType.Boundary);
            }

            FileInfo testFile = new FileInfo("test_message_save_.testFile");
            message.Save(testFile);

            Message message2 = Message.Load(testFile);
            {
                System.Collections.Generic.List<MessagePart> parts2 = message2.FindAllMessagePartsWithMediaType("multipart/mixed");

                Assert.NotNull(parts2);
                Assert.IsNotEmpty(parts2);
                Assert.AreEqual(2, parts2.Count);

                MessagePart firstPart2 = parts2[0];
                Assert.IsTrue(firstPart2.IsMultiPart);
                Assert.AreEqual("multipart/mixed", firstPart2.ContentType.MediaType);
                Assert.AreEqual("simple boundary", firstPart2.ContentType.Boundary);

                MessagePart secondPart2 = parts2[1];
                Assert.IsTrue(secondPart2.IsMultiPart);
                Assert.AreEqual("multipart/mixed", secondPart2.ContentType.MediaType);
                Assert.AreEqual("anotherBoundary", secondPart2.ContentType.Boundary);
            }

            testFile.Delete();
        }
开发者ID:bitspill,项目名称:Gridcoin-master,代码行数:71,代码来源:MessageTest.cs

示例7: TestSaveAndLoad

        public void TestSaveAndLoad()
        {
            const string messageString =
                "Content-Type: text/plain\r\n" +
                "Content-Disposition: attachment\r\n" +
                "\r\n" +
                "Testing";

            Message message = new Message(Encoding.ASCII.GetBytes(messageString));

            FileInfo testFile = new FileInfo("test_message_save_.testFile");

            message.Save(testFile);

            Message message2 = Message.Load(testFile);

            Assert.AreEqual("Testing", message.MessagePart.GetBodyAsText());
            Assert.AreEqual("Testing", message2.MessagePart.GetBodyAsText());

            Assert.AreEqual("text/plain", message.Headers.ContentType.MediaType);
            Assert.AreEqual("text/plain", message2.Headers.ContentType.MediaType);

            Assert.IsFalse(message.Headers.ContentDisposition.Inline);
            Assert.IsFalse(message2.Headers.ContentDisposition.Inline);

            testFile.Delete();
        }
开发者ID:bitspill,项目名称:Gridcoin-master,代码行数:27,代码来源:MessageTest.cs


注:本文中的OpenPop.Mime.Message.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。