/// <summary>
        ///
        /// </summary>
        /// <param name="FilePath"></param>
        /// <returns></returns>
        public Message ResolveMailByLSoft(String FilePath)
        {
            Message oMsg = new Message();

            ADODB.Stream stm = null;
            try
            {
                stm = new ADODB.Stream();
                stm.Open(System.Reflection.Missing.Value,
                         ADODB.ConnectModeEnum.adModeUnknown,
                         ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", "");
                stm.Type = ADODB.StreamTypeEnum.adTypeBinary; //二进制方式读入

                stm.LoadFromFile(FilePath);                   //将EML读入数据流

                oMsg.DataSource.OpenObject(stm, "_stream");   //将EML数据流载入到CDO.Message,要做解析的话,后面就可以了。
            }
            catch (IOException)
            {
            }
            finally
            {
                stm.Close();
            }
            return(oMsg);
        }
Example #2
0
        /// <summary>
        /// 解析邮件文件为邮件对象
        /// </summary>
        /// <param name="FilePath"></param>
        /// <returns></returns>
        public Message ResolveMailByLSoft(String FilePath)
        {
            Message oMsg = new Message();
            ADODB.Stream stm = null;
            //读取EML文件到CDO.MESSAGE,做分析的话,实际是用了下面的部分

            try
            {
                stm = new ADODB.Stream();
                stm.Open(System.Reflection.Missing.Value,
                ADODB.ConnectModeEnum.adModeUnknown,
                ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", "");
                stm.Type = ADODB.StreamTypeEnum.adTypeBinary;//二进制方式读入

                stm.LoadFromFile(FilePath); //将EML读入数据流

                oMsg.DataSource.OpenObject(stm, "_stream"); //将EML数据流载入到CDO.Message,要做解析的话,后面就可以了。

            }
            catch (IOException)
            {

            }
            finally
            {
                stm.Close();
            }
            return oMsg;
        }
Example #3
0
 protected CDO.Message ReadMessage(String emlFileName)
 {
     ADODB.Stream stream = new ADODB.Stream();
     stream.Open(Type.Missing, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, String.Empty, String.Empty);
     stream.LoadFromFile(emlFileName);
     stream.Flush();
     return(ReadMessage(stream));
 }
Example #4
0
        protected Message ReadMessage(String emlFileName)
        {
            Message msg    = new Message();
            Stream  stream = new Stream();

            stream.Open(Type.Missing,
                        ADODB.ConnectModeEnum.adModeUnknown,
                        ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified,
                        String.Empty,
                        String.Empty);
            stream.LoadFromFile(emlFileName);
            stream.Flush();
            msg.DataSource.OpenObject(stream, "_Stream");
            msg.DataSource.Save();
            return(msg);
        }
Example #5
0
        public static CDO.Message GetEmlFromFile(String emlFileName)
        {
            CDO.Message msg = new CDO.Message();
            try
            {
                ADODB.Stream stream = new ADODB.Stream();
                stream.Open(Type.Missing, ADODB.ConnectModeEnum.adModeUnknown,
                            ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, String.Empty, String.Empty);
                stream.LoadFromFile(emlFileName);
                stream.Flush();
                msg.DataSource.OpenObject(stream, "_Stream");
                msg.DataSource.Save();
            }
            catch
            {
            }

            return(msg);
        }
Example #6
0
 /// <summary>
 /// Read eml file into CDO message
 /// </summary>
 /// <param name="filepath">Path to eml file</param>
 /// <returns>CDO message</returns>
 private static CDO.Message ReadEml(string filepath)
 {
     var oMsg = new CDO.Message();
     var stm = new ADODB.Stream();
     stm.Open(System.Reflection.Missing.Value);
     stm.Type = ADODB.StreamTypeEnum.adTypeBinary;
     stm.LoadFromFile(filepath);
     oMsg.DataSource.OpenObject(stm, "_stream");
     stm.Close();
     return oMsg;
 }
Example #7
0
        private bool LoadMessage(string sLoadType, string sMessage)
        {
            ADODB.Stream objMsgStream = new ADODB.Stream();
            string       sFileName    = "";

            objCDOMsg = null;
            objCDOMsg = new CDO.Message();
            bLoaded   = false;

            try {
                this.Cursor = Cursors.WaitCursor;


                // First Get the Raw Mime and display it.
                string sFileText = null;
                if (sLoadType == "file")
                {
                    //MyApp.AppUtil xObj = new MyApp.AppUtil();
                    sFileName = txtFileName.Text.Trim();
                    sFileText = UserIoHelper.GetFileAsString(sFileName);


                    txtMime.Text = sFileText;


                    // Now Lets read this thing
                    objMsgStream.Open();
                    objMsgStream.LoadFromFile(sFileName);
                    objCDOMsg.BodyPart.DataSource.OpenObject(objMsgStream, "IStream");
                    m_MessageMime = sFileText;
                }
                else
                {
                    sFileName    = Path.GetTempFileName();
                    txtMime.Text = sMessage;


                    UserIoHelper.SaveStringAsFile(sMessage, sFileName);

                    // Ran into problems writing mime text to a message, working around by using a temp file
                    objMsgStream.Open();
                    objMsgStream.LoadFromFile(sFileName);
                    // Read temp file

                    objCDOMsg.BodyPart.DataSource.OpenObject(objMsgStream, "IStream");
                    // read it
                    File.Delete(sFileName);
                    // Get rid of temp file
                    m_MessageMime = sMessage;
                }

                LoadMessageFields();
                //LoadAttachemntsFields();
                ExtractBodyPart(objCDOMsg.BodyPart);


                //Marshal.ReleaseComObject(objMsgStream);
            }
            catch (Exception ex) {
                bLoaded = false;
                MessageBox.Show("Error Loading File: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            try {
                System.Windows.Forms.TreeNode pNode = new System.Windows.Forms.TreeNode();
                TreeView1.Nodes.Clear();
                pNode = TreeView1.Nodes.Add("Root");
                // m_BaseURI
                pNode.Tag = objCDOMsg.BodyPart;



                int iBodyPartCount1 = 1;
                int iBodyPartCount2 = 1;
                int iBodyPartCount3 = 1;
                int iBodyPartCount4 = 1;
                int iBodyPartCount5 = 1;
                int iBodyPartCount6 = 1;
                int iBodyPartCount7 = 1;

                System.Windows.Forms.TreeNode aNode1 = null;
                System.Windows.Forms.TreeNode aNode2 = null;
                System.Windows.Forms.TreeNode aNode3 = null;
                System.Windows.Forms.TreeNode aNode4 = null;
                System.Windows.Forms.TreeNode aNode5 = null;
                System.Windows.Forms.TreeNode aNode6 = null;
                System.Windows.Forms.TreeNode aNode7 = null;

                iBodyPartCount1 = 1;
                // Note: I'm using this big loop because i want to be able to see things better
                // as this code loops through each body part.  Using a recursive call to a method
                // just makes the debugging process more difficult.
                foreach (CDO.IBodyPart objBodypart1 in objCDOMsg.BodyPart.BodyParts)
                {
                    AddNode(objBodypart1, ref pNode, ref aNode1, iBodyPartCount1);

                    iBodyPartCount2 = 1;
                    foreach (CDO.IBodyPart objBodypart2 in objBodypart1.BodyParts)
                    {
                        AddNode(objBodypart2, ref aNode1, ref aNode2, iBodyPartCount2);
                        iBodyPartCount3 = 1;
                        foreach (CDO.IBodyPart objBodypart3 in objBodypart2.BodyParts)
                        {
                            AddNode(objBodypart3, ref aNode2, ref aNode3, iBodyPartCount3);
                            iBodyPartCount4 = 1;
                            foreach (CDO.IBodyPart objBodypart4 in objBodypart3.BodyParts)
                            {
                                AddNode(objBodypart4, ref aNode3, ref aNode4, iBodyPartCount4);
                                iBodyPartCount5 = 1;
                                foreach (CDO.IBodyPart objBodypart5 in objBodypart4.BodyParts)
                                {
                                    AddNode(objBodypart5, ref aNode4, ref aNode5, iBodyPartCount5);
                                    iBodyPartCount6 = 1;
                                    foreach (CDO.IBodyPart objBodypart6 in objBodypart5.BodyParts)
                                    {
                                        AddNode(objBodypart6, ref aNode5, ref aNode6, iBodyPartCount6);
                                        iBodyPartCount7 = 1;
                                        foreach (CDO.IBodyPart objBodypart7 in objBodypart6.BodyParts)
                                        {
                                            AddNode(objBodypart7, ref aNode6, ref aNode7, iBodyPartCount7);
                                            iBodyPartCount7 += 1;
                                            //Marshal.ReleaseComObject(objBodypart7);
                                        }
                                        iBodyPartCount6 += 1;
                                        // Marshal.ReleaseComObject(objBodypart6);
                                    }
                                    iBodyPartCount5 += 1;
                                    //Marshal.ReleaseComObject(objBodypart5);
                                }
                                iBodyPartCount4 += 1;
                                //Marshal.ReleaseComObject(objBodypart4);
                            }
                            iBodyPartCount3 += 1;
                            // Marshal.ReleaseComObject(objBodypart3);
                        }
                        iBodyPartCount2 += 1;
                        //Marshal.ReleaseComObject(objBodypart2);
                    }
                    iBodyPartCount1 += 1;
                    //Marshal.ReleaseComObject(objBodypart1);
                }
                pNode.ExpandAll();

                bLoaded = true;
            } catch (Exception ex) {
                bLoaded = false;
                MessageBox.Show("Error Loading Message Body Parts: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            objMsgStream = null;
            Cursor       = Cursors.Default;
            return(bLoaded);
        }