public Form1()
 {
     InitializeComponent();
     CreateMyMultilineTextBox();
     DisplayData(ManageDB.DBTOLIST(con), false);
     //DisplayData(LoadApp.mail,false);
 }
 private void button6_Click(object sender, EventArgs e)
 {
     ListView.SelectedListViewItemCollection mails = listView1.SelectedItems;
     foreach (ListViewItem item in mails)
     {
         ManageDB.RemoveMailByRef(Int32.Parse(item.SubItems[4].Text), con);
     }
     DisplayData(ManageDB.DBTOLIST(con), false);
 }
        public async void Refresh()
        {
            await Task.Run(() =>
            {
                /*Refresh (count message and compare with database*/
                /*Save new mail to DB*/
                ManageDB.RemoveMail(con);
                System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
                var mails = new List <Mail>();
                MessagePart plainTextPart = null, HTMLTextPart = null;

                string pattern = @"[A-Za-z0-9]*[@]{1}[A-Za-z0-9]*[.\]{1}[A-Za-z]*";
                int a          = 0;
                foreach (var msg in Manage.Receive())
                {
                    //Check you message is not null
                    if (msg != null)
                    {
                        plainTextPart = msg.FindFirstPlainTextVersion();
                        //HTMLTextPart = msg.FindFirstHtmlVersion();
                        //mail.Html = (HTMLTextPart == null ? "" : HTMLTextPart.GetBodyAsText().Trim());
                        ManageDB.AddMailToDB(
                            new Mail
                        {
                            From       = Regex.Match(msg.Headers.From.ToString(), pattern).Value,
                            Subject    = msg.Headers.Subject,
                            Date       = msg.Headers.DateSent.ToString(),
                            msg        = (plainTextPart == null ? "" : plainTextPart.GetBodyAsText().Trim()),
                            Attachment = msg.FindAllAttachments(),
                            Reference  = a += 1
                        }, con);                                                      //if mails ! DB ajouter
                    }
                }
            });

            DisplayData(ManageDB.DBTOLIST(con), false);
        }
        //Lire les msg envoyés
        private void button4_Click(object sender, EventArgs e)
        {
            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
            var         mails = new List <Mail>();
            MessagePart plainTextPart = null, HTMLTextPart = null;

            string pattern = @"[A-Za-z0-9]*[@]{1}[A-Za-z0-9]*[.\]{1}[A-Za-z]*";

            foreach (var msg in Manage.Receive())
            {
                //Check you message is not null
                if (msg != null)
                {
                    plainTextPart = msg.FindFirstPlainTextVersion();
                    //HTMLTextPart = msg.FindFirstHtmlVersion();
                    //mail.Html = (HTMLTextPart == null ? "" : HTMLTextPart.GetBodyAsText().Trim());
                    mails.Add(new Mail {
                        From = Regex.Match(msg.Headers.From.ToString(), pattern).Value, Subject = msg.Headers.Subject, Date = msg.Headers.DateSent.ToString(), msg = (plainTextPart == null ? "" : plainTextPart.GetBodyAsText().Trim())
                    });
                }
            }
            DisplayData(ManageDB.DBTOLIST(con), true);
            //DisplayData(LoadApp.mail, true);
        }