Exemple #1
0
		/// <summary>
		/// Example showing:
		///  - how to find a MessagePart with a specified MediaType
		///  - how to get the body of a MessagePart as a string
		/// </summary>
		/// <param name="message">The message to examine for xml</param>
		public static void FindXmlInMessage(Message message)
		{
			MessagePart xml = message.FindFirstMessagePartWithMediaType("text/xml");
			if (xml != null)
			{
				// Get out the XML string from the email
				string xmlString = xml.GetBodyAsText();

				System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

				// Load in the XML read from the email
				doc.LoadXml(xmlString);

				// Save the xml to the filesystem
				doc.Save("test.xml");
			}
		}
        public void TestGetFirstMessageWithMediaTypeSimpleNotFound()
        {
            const string rfcExample =
                "Content-type: text/plain; charset=us-ascii\r\n" +
                "\r\n" +
                "This is explicitly typed plain US-ASCII text";

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

            MessagePart part = message.FindFirstMessagePartWithMediaType("text/html");

            // We should not be able to find such a MessagePart
            Assert.Null(part);
        }
        public void TestGetFirstMessageWithMediaTypeSimpleFoundHTML()
        {
            const string rfcExample =
                "Content-type: text/html; charset=us-ascii\r\n" +
                "\r\n" +
                "This is explicitly typed plain US-ASCII HTML text";

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

            MessagePart part = message.FindFirstMessagePartWithMediaType("text/html");

            Assert.NotNull(part);
            Assert.AreEqual("text/html", part.ContentType.MediaType);
            Assert.AreEqual("us-ascii", part.ContentType.CharSet);
            Assert.AreEqual(Encoding.ASCII, part.BodyEncoding);
            Assert.AreEqual("This is explicitly typed plain US-ASCII HTML text", part.GetBodyAsText());
        }
        public void TestGetFirstMessageWithMediaTypeMultiPartFoundSecond()
        {
            const string rfcExample =
                "From: Nathaniel Borenstein <*****@*****.**>\r\n" +
                "To: Ned Freed <*****@*****.**>\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" +
                "\r\n" +
                "TEXT\r\n" +
                "--simple boundary\r\n" +
                "Content-type: text/html; charset=ISO-8859-1\r\n" +
                "\r\n" +
                "HTML\r\n" +
                "--simple boundary--";

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

            MessagePart part = message.FindFirstMessagePartWithMediaType("text/html");

            Assert.NotNull(part);
            Assert.AreEqual("text/html", part.ContentType.MediaType);
            Assert.AreEqual("ISO-8859-1", part.ContentType.CharSet);
            Assert.AreEqual(Encoding.GetEncoding("ISO-8859-1"), part.BodyEncoding);
            Assert.AreEqual("HTML", part.GetBodyAsText());
        }
        public void TestGetFirstMessageWithMediaTypeMultiPartFindMultiPartMediaTypeWithNestedMultiPart()
        {
            const string rfcExample =
                "From: Nathaniel Borenstein <*****@*****.**>\r\n" +
                "To: Ned Freed <*****@*****.**>\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" +
                "\r\n" +
                "MORE TEXT\r\n" +
                "--anotherBoundary--\r\n" +
                "--simple boundary\r\n" +
                "Content-type: text/html; charset=ISO-8859-1\r\n" +
                "\r\n" +
                "HTML\r\n" +
                "--simple boundary--";

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

            MessagePart part = message.FindFirstMessagePartWithMediaType("multipart/mixed");

            Assert.NotNull(part);
            Assert.IsTrue(part.IsMultiPart);
            Assert.AreEqual("simple boundary", part.ContentType.Boundary);
        }
Exemple #6
0
        private void button11_Click(object sender, EventArgs e)
        {
            dt = new DataTable("Inbox");
            dt.Columns.Add("ID");
            dt.Columns.Add("Temat");
            dt.Columns.Add("Sender");
            dt.Columns.Add("Email");
            dt.Columns.Add("Tekst");
            dt.Columns.Add("Czas");
            dataGridView1.DataSource = dt;

            try
            {
                client.Connect(comboBox5.Text, 995, true);
                client.Authenticate(textBox6.Text, textBox5.Text, OpenPop.Pop3.AuthenticationMethod.UsernameAndPassword);
                int count = client.GetMessageCount();

                string htmlContained = "";



                if (client.Connected)
                {
                    //   for (int i = count; i > count - 100 && i >= 0; i--)
                    //     for (int i = 1;  i <=100 && i <= count; i--)
                    //  for (int i = 1; i <= count && i <= 100 ; i++)
                    // for (int i = count; i >= 100; i--)


                    for (int i = count; i > count - Convert.ToInt32(textBox4.Text) && i >= 1; i--)
                    {
                        OpenPop.Mime.Message message = client.GetMessage(i);


                        OpenPop.Mime.MessagePart html = message.FindFirstHtmlVersion();
                        OpenPop.Mime.MessagePart file = message.FindFirstMessagePartWithMediaType("");


                        if (html != null)
                        {
                            htmlContained = html.GetBodyAsText();
                        }
                        else
                        {
                            html = message.FindFirstPlainTextVersion();

                            htmlContained = html.GetBodyAsText();
                        }

                        string name = message.Headers.Subject;
                        if (name == "")
                        {
                            name = "Brak Tematu";
                        }

                        string nadawca = message.Headers.From.DisplayName;

                        if (nadawca == "")
                        {
                            nadawca = "Brak Informacji";
                        }

                        dt.Rows.Add(new object[] { i.ToString(), name.ToString(), nadawca.ToString(), message.Headers.From.Address, htmlContained, message.Headers.DateSent });
                    }
                }
                client.Disconnect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }