Exemplo n.º 1
0
        // BackgroundWorkers / Threads
        private void newEmail(object sender, DoWorkEventArgs e)
        {
            List <Message> allEmail = FetchAllMessages(hostname, port, useSsl, username, password);

            App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE
            {
                ListBoxData.Clear();
            });


            //ListBoxData = new List<EmailEntry> { };
            foreach (Message singleEmail in allEmail)
            {
                MessagePart theEmailTxt  = singleEmail.FindFirstPlainTextVersion();
                MessagePart theEmailHTML = singleEmail.FindFirstHtmlVersion();

                // For show in listbox
                var mailData = new ListBoxDataClass {
                    theMessage = singleEmail, truncate = 40
                };
                readyUpListBoxData(mailData);
                App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE
                {
                    ListBoxData.Add(new EmailEntry {
                        from = mailData.displayName, subject = mailData.partOfBody, messageID = singleEmail.Headers.MessageId.ToString()
                    });
                });

                // SQL
                string           myConnString  = "Data Source=db.s3db;Version=3;";
                string           mySelectQuery = "SELECT * FROM `emails` WHERE `messageId`='" + singleEmail.Headers.MessageId + "'";
                SQLiteConnection conn          = new SQLiteConnection(myConnString);
                conn.Open();
                SQLiteCommand    cmdSelect = new SQLiteCommand(mySelectQuery, conn);
                SQLiteDataReader exists    = cmdSelect.ExecuteReader();
                if (!exists.Read())
                {
                    string bodyTxt = theEmailTxt.GetBodyAsText().ToString();
                    if (theEmailHTML != null)
                    {
                        bodyTxt = theEmailHTML.GetBodyAsText().ToString();
                    }
                    string mailDate = singleEmail.Headers.DateSent.Year.ToString("0000") + "-" + singleEmail.Headers.DateSent.Month.ToString("00") + "-" + singleEmail.Headers.DateSent.Day.ToString("00");
                    string mailTime = singleEmail.Headers.DateSent.Hour.ToString("00") + ":" + singleEmail.Headers.DateSent.Minute.ToString("00") + ":" + singleEmail.Headers.DateSent.Second.ToString("00");
                    //MessageBox.Show(mailDate + "\n" + mailTime);

                    SQLiteCommand cmdInsert = new SQLiteCommand("INSERT INTO `emails`(`messageId`,`subject`,`body`,`sender`, `read`, `date`, 'time') VALUES ('" + singleEmail.Headers.MessageId + "','" + singleEmail.Headers.Subject + "',@Message,'" + singleEmail.Headers.From.Address + "', '0', '" + mailDate + "', '" + mailTime + "')", conn);
                    cmdInsert.Parameters.Add(new SQLiteParameter("@Message", bodyTxt));
                    cmdInsert.ExecuteNonQuery();
                    conn.Close();
                }
            }
            getMailsFromDb();
        }
Exemplo n.º 2
0
        public void readyUpListBoxData(ListBoxDataClass data)
        {
            MessagePart theEmailTxt  = data.theMessage.FindFirstPlainTextVersion();
            string      noLineBreaks = theEmailTxt.GetBodyAsText().ToString().Replace(System.Environment.NewLine, " ");

            data.partOfBody  = noLineBreaks.Length <= data.truncate ? noLineBreaks : noLineBreaks.Substring(0, data.truncate) + " ..";
            data.displayName = data.theMessage.Headers.From.DisplayName.ToString();
            if (data.displayName == "")
            {
                data.displayName = data.theMessage.Headers.From.Address.ToString();
            }
            data.displayName += " <" + data.theMessage.Headers.From.Address.ToString() + ">";
        }
Exemplo n.º 3
0
        // BackgroundWorkers / Threads
        private void newEmail(object sender, DoWorkEventArgs e)
        {
            List<Message> allEmail = FetchAllMessages(hostname, port, useSsl, username, password);
            App.Current.Dispatcher.Invoke((Action)delegate // <--- HERE
            {
                ListBoxData.Clear();
            });

            //ListBoxData = new List<EmailEntry> { };
            foreach (Message singleEmail in allEmail)
            {
                MessagePart theEmailTxt = singleEmail.FindFirstPlainTextVersion();
                MessagePart theEmailHTML = singleEmail.FindFirstHtmlVersion();

                // For show in listbox
                var mailData = new ListBoxDataClass { theMessage = singleEmail, truncate = 40 };
                readyUpListBoxData(mailData);
                App.Current.Dispatcher.Invoke((Action)delegate // <--- HERE
                {
                    ListBoxData.Add(new EmailEntry { from = mailData.displayName, subject = mailData.partOfBody, messageID = singleEmail.Headers.MessageId.ToString() });
                });

                // SQL
                string myConnString = "Data Source=db.s3db;Version=3;";
                string mySelectQuery = "SELECT * FROM `emails` WHERE `messageId`='" + singleEmail.Headers.MessageId + "'";
                SQLiteConnection conn = new SQLiteConnection(myConnString);
                conn.Open();
                SQLiteCommand cmdSelect = new SQLiteCommand(mySelectQuery, conn);
                SQLiteDataReader exists = cmdSelect.ExecuteReader();
                if (!exists.Read())
                {
                    string bodyTxt = theEmailTxt.GetBodyAsText().ToString();
                    if (theEmailHTML != null)
                    {
                        bodyTxt = theEmailHTML.GetBodyAsText().ToString();
                    }
                    string mailDate = singleEmail.Headers.DateSent.Year.ToString("0000") + "-" + singleEmail.Headers.DateSent.Month.ToString("00") + "-" + singleEmail.Headers.DateSent.Day.ToString("00");
                    string mailTime = singleEmail.Headers.DateSent.Hour.ToString("00") + ":" + singleEmail.Headers.DateSent.Minute.ToString("00") + ":" + singleEmail.Headers.DateSent.Second.ToString("00");
                    //MessageBox.Show(mailDate + "\n" + mailTime);

                    SQLiteCommand cmdInsert = new SQLiteCommand("INSERT INTO `emails`(`messageId`,`subject`,`body`,`sender`, `read`, `date`, 'time') VALUES ('" + singleEmail.Headers.MessageId + "','" + singleEmail.Headers.Subject + "',@Message,'" + singleEmail.Headers.From.Address + "', '0', '" + mailDate + "', '" + mailTime + "')", conn);
                    cmdInsert.Parameters.Add(new SQLiteParameter("@Message", bodyTxt));
                    cmdInsert.ExecuteNonQuery();
                    conn.Close();
                }

            }
            getMailsFromDb();
        }
Exemplo n.º 4
0
 public void readyUpListBoxData(ListBoxDataClass data)
 {
     MessagePart theEmailTxt = data.theMessage.FindFirstPlainTextVersion();
     string noLineBreaks = theEmailTxt.GetBodyAsText().ToString().Replace(System.Environment.NewLine, " ");
     data.partOfBody = noLineBreaks.Length <= data.truncate ? noLineBreaks : noLineBreaks.Substring(0, data.truncate) + " ..";
     data.displayName = data.theMessage.Headers.From.DisplayName.ToString();
     if (data.displayName == "")
     {
         data.displayName = data.theMessage.Headers.From.Address.ToString();
     }
     data.displayName += " <" + data.theMessage.Headers.From.Address.ToString() + ">";
 }