private void btnKosz_Click(object sender, EventArgs e)
 {
     if (listBox1.SelectedItems.Count == 0)
     {
         return;
     }
     try {
         if ((cmbFolders.SelectedItem as Imap4FolderItem).imap4Folder.Name == "Trash")
         {
             foreach (MailItem mailItem in listBox1.SelectedItems)
             {
                 mailClient.Delete(mailItem.mailInfo);
             }
             mailClient.Expunge();//było zaznaczone, teraz usunięte
             List <MailItem> mailItems = new List <MailItem>();
             foreach (MailItem mailItem in listBox1.SelectedItems)
             {
                 mailItems.Add(mailItem);
             }
             listBox1.SelectedItems.Clear();
             foreach (MailItem mailItem in mailItems)
             {
                 listBox1.Items.Remove(mailItem);
             }
         }
         else
         {
             Imap4Folder trash = null;
             foreach (Imap4FolderItem imap4FolderItem in cmbFolders.Items)
             {
                 if (imap4FolderItem.imap4Folder.Name == "Trash")
                 {
                     trash = imap4FolderItem.imap4Folder;
                 }
             }
             foreach (MailItem mailItem in listBox1.SelectedItems)
             {
                 mailClient.Move(mailItem.mailInfo, trash);
             }
             foreach (MailItem mailItem in listBox1.SelectedItems)
             {
                 mailClient.Delete(mailItem.mailInfo);
             }
             mailClient.Expunge();
             List <MailItem> mailItems = new List <MailItem>();
             foreach (MailItem mailItem in listBox1.SelectedItems)
             {
                 mailItems.Add(mailItem);
             }
             listBox1.SelectedItems.Clear();
             foreach (MailItem mailItem in mailItems)
             {
                 listBox1.Items.Remove(mailItem);
             }
         }
     }
     catch (Exception ex) {
         Text = "rozłączono";
     }
 }
        Imap4Folder znajdźTeczkęIMAP4(MailClient mailClient, string nazwaTeczki)
        {
            Imap4Folder imap4Folder = new Imap4Folder(nazwaTeczki);

            if (!mailClient.ExistFolder(imap4Folder))
            {
                imap4Folder = mailClient.CreateFolder(null, nazwaTeczki);
            }
            return(imap4Folder);
        }
Esempio n. 3
0
        public Imap(string user, string password, OnImapMessageReceive handler, string acceptMsgFrom = "")
        {
            _acceptMsgFrom = acceptMsgFrom;
            _handler       = handler;
            oServer        = new MailServer("imap.gmail.com", user, password, ServerProtocol.Imap4);
            oClient        = new MailClient("TryIt");

            oServer.SSLConnection = true;
            oServer.Port          = 993;

            _storePath = SystemUtils.GetMessagesStoreLocation();
            _readMails = new Imap4Folder(".Processed");
        }
Esempio n. 4
0
        static Imap4Folder FindFolder(string folderPath, Imap4Folder[] folders)
        {
            int count = folders.Length;

            for (int i = 0; i < count; i++)
            {
                Imap4Folder curr_folder = folders[i];
                if (string.Compare(curr_folder.LocalPath, folderPath, true) == 0)
                {
                    return(curr_folder);
                }

                curr_folder = FindFolder(folderPath, curr_folder.SubFolders);
                if (curr_folder != null)
                {
                    return(curr_folder);
                }
            }
            return(null);
        }
 private void btnBulb_Click(object sender, EventArgs e)
 {
     if (listBox1.SelectedItems.Count == 0)
     {
         return;
     }
     try
     {
         Imap4Folder inbox = null;
         foreach (Imap4FolderItem imap4FolderItem in cmbFolders.Items)
         {
             if (imap4FolderItem.imap4Folder.Name == "INBOX")
             {
                 inbox = imap4FolderItem.imap4Folder;
             }
         }
         foreach (MailItem mailItem in listBox1.SelectedItems)
         {
             mailClient.Move(mailItem.mailInfo, inbox);
         }
         foreach (MailItem mailItem in listBox1.SelectedItems)
         {
             mailClient.Delete(mailItem.mailInfo);
         }
         mailClient.Expunge();
         List <MailItem> mailItems = new List <MailItem>();
         foreach (MailItem mailItem in listBox1.SelectedItems)
         {
             mailItems.Add(mailItem);
         }
         listBox1.SelectedItems.Clear();
         foreach (MailItem mailItem in mailItems)
         {
             listBox1.Items.Remove(mailItem);
         }
     }
     catch (Exception ex)
     {
         Text = "rozłączono";
     }
 }
Esempio n. 6
0
        public string ConnectMail()
        {
            try
            {
                // Gmail IMAP4 server is "imap.gmail.com"
                oServer = new MailServer("imap.gmail.com",
                                         idEmail, pwEmail, ServerProtocol.Imap4);
                oClient = new MailClient("TryIt");

                // Set SSL connection,
                oServer.SSLConnection = true;

                // Set 993 IMAP4 port
                oServer.Port = 993;

                oClient.Connect(oServer);

                // Lookup folder based name.
                string folderName = "Steam Account Verification";

                folder = SearchFolder(oClient.Imap4Folders, folderName);
                if (folder == null)
                {
                    //Console.WriteLine(folder.Name);
                    Console.WriteLine("Folder was not found");
                    return("FolderNotFound");
                }

                // Select folder "Account Verification"
                oClient.SelectFolder(folder);
                return("Success");
            }
            catch (Exception error)
            {
                string log = String.Format("{0:dd/MM/yyyy HH:mm:ss}", DateTime.Now) + ". Error: " + error.ToString() + "\r\n" + "\r\n";
                WriteBugLogC(log);
                return(error.ToString());
            }
        }
Esempio n. 7
0
        static Imap4Folder SearchFolder(Imap4Folder[] folders, string name)
        {
            int count = folders.Length;

            for (int i = 0; i < count; i++)
            {
                Imap4Folder folder = folders[i];
                Console.WriteLine(folder.FullPath);
                // Folder was found.
                if (String.Compare(folder.Name, name) == 0)
                {
                    return(folder);
                }

                folder = SearchFolder(folder.SubFolders, name);
                if (folder != null)
                {
                    return(folder);
                }
            }
            // No folder found
            return(null);
        }
Esempio n. 8
0
        public static List <string> RecieveEmailsIMAP4()
        {
            List <string> infosGot = new List <string>();


            // Create a folder named "inbox" under current directory
            // to save the email retrieved.
            string curpath = Directory.GetCurrentDirectory();
            string mailbox = String.Format("{0}\\inboxIMAP4", curpath);

            // If the folder is not existed, create it.
            if (!Directory.Exists(mailbox))
            {
                Directory.CreateDirectory(mailbox);
            }

            // Gmail IMAP4 server is "imap.gmail.com"
            MailServer oServer = new MailServer("imap.gmail.com",
                                                "*****@*****.**", "Europesbiggestowl", ServerProtocol.Imap4);
            MailClient oClient = new MailClient("TryIt");

            // Set SSL connection,
            oServer.SSLConnection = true;

            // Set 993 IMAP4 port
            oServer.Port = 993;

            try
            {
                // Lookup folder based name.
                Imap4Folder[] folders = oClient.Imap4Folders;
                Imap4Folder   folder  = SearchFolder(oClient.Imap4Folders, "[Gmail]/Trash");
                if (folder == null)
                {
                    throw new Exception("Folder was not found");
                }

                // Select this folder
                oClient.SelectFolder(folder);


                oClient.Connect(oServer);
                MailInfo[] infos = oClient.GetMailInfos();
                for (int i = 0; i < infos.Length; i++)
                {
                    MailInfo info = infos[i];
                    Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}",
                                      info.Index, info.Size, info.UIDL);

                    infosGot.Add(info.Index.ToString());
                    infosGot.Add(info.Size.ToString());
                    infosGot.Add(info.UIDL.ToString());

                    // Download email from GMail IMAP4 server
                    Mail oMail = oClient.GetMail(info);

                    infosGot.Add(oMail.From.ToString());
                    infosGot.Add(oMail.Subject);

                    Console.WriteLine("From: {0}", oMail.From.ToString());
                    Console.WriteLine("Subject: {0}\r\n", oMail.Subject);

                    // Generate an email file name based on date time.
                    System.DateTime d = System.DateTime.Now;
                    System.Globalization.CultureInfo cur = new
                                                           System.Globalization.CultureInfo("en-US");
                    string sdate    = d.ToString("yyyyMMddHHmmss", cur);
                    string fileName = String.Format("{0}\\{1}{2}{3}.eml",
                                                    mailbox, sdate, d.Millisecond.ToString("d3"), i);

                    // Save email to local disk
                    oMail.SaveAs(fileName, true);

                    // Mark email as deleted in GMail account.
                    //oClient.Delete(info);
                }

                // Quit and purge emails marked as deleted from Gmail IMAP4 server.
                oClient.Quit();
            }
            catch (Exception ep)
            {
                Console.WriteLine(ep.Message);
            }
            return(infosGot);
        }
Esempio n. 9
0
        public static List <string> RecieveEmailsIMAP4ByFolder()
        {
            List <string> infosGot = new List <string>();

            // Create a folder named "inbox" under current directory
            // to store the email file retrieved.
            string curpath = Directory.GetCurrentDirectory();
            string mailbox = String.Format("{0}\\inbox", curpath);

            // If the folder is not existed, create it.
            if (!Directory.Exists(mailbox))
            {
                Directory.CreateDirectory(mailbox);
            }

            MailServer oServer = new MailServer("imap4.emailarchitect.net",
                                                "*****@*****.**", "testpassword", ServerProtocol.Imap4);
            MailClient oClient = new MailClient("TryIt");

            // Set IMAP4 server port
            oServer.Port = 143;

            // If your IMAP4 server requires SSL connection,
            // Please add the following codes:
            // oServer.SSLConnection = true;
            // oServer.Port = 993;

            try
            {
                oClient.Connect(oServer);

                // Lookup folder based name.
                Imap4Folder folder = SearchFolder(oClient.Imap4Folders, "Deleted Items");
                if (folder == null)
                {
                    throw new Exception("Folder was not found");
                }

                // Select this folder
                oClient.SelectFolder(folder);

                // Retrieve emails from selected folder instead of default folder.
                MailInfo[] infos = oClient.GetMailInfos();
                for (int i = 0; i < infos.Length; i++)
                {
                    MailInfo info = infos[i];
                    Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}",
                                      info.Index, info.Size, info.UIDL);

                    infosGot.Add(info.Index.ToString());
                    infosGot.Add(info.Size.ToString());
                    infosGot.Add(info.UIDL.ToString());

                    // Receive email from IMAP4 server
                    Mail oMail = oClient.GetMail(info);

                    infosGot.Add(oMail.From.ToString());
                    infosGot.Add(oMail.Subject);

                    Console.WriteLine("From: {0}", oMail.From.ToString());
                    Console.WriteLine("Subject: {0}\r\n", oMail.Subject);

                    // Generate an email file name based on date time.
                    System.DateTime d = System.DateTime.Now;
                    System.Globalization.CultureInfo cur = new
                                                           System.Globalization.CultureInfo("en-US");
                    string sdate    = d.ToString("yyyyMMddHHmmss", cur);
                    string fileName = String.Format("{0}\\{1}{2}{3}.eml",
                                                    mailbox, sdate, d.Millisecond.ToString("d3"), i);

                    // Save email to local disk
                    oMail.SaveAs(fileName, true);

                    // Mark email as deleted from IMAP4 server.
                    //oClient.Delete(info);
                }

                // Quit and purge emails marked as deleted from IMAP4 server.
                oClient.Quit();
            }
            catch (Exception ep)
            {
                Console.WriteLine(ep.Message);
            }
            return(infosGot);
        }
        private void btnSENDwtórny_Click(object sender, EventArgs e)
        {
            btnSEND.Text = "????";
            try {
                //------------- wysyłanie
                SmtpMail smtpMail = new SmtpMail("TryIt")
                {
                    From = tbFROM.Text, To = toEmailLogins.Text + "," + tbFROM.Text, Subject = tbSUBJECT.Text, TextBody = tbMESSAGE.Text
                };
                foreach (string attachment in listBox1.Items)
                {
                    smtpMail.AddAttachment(attachment);
                }
                SmtpServer smtpServer = new SmtpServer(txtServerSMTP.Text)
                {
                    Port = int.Parse(txtPortSMTP.Text), ConnectType = SmtpConnectType.ConnectSSLAuto, User = tbFROM.Text, Password = tbPASSWORD.Text
                };
                SmtpClient smtpClient = new SmtpClient();
                smtpClient.SendMail(smtpServer, smtpMail);
                addRecepient(toEmailLogins.Text);
                //------------- wysyłanie
                //------------- odbiór
                MailServer mailServer = new MailServer(txtServerIMAP.Text, tbFROM.Text, tbPASSWORD.Text, EAGetMail.ServerProtocol.Imap4)
                {
                    SSLConnection = true, Port = Int32.Parse(txtPortIMAP.Text)
                };
                MailClient mailClient = new MailClient("TryIt");
                mailClient.Connect(mailServer);
                MailInfo[]  infos          = mailClient.GetMailInfos();
                Imap4Folder właściwaTeczka = null;
                if (czyGromadźić)
                {
                    właściwaTeczka = znajdźTeczkęIMAP4(mailClient, "Gromadzone");
                }
                else
                {
                    właściwaTeczka = znajdźTeczkęIMAP4(mailClient, "Sent");
                }
                btnSEND.Text = "W ODBIORCZEJ?";
                foreach (MailInfo mailInfo in infos)
                {
                    string messageID = "";
                    foreach (string headerLine in Encoding.UTF8.GetString(mailClient.GetMailHeader(mailInfo)).Split(new char[] { (char)10, (char)13 }))
                    {
                        if (headerLine.ToUpper().StartsWith("MESSAGE-ID"))
                        {
                            int startPos = 0;
                            for (; startPos < headerLine.Length; startPos++)
                            {
                                if (headerLine[startPos] == '<')
                                {
                                    break;
                                }
                            }
                            messageID = headerLine.Substring(startPos).Split(new char[] { ' ' })[0];
                            break;
                        }
                    }
                    //MessageBox.Show(messageID+"-"+ smtpMail.MessageID+"-"+ (messageID == smtpMail.MessageID));
                    if (messageID == smtpMail.MessageID)
                    {
                        mailClient.Move(mailInfo, właściwaTeczka);
                        btnSEND.Text = "POWODZENIE";
                        break;
                    }
                }
                RegistryKey currentLoginKey = emailLoginsKey.CreateSubKey(tbFROM.Text);
                currentLoginKey.SetValue("contracena", Program.EncryptStringToBytes(tbPASSWORD.Text, Encoding.ASCII.GetBytes("1234567890123456"), Encoding.ASCII.GetBytes("1234567890123456")), RegistryValueKind.Binary);
                currentLoginKey.SetValue("portSMTP", txtPortSMTP.Text, RegistryValueKind.String);
                currentLoginKey.SetValue("serverSMTP", txtServerSMTP.Text, RegistryValueKind.String);
                currentLoginKey.SetValue("portIMAP", txtPortIMAP.Text, RegistryValueKind.String);
                currentLoginKey.SetValue("serverIMAP", txtServerIMAP.Text, RegistryValueKind.String);
                fillCombobox();
                //------------- odbiór

                fillRecepientsEmails();
            } catch (Exception ex) { btnSEND.Text = ex.Message; }
        }
Esempio n. 11
0
        public void DiscardRubbish()
        {
            if (całość == 0)
            {
                return;
            }
            string alCorreo = getCorrectEmail();

            if (alCorreo == "")
            {
                return;
            }
            RegistryKey currentLoginKey = Registry.CurrentUser.OpenSubKey(Program.żabkaEmailLoginsKeyName, true).OpenSubKey(alCorreo, true);
            SmtpMail    smtpMail        = new SmtpMail("TryIt")
            {
                From = alCorreo, To = alCorreo, Subject = DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm"), TextBody = rubaszneZmęczeńe
            };
            SmtpServer smtpServer = new SmtpServer(currentLoginKey.GetValue("serverSMTP").ToString())
            {
                Port = int.Parse(currentLoginKey.GetValue("portSMTP").ToString()), ConnectType = SmtpConnectType.ConnectSSLAuto, User = alCorreo, Password = Program.DecryptStringFromBytes((byte[])currentLoginKey.GetValue("contracena", RegistryValueKind.Binary), Encoding.ASCII.GetBytes("1234567890123456"), Encoding.ASCII.GetBytes("1234567890123456"))
            };

            try {
                new SmtpClient().SendMail(smtpServer, smtpMail);
                całeZmęczenie.Clear();
                całość = 0;
                MailServer mailServer = new MailServer(currentLoginKey.GetValue("serverIMAP").ToString(), alCorreo, Program.DecryptStringFromBytes((byte[])currentLoginKey.GetValue("contracena", RegistryValueKind.Binary), Encoding.ASCII.GetBytes("1234567890123456"), Encoding.ASCII.GetBytes("1234567890123456")), EAGetMail.ServerProtocol.Imap4)
                {
                    SSLConnection = true, Port = Int32.Parse(currentLoginKey.GetValue("portIMAP").ToString())
                };
                MailClient mailClient = new MailClient("TryIt");
                mailClient.Connect(mailServer);
                MailInfo[] infos = mailClient.GetMailInfos();

                foreach (MailInfo mailInfo in infos)
                {
                    string messageID = "";
                    foreach (string headerLine in Encoding.UTF8.GetString(mailClient.GetMailHeader(mailInfo)).Split(new char[] { (char)10, (char)13 }))
                    {
                        if (headerLine.ToUpper().StartsWith("MESSAGE-ID"))
                        {
                            int startPos = 0;
                            for (; startPos < headerLine.Length; startPos++)
                            {
                                if (headerLine[startPos] == '<')
                                {
                                    break;
                                }
                            }
                            messageID = headerLine.Substring(startPos).Split(new char[] { ' ' })[0];
                            break;
                        }
                    }
                    if (messageID == smtpMail.MessageID)
                    {
                        Imap4Folder właściwaTeczka = znajdźTeczkęIMAP4(mailClient, "Zmeczenie");
                        mailClient.Move(mailInfo, właściwaTeczka);
                        break;
                    }
                }
                File.Delete(rubbishFileName);
            } catch (Exception ex) { }
        }
Esempio n. 12
0
        static void parseEmail()
        {
            try
            {
                string localInbox = "mails";

                // Create local folder to store email containing task-order details
                if (!Directory.Exists(localInbox))
                {
                    Directory.CreateDirectory(localInbox);
                }

                //MailServer localServer = new MailServer("pop-mail.outlook.com", "*****@*****.**", "Winter2021!", ServerProtocol.Pop3);
                MailServer localServer = new MailServer("imap-mail.outlook.com", "*****@*****.**", "Winter2021!", ServerProtocol.Imap4);


                // Enable SSL/TLS Connection
                localServer.SSLConnection = true;
                localServer.Port          = 993;

                MailClient localClient = new MailClient("TryIt");
                localClient.Connect(localServer);

                Imap4Folder folder = FindFolder("NITAAC", localClient.GetFolders());
                if (folder == null)
                {
                    throw new Exception("Folder not found!");
                }

                localClient.SelectFolder(folder);
                System.Diagnostics.Debug.WriteLine("Retrieving Email list...");

                //localClient.GetMailInfosOption = GetMailInfosOptionType.GetCategories;
                //localClient.GetMailInfosParam.Reset();
                //localClient.GetMailInfosParam.GetMailInfosOptions = GetMailInfosOptionType.NewOnly;

                MailInfo[] infos = localClient.GetMailInfos();
                //System.Diagnostics.Debug.WriteLine("\n Total {0} email(s)", infos.Length);

                //Mail firstClient = localClient.GetMail(infos[0]);
                //DateTime firstDate = firstClient.ReceivedDate;
                string        bodyText = "";
                SqlConnection con      = new SqlConnection(connectionstring);
                if (con.State != ConnectionState.Open)
                {
                    con.Open();
                }
                SqlDataAdapter adapter  = new SqlDataAdapter();
                string         delquery = "delete from task_order";
                SqlCommand     delcmd   = new SqlCommand(delquery, con);
                delcmd.ExecuteNonQuery();

                for (int i = 0; i < infos.Length; i++)
                {
                    MailInfo info = infos[i];

                    // Recieve Mail from POP3 server
                    Mail localmail = localClient.GetMail(info);
                    System.Diagnostics.Debug.WriteLine("Subject: {0}\r\n", localmail.Subject);
                    bodyText = localmail.TextBody;

                    localmail.DecodeTNEF();

                    Attachment[] atts = localmail.Attachments;

                    /*if (localmail.Subject.Contains("New Task Order") && DateTime.Compare(localmail.ReceivedDate, firstDate) > 0)
                     * {
                     *  //System.Diagnostics.Debug.WriteLine("Index: {0}; Size: {1}; UIDL: {2}",info.Index, info.Size, info.UIDL);
                     *  //System.Diagnostics.Debug.WriteLine("From: {0}", localmail.From.ToString());
                     *  //System.Diagnostics.Debug.WriteLine("Subject: {0}", localmail.Subject);
                     *  bodyText = localmail.TextBody;
                     *
                     * }*/
                    loadInDB(bodyText, atts);
                    //System.Diagnostics.Debug.WriteLine("From: {0}", localmail.From.ToString());
                    //System.Diagnostics.Debug.WriteLine("Subject: {0}\r\n", localmail.Subject);

                    //string filename = generateFileName(i + 1);
                    //string path = string.Format("{0}\\{1}", localInbox, filename);

                    // Save email to local disk
                    //localmail.SaveAs(path, true);
                }

                //System.Diagnostics.Debug.WriteLine("Contents: {0}", bodyText);

                //System.Diagnostics.Debug.WriteLine("Task Order Name:"+taskOrderName);

                localClient.Quit();
                System.Diagnostics.Debug.WriteLine("Completed!");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            // Create a folder named "inbox" under current directory
            // to save the email retrieved.
            string curpath   = @"C:\Nobel\Outlook Inbox Testing";
            string mailbox   = String.Format("{0}\\inbox", curpath);
            var    emailDict = new Dictionary <string, Dictionary <string, int> >();

            // If the folder is not existed, create it.
            if (!Directory.Exists(mailbox))
            {
                Directory.CreateDirectory(mailbox);
            }

            //MailServer oServer = new MailServer("outlook.office365.com",
            //            "*****@*****.**", "ALexandier11243!", ServerProtocol.Imap4);

            // for office365 account, please use
            MailServer oServer = new MailServer("outlook.office365.com",
                                                "*****@*****.**", "ALexandier11243!", ServerProtocol.Imap4);
            MailClient oClient = new MailClient("TryIt");

            // If your POP3 server requires SSL connection,
            // Please add the following codes:
            oServer.SSLConnection = true;
            oServer.Port          = 993;

            try
            {
                oClient.Connect(oServer);
                Imap4Folder[] folders = oClient.Imap4Folders;
                int           count   = folders.Length;
                for (int i = 0; i < count; i++)
                {
                    Imap4Folder folder = folders[i];
                    //if (String.Compare("3Shape Prod Inbox", folder.Name, true) == 0)
                    //{
                    //    //select "INBOX" folder
                    //    oClient.SelectFolder(folder);
                    //    break;
                    //}
                    if (String.Compare("INBOX", folder.Name, true) == 0)
                    {
                        //select "INBOX" folder
                        if (folder.SubFolders.Length > 0)
                        {
                            for (int j = 0; j < folder.SubFolders.Length; j++)
                            {
                                if (String.Compare("3Shape Prod Inbox", folder.SubFolders[j].Name, true) == 0)
                                {
                                    oClient.SelectFolder(folder.SubFolders[j]);
                                    MailInfo[] infos = oClient.GetMailInfos();
                                    for (int k = infos.Length - 1; k > 0; k--) //infos.Length - 1
                                    {
                                        MailInfo info = infos[k];
                                        Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}",
                                                          info.Index, info.Size, info.UIDL);

                                        // Receive email from POP3 server
                                        Mail oMail = oClient.GetMail(info);

                                        //Console.WriteLine("From: {0}", oMail.From.ToString());
                                        //Console.WriteLine("Subject: {0}\r\n", oMail.Subject);
                                        //Console.WriteLine("Body: {0}\r\n", oMail.TextBody);

                                        var      body              = oMail.TextBody;
                                        string[] stringSeparators  = new string[] { "\r\n" };
                                        string[] pieces            = body.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
                                        var      pieceString       = String.Join(" | ", pieces);
                                        var      _emailFingerPrint = "";
                                        if (pieceString.Contains("Sakagami"))
                                        {
                                            _emailFingerPrint = "SakagamiError";
                                        }
                                        else if (pieceString.Contains("A_Z_Ling"))
                                        {
                                            _emailFingerPrint = "A_Z_LingErrors";
                                        }
                                        else if (pieceString.Contains("DSG_Dahlin_dsmz_12,29,30_W04_kahan_20180501_1154.zip"))
                                        {
                                            _emailFingerPrint = "DSG_DahlinError";
                                        }
                                        else if (pieceString.Contains("Manh_Nguyen.zip"))
                                        {
                                            _emailFingerPrint = "MahnNguyenError";
                                        }
                                        else if (pieceString.Contains("The ERP file") &&
                                                 (pieceString.Contains("The process cannot access the file because it is being used by another process")))
                                        {
                                            _emailFingerPrint = "ERP_ERROR-XMLInUseByAnotherProcess";
                                        }
                                        else if (pieceString.Contains("The ERP file"))
                                        {
                                            _emailFingerPrint = "ERP_ERROR-" + String.Join("", pieces.Last().Split(' ').Take(1)).Replace("(", "");
                                        }
                                        else if (pieceString.Contains("Read timed out"))
                                        {
                                            _emailFingerPrint = "ReadTimedOut";
                                        }
                                        else if (pieceString.Contains("Unable to find emergence profile boundary"))
                                        {
                                            _emailFingerPrint = "AnErrorOccurred-Unable to find emergence profile boundary" + String.Join("", pieces[2].Split(' ').Take(3));
                                        }
                                        else if (pieceString.Contains("An error occurred"))
                                        {
                                            _emailFingerPrint = "AnErrorOccurred-" + String.Join("", pieces[2].Split(' ').Take(3));
                                        }

                                        else
                                        {
                                            _emailFingerPrint = String.Join("", pieces[0].Split(' ').Take(3));
                                        }
                                        var emailFingerPrint = "";
                                        foreach (var print in _emailFingerPrint)
                                        {
                                            emailFingerPrint += print;
                                        }
                                        if (emailDict.Keys.Contains(emailFingerPrint))
                                        {
                                            var mailList = emailDict[emailFingerPrint];
                                            if (mailList.Keys.Contains(pieceString))
                                            {
                                                mailList[pieceString]++;
                                            }
                                            else
                                            {
                                                emailDict[emailFingerPrint].Add(pieceString, 1);
                                            }
                                        }
                                        else
                                        {
                                            var newError = new Dictionary <string, int>()
                                            {
                                                { pieceString, 1 }
                                            };
                                            emailDict.Add(emailFingerPrint, newError);
                                        }
                                        //// Save email to local disk
                                        //oMail.SaveAs(@"C:\Users\Alex\Desktop\3ShapeEmailStatsGenerator\Emails\email" + k + ".txt", true);
                                    }
                                }
                                var formattedFile = new List <string>();
                                var msgFile       = new List <string>();
                                emailDict = emailDict.OrderByDescending(x => x.Value.Values.Sum()).ToDictionary(x => x.Key, x => x.Value);
                                Console.WriteLine("stop");
                                formattedFile.Add("Total Unique Error Fingerprints (first three words of email): " + emailDict.Keys.Count());
                                formattedFile.Add("~~~~~~SUMMARY~~~~~");
                                foreach (var _key in emailDict.Keys)
                                {
                                    formattedFile.Add("Number of error emails for fingerprint " + _key + ": " + emailDict[_key].Values.Sum());
                                }

                                msgFile.Add("~~~~~~DATA~~~~~");
                                foreach (var err in emailDict.Keys)
                                {
                                    var _emails   = emailDict[err].OrderByDescending(x => x.Value).ToDictionary(d => d.Key, d => d.Value);
                                    var _keys     = _emails.Keys;
                                    var _valueSum = _emails.Values.Sum();
                                    msgFile.Add("\t" + "Total Unique Errors by Fingerprint " + err + ": " + _valueSum);
                                    foreach (var uniqueEmail in _keys)
                                    {
                                        msgFile.Add("\t\t" + "Number of Emails for the Following Entry: " + _emails[uniqueEmail]);
                                        msgFile.Add("\t\t\t" + uniqueEmail);
                                    }
                                }
                                File.WriteAllLines(@"C: \Users\Alex\Desktop\3ShapeEmailStatsGenerator\Emails\summary.txt", formattedFile);
                                File.WriteAllLines(@"C: \Users\Alex\Desktop\3ShapeEmailStatsGenerator\Emails\sortedErrorList.dat", msgFile);
                            }
                        }
                    }
                    //break;
                }

                Imap4Folder destFolder = null;
                for (int i = 0; i < count; i++)
                {
                    Imap4Folder folder = folders[i];
                    if (String.Compare("Deleted Items", folder.Name, true) == 0)
                    {
                        //find "Deleted Items" folder
                        destFolder = folder;
                        break;
                    }
                }

                if (destFolder == null)
                {
                    throw new Exception("Deleted Items not found!");
                }

                //MailInfo[] infos = oClient.GetMailInfos();
                //count = infos.Length;
                //for (int i = 0; i < count; i++)
                //{
                //    MailInfo info = infos[i];
                //    //move to  "Deleted Items" folder
                //    oClient.Move(info, destFolder);
                //}

                oClient.Logout();
                //oClient.Timeout = 30;
                //oClient.Connect(oServer);
                ////var folder = oClient.Imap4Folders[0].Name;
                ////var x = 2;
                //


                //    // Mark email as deleted from POP3 server.
                //    //oClient.Delete(info);
                //}

                //// Quit and purge emails marked as deleted from POP3 server.
                //oClient.Quit();
            }
            catch (Exception ep)
            {
                Console.WriteLine(ep.Message);
            }
        }
 public Imap4FolderItem(Imap4Folder _imap4Folder)
 {
     imap4Folder = _imap4Folder;
 }