예제 #1
0
        /// <summary>
        /// Load an individual email
        /// </summary>
        /// <param name="path"></param>
        private void LoadMessage(string path)
        {
            // open a message stream to get the message object
            Stream messageStream = File.Open(path, FileMode.Open, FileAccess.Read);

            OutlookStorage.Message message = new OutlookStorage.Message(messageStream);
            messageStream.Close();

            // set the basic properties
            body.Rtf     = message.BodyRTF;
            subject.Text = message.Subject;
            from.Text    = string.Format("{0} <{1}>", message.From, message.GetMapiPropertyString("5D01"));
            headers.Text = message.GetMapiPropertyString("007D");

            // add the recipients
            AddRecipients(message);

            // add any attachments
            AddAttachments(message);

            // populate the extended data
            PopulateData(message);
        }
예제 #2
0
        // Each message is opened and a tabpage is created dynamically with a header and body box
        private void load_files(string msgfile, string holder, ref int TabCount, string ruleTxt = "", bool fromNode = false)
        {
            bool rulesFileHere = check_for_rules();

            myTab      = new TabPage(holder);
            myTab.Text = holder;
            TextBox HeaderBox = new TextBox();

            HeaderBox.Multiline        = true;
            HeaderBox.Width            = 550;
            HeaderBox.Height           = 960;
            HeaderBox.Location         = new Point(650, 0);
            HeaderBox.ScrollBars       = ScrollBars.Both;
            HeaderBox.ReadOnly         = true;
            HeaderBox.BackColor        = Color.White;
            HeaderBox.WordWrap         = false;
            headerSizeDec.Enabled      = true;
            headerSizeInc.Enabled      = true;
            HeaderBox.ContextMenuStrip = headerMenu;
            myTab.Controls.Add(HeaderBox);

            TextBox BodyBox = new TextBox();

            BodyBox.Multiline        = true;
            BodyBox.Width            = 650;
            BodyBox.Height           = 960;
            BodyBox.ScrollBars       = ScrollBars.Both;
            BodyBox.ReadOnly         = true;
            BodyBox.BackColor        = Color.White;
            BodyBox.WordWrap         = false;
            bodySizeDec.Enabled      = true;
            bodySizeInc.Enabled      = true;
            BodyBox.ContextMenuStrip = bodyMenu;
            myTab.Controls.Add(BodyBox);

            Regex regex_txt = new Regex(@"\.txt$");
            Regex regex_msg = new Regex(@"\.msg$");
            Regex regex_eml = new Regex(@"\.eml$");
            Match match_txt = regex_txt.Match(msgfile);
            Match match_msg = regex_msg.Match(msgfile);
            Match match_eml = regex_eml.Match(msgfile);

            TabCount = TabCount + 1;

            // What type of file are we trying to open.
            if (match_msg.Success)
            {
                Stream messageStream;
                try { messageStream = File.Open(msgfile, FileMode.Open, FileAccess.Read); }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "File Error", MessageBoxButtons.OK);
                    return;
                }
                OutlookStorage.Message message = new OutlookStorage.Message(messageStream);
                messageStream.Close();


                HeaderBox.Text = message.GetMapiPropertyString("007D");
                BodyBox.Text   = message.BodyText;
                message.Dispose();
            }
            else if (match_eml.Success || match_txt.Success)
            {
                StreamReader mStream;
                try { mStream = new StreamReader(msgfile); }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "File Error", MessageBoxButtons.OK);
                    return;
                }

                bool   reachedBody = false;
                bool   firstLine   = true;
                string header      = "";
                string body        = "";

                while (mStream.Peek() >= 0)
                {
                    string lineTest = mStream.ReadLine();
                    if (lineTest != "" && reachedBody == false)
                    {
                        if (!firstLine)
                        {
                            header = header + "\r\n" + lineTest;
                        }
                        else
                        {
                            header = lineTest; firstLine = false;
                        }
                        reachedBody = false;
                    }

                    else if (lineTest == "" && reachedBody == false)
                    {
                        reachedBody    = true;
                        firstLine      = true;
                        HeaderBox.Text = header;
                    }
                    if (reachedBody)
                    {
                        if (!firstLine)
                        {
                            body = body + "\r\n" + lineTest;
                        }
                        else
                        {
                            body = lineTest; firstLine = false;
                        }
                    }
                }
                BodyBox.Text = body;
            }

            // Add a new node to the tree view for these files
            messageNodeInfo nodeNew = new messageNodeInfo();

            nodeNew.headerText             = HeaderBox.Text;
            nodeNew.bodyText               = BodyBox.Text;
            nodeNew.tNode.Text             = holder;
            nodeNew.tNode.Name             = msgfile;
            nodeNew.filePath               = msgfile;
            nodeNew.fileName               = holder;
            nodeNew.tNode.ContextMenuStrip = contextMenuStrip2;
            nodeList.Add(nodeNew);

            tabControl1.TabPages.Add(myTab);
            //tabControl1.Hide();
            closeBtn.Enabled    = true;
            button1.Enabled     = true;
            closeAllBtn.Enabled = true;

            // If a top level treeview node is already selected add the new files to that node
            // Otherwise create a new toplevel node
            if (treeView1.SelectedNode != null)
            {
                if (treeView1.SelectedNode.Level != 0 && fromNode == false)
                {
                    treeView1.SelectedNode.Parent.Nodes.Add(nodeNew.tNode);
                    nodeNew.pNodeIndex = treeView1.SelectedNode.Parent.Index;
                }
                else if (fromNode == false)
                {
                    treeView1.SelectedNode.Nodes.Add(nodeNew.tNode);
                    nodeNew.pNodeIndex = treeView1.SelectedNode.Index;
                }

                treeView1.SelectedNode.Expand();
            }
            else if (treeView1.SelectedNode == null)
            {
                if (treeView1.Nodes.ContainsKey("Untitled") == false)
                {
                    TreeNode newTopNode = new TreeNode("Untitled");
                    newTopNode.Name             = "Untitled";
                    newTopNode.ContextMenuStrip = contextMenuStrip1;
                    nodeNew.pNodeIndex          = treeView1.Nodes.Count;
                    newTopNode.Nodes.Add(nodeNew.tNode);
                    treeView1.Nodes.Add(newTopNode);
                    treeView1.SelectedNode = treeView1.Nodes[newTopNode.Name];
                }
                else
                {
                    ;
                }
            }
            else
            {
                ;
            }
        }