예제 #1
0
        public void TestMimeMessage()
        {
            string[] tests = { MimeMessages.SimpleNDR, MimeMessages.BinaryNDR, MimeMessages.BrokenNDR };

            /// http://www.codeproject.com/useritems/MIME_De_Encode_in_C_.asp
            foreach (string test in tests)
            {
                MimeMessage msg = new MimeMessage();
                msg.LoadBody(test);

                ArrayList bodylist = new ArrayList();
                msg.GetBodyPartList(bodylist);

                for (int i = 0; i < bodylist.Count; i++)
                {
                    MIME.MimeBody ab = (MimeBody)bodylist[i];
                    Console.WriteLine(ab.GetType().Name);
                    Console.WriteLine(" {0}", ab.GetContentType());
                    switch (ab.GetContentType())
                    {
                    case "message/delivery-status":
                        /// TODO: move to Mime processor
                        MimeDSN dsn = new MimeDSN();
                        dsn.LoadBody(ab.GetText());
                        Console.WriteLine("ReportingMTA: {0}", dsn.ReportingMTA);
                        Console.WriteLine("ReceivedFromMTA: {0}", dsn.ReceivedFromMTA);
                        Console.WriteLine("OriginalEnvelopeId: {0}", dsn.OriginalEnvelopeId);
                        foreach (MimeDSNRecipient r in dsn.Recipients)
                        {
                            Console.WriteLine("{0}: {1}", r.Action, r.FinalRecipientEmailAddress);
                        }
                        break;
                    }
                }
            }
        }
예제 #2
0
        public void TestEmbeddedResources()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            string[] resources = assembly.GetManifestResourceNames();

            /// http://www.codeproject.com/useritems/MIME_De_Encode_in_C_.asp
            foreach (string resource in resources)
            {
                bool expected_found = false;

                if (resource.StartsWith("MIME.NET.Tests.Tests._"))
                {
                    expected_found = true;
                }
                else if (resource.StartsWith("MIME.NET.Tests.Failures._"))
                {
                    expected_found = false;
                }
                else
                {
                    continue;
                }

                Console.WriteLine(resource);

                StreamReader sr = new StreamReader(assembly.GetManifestResourceStream(resource));

                string       filename = Path.GetTempFileName();
                StreamWriter sw       = new StreamWriter(filename);
                sw.Write(sr.ReadToEnd());
                sw.Close();

                MimeMessage  msg     = new MimeMessage();
                StreamReader content = new StreamReader(filename);
                msg.LoadBody(content.ReadToEnd());
                content.Close();

                bool found = false;

                ArrayList bodylist = new ArrayList();
                msg.GetBodyPartList(bodylist);

                for (int i = 0; i < bodylist.Count; i++)
                {
                    MIME.MimeBody ab = (MimeBody)bodylist[i];
                    Console.WriteLine(ab.GetType().Name);
                    Console.WriteLine(" {0}", ab.GetContentType());
                    switch (ab.GetContentType())
                    {
                    case "message/delivery-status":
                        /// TODO: move to Mime processor
                        MimeDSN dsn = new MimeDSN();
                        dsn.LoadBody(ab.GetText());
                        Console.WriteLine("ReportingMTA: {0}", dsn.ReportingMTA);
                        Console.WriteLine("ReceivedFromMTA: {0}", dsn.ReceivedFromMTA);
                        Console.WriteLine("OriginalEnvelopeId: {0}", dsn.OriginalEnvelopeId);
                        foreach (MimeDSNRecipient r in dsn.Recipients)
                        {
                            found = true;
                            Console.WriteLine("{0}: {1}", r.Action, r.FinalRecipientEmailAddress);
                        }
                        break;
                    }
                }

                File.Delete(filename);
                Console.WriteLine("{0}: {1}", resource, found);
                Console.WriteLine("-------------------------------------------------------------------------");
                Assert.AreEqual(expected_found, found);
            }
        }
예제 #3
0
        private void ProcessMessage(string filename)
        {
            MimeMessage msg = new MimeMessage();

            StreamReader content = new StreamReader(filename);

            msg.LoadBody(content.ReadToEnd());
            content.Close();

            ArrayList bodylist = new ArrayList();

            msg.GetBodyPartList(bodylist);
            EventLogManager.WriteEntry(string.Format("Loaded {0} parts of message \"{1}\".",
                                                     bodylist.Count, filename));

            List <MimeDSNRecipient> failures = new List <MimeDSNRecipient>();

            for (int i = 0; i < bodylist.Count; i++)
            {
                MimeBody ab = (MimeBody)bodylist[i];
                EventLogManager.WriteEntry(string.Format("Parsing body part {0}: \"{1}\" ({2}).", i, ab.GetName(), ab.GetContentType()));
                switch (ab.GetContentType())
                {
                case "message/delivery-status":
                    /// TODO: move to Mime processor
                    MimeDSN dsn = new MimeDSN();
                    dsn.LoadBody(ab.GetText());
                    foreach (MimeDSNRecipient r in dsn.Recipients)
                    {
                        if (IsStopping)
                        {
                            break;
                        }

                        EventLogManager.WriteEntry(string.Format("Checking {0} ({1}).", r.FinalRecipientEmailAddress, r.Action));
                        switch (r.Action)
                        {
                        case "failed":
                            failures.Add(r);
                            break;
                        }
                    }
                    break;
                }
            }

            if (failures.Count > 0)
            {
                foreach (MimeDSNRecipient r in failures)
                {
                    if (IsStopping)
                    {
                        break;
                    }

                    EventLogManager.WriteEntry(string.Format("Processing {0} ({1}).",
                                                             r.FinalRecipientEmailAddress, r.Action));
                    UpdateFailure(r);
                }
            }

            EventLogManager.WriteEntry(string.Format("Processed message \"{0}\".", filename));
        }