Пример #1
0
        public EmailAccount(string accountName, Settings settings)
        {
            InitializeComponent();
            this.accountName = accountName;
            this.settings    = settings;
            SqlConnection connection = CoreFeature.getInstance().getDataConnection();
            SqlCommand    cmd        = connection.CreateCommand();

            cmd.CommandText = "select * from account where name='" + accountName + "'";
            cmd.CommandType = CommandType.Text;
            SqlDataReader rdr = cmd.ExecuteReader();

            if (rdr.Read())
            {
                txtName.Text      = rdr.GetString(rdr.GetOrdinal("name"));
                txtServer.Text    = rdr.GetString(rdr.GetOrdinal("server"));
                txtPort.Value     = rdr.GetInt32(rdr.GetOrdinal("port"));
                chkUseSSL.Checked = rdr.GetByte(rdr.GetOrdinal("use_ssl")) == 1;
                txtUsername.Text  = rdr.GetString(rdr.GetOrdinal("username"));
                txtPassword.Text  = Cryptho.Decrypt(rdr.GetString(rdr.GetOrdinal("password")));
                chkActive.Checked = rdr.GetByte(rdr.GetOrdinal("active")) == 1;
            }

            cmd.Dispose();
            rdr.Close();
            connection.Close();
        }
Пример #2
0
        private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            timer.Stop();
            string sql;

            CoreFeature.getInstance().LogActivity(LogLevel.Debug, "Begin timed activity : Logging to email account and processing the rules", EventLogEntryType.Information);
            try
            {
                //1. LOOP ALL EMAIL ACCOUNTS
                sql = "select name, server,port,use_ssl,username,password,active from account where active=1";
                SqlCommand     cmdAccount  = new SqlCommand(sql, CoreFeature.getInstance().getDataConnection());
                SqlDataReader  rdrAccount  = cmdAccount.ExecuteReader();
                List <Account> listAccount = new List <Account>();
                while (rdrAccount.Read())
                {
                    Account emailAccount = new Account(rdrAccount.GetString(rdrAccount.GetOrdinal("name")), rdrAccount.GetString(rdrAccount.GetOrdinal("server")), rdrAccount.GetInt32(rdrAccount.GetOrdinal("port")), rdrAccount.GetString(rdrAccount.GetOrdinal("username")), Cryptho.Decrypt(rdrAccount.GetString(rdrAccount.GetOrdinal("password"))), rdrAccount.GetByte(rdrAccount.GetOrdinal("use_ssl")) == 1, rdrAccount.GetByte(rdrAccount.GetOrdinal("active")) == 1);
                    listAccount.Add(emailAccount);
                    CoreFeature.getInstance().LogActivity(LogLevel.Debug, "Will use active email " + emailAccount.name, EventLogEntryType.Information);
                }
                rdrAccount.Close();

                //2. LOOP ALL NEW MESSAGES
                foreach (Account emailAccount in listAccount)
                {
                    CoreFeature.getInstance().LogActivity(LogLevel.Debug, "Logging in to email account " + emailAccount.name, EventLogEntryType.Information);
                    SqlDataReader rdrInbox = null;
                    sql = "SELECT count(*) FROM inbox i, account a where i.account_name = a.name and a.name=@name";
                    SqlCommand cmdInbox = new SqlCommand(sql, CoreFeature.getInstance().getDataConnection());
                    cmdInbox.Parameters.AddWithValue("name", emailAccount.name);
                    rdrInbox = cmdInbox.ExecuteReader();

                    if (rdrInbox.Read())
                    {
                        if (rdrInbox.GetInt32(0) == 0)
                        {
                            CoreFeature.getInstance().LogActivity(LogLevel.Debug, "No messages in inbox, try to fetch all last 30 days message to test the rule", EventLogEntryType.Information);
                            rdrInbox.Dispose();
                            CoreFeature.getInstance().FetchRecentMessages(emailAccount, true);
                        }
                        else
                        {
                            CoreFeature.getInstance().LogActivity(LogLevel.Debug, "Inbox already consisted of previous fetched message, now only fetch new message", EventLogEntryType.Information);
                            rdrInbox.Dispose();
                            CoreFeature.getInstance().FetchRecentMessages(emailAccount, false);
                        }
                    }
                    rdrInbox.Close();
                    cmdInbox.Dispose();
                }
            }
            catch (Exception ex)
            {
                CoreFeature.getInstance().LogActivity(LogLevel.Debug, "[Internal Application Error] " + ex.Message, EventLogEntryType.Error);
                if (CoreFeature.getInstance().getDataConnection() != null)
                {
                    CoreFeature.getInstance().getDataConnection().Close();
                }
            }
            timer.Start();
        }
Пример #3
0
        private bool saveConnection()
        {
            SqlConnection connection = CoreFeature.getInstance().getDataConnection();
            SqlCommand    cmd        = connection.CreateCommand();

            if (accountName == "")
            {
                cmd.CommandText = "insert into account(name,server,port,use_ssl,username,password,active) values ('" + txtName.Text + "','" + txtServer.Text + "'," + txtPort.Value + "," + Convert.ToInt32(chkUseSSL.Checked) + ",'" + txtUsername.Text + "','" + Cryptho.Encrypt(txtPassword.Text) + "'," + Convert.ToInt32(chkActive.Checked) + ")";
            }
            else
            {
                cmd.CommandText = "update account set name='" + txtName.Text + "', server='" + txtServer.Text + "',port=" + txtPort.Value + ",use_ssl=" + Convert.ToInt32(chkUseSSL.Checked) + ",username='******',password='******', active=" + Convert.ToInt32(chkActive.Checked) + " where name='" + accountName + "'";
            }
            cmd.CommandType = CommandType.Text;
            int rowAffected = cmd.ExecuteNonQuery();

            if (rowAffected != 1)
            {
                MessageBox.Show("Error occured in saving your connection info. Please correct them before testing connection");
                cmd.Dispose();
                connection.Close();
                return(false);
            }
            settings.updateListAccountName(txtName.Text);
            cmd.Dispose();
            connection.Close();

            return(true);
        }