示例#1
0
        private void MailCheck()
        {
            DBConnect     conn          = new DBConnect();
            SqlConnection sqlConnection = new SqlConnection(@"Data Source=" + conn.host + ";Initial Catalog=" + conn.db +
                                                            ";" + "User ID=" + conn.user + ";Password="******"SELECT * FROM Mails WHERE Send_from = '{message.From.ToString().Replace("'","")}' " +
                                                 $"and Subject = '{message.Subject.ToString().Replace("'", "")}' and Send_to = '{message.To.ToString().Replace("'", "")}'";

                        bool kostyl = false;
                        using (DbDataReader reader = sqlCommand.ExecuteReader())
                        {
                            if (!reader.HasRows)
                            {
                                kostyl = true;
                            }
                        }

                        if (kostyl)
                        {
                            SqlCommand command = sqlConnection.CreateCommand();
                            command.CommandText = "INSERT INTO Mails (Send_from, Subject, Date_send, Send_to, Importance, isRead) " +
                                                  $"VALUES ('{message.From.ToString().Replace("'","")}', '{message.Subject.ToString().Replace("'", "")}', " +
                                                  $"'{message.Date.ToString().Replace("'", "")}', '{message.To.ToString().Replace("'", "")}', 'Важное', 0)";

                            command.ExecuteNonQuery();
                            inbox.AddFlags(item.UniqueId, MessageFlags.Deleted, true);
                            inbox.Expunge();
                        }
                    }

                    inbox.Close();
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex.ToString());
            }
            finally
            {
                sqlConnection.Close();
                sqlConnection.Dispose();
            }
        }