Exemple #1
0
        /// <summary>
        /// Loads messages to UI.
        /// </summary>
        private void LoadData()
        {
            m_pMessages.BeginUpdate();
            m_pMessages.Items.Clear();

            DataSet ds = m_pFolder.GetMessagesInfo();

            if (ds.Tables.Contains("MessagesInfo"))
            {
                foreach (DataRow dr in ds.Tables["MessagesInfo"].Rows)
                {
                    IMAP_t_Fetch_r_i_Envelope envelope = null;
                    try{
                        LumiSoft.Net.StringReader r = new LumiSoft.Net.StringReader(dr["Envelope"].ToString());
                        // Remove ENVELOPE and read content ().
                        r.ReadWord();
                        r = new LumiSoft.Net.StringReader(r.ReadParenthesized());

                        envelope = IMAP_t_Fetch_r_i_Envelope.Parse(r);
                    }
                    catch {
                        envelope = new IMAP_t_Fetch_r_i_Envelope(DateTime.Now, "Mailserver parse error", null, null, null, null, null, null, null, null);
                    }

                    ListViewItem item = new ListViewItem(envelope.Subject);
                    item.ImageIndex = 0;
                    item.Tag        = new object[] { dr["ID"].ToString(), Convert.ToInt32(dr["UID"]) };
                    if (envelope.Sender != null && ((Mail_t_Mailbox)envelope.Sender[0]).DisplayName != null && ((Mail_t_Mailbox)envelope.Sender[0]).DisplayName != "")
                    {
                        item.SubItems.Add(((Mail_t_Mailbox)envelope.Sender[0]).DisplayName);
                    }
                    else
                    {
                        if (envelope.From != null && envelope.From.Length > 0)
                        {
                            item.SubItems.Add(envelope.From[0].ToString());
                        }
                        else
                        {
                            item.SubItems.Add("<none>");
                        }
                    }
                    item.SubItems.Add(envelope.Date.ToString());
                    item.SubItems.Add(((decimal)(Convert.ToDecimal(dr["Size"]) / 1000)).ToString("f2"));
                    m_pMessages.Items.Add(item);
                }

                mt_Info.Text = "User '" + m_pFolder.User.UserName + "' Folder '" + m_pFolder.FolderFullPath + "' Messages (" + ds.Tables["MessagesInfo"].Rows.Count + ")";
            }

            m_pMessages.EndUpdate();
            m_pMessages_SelectedIndexChanged(null, null);
        }
        /// <summary>
        /// Refreshes sessions.
        /// </summary>
        private void RefreshSessions()
        {
            m_pSessions.BeginUpdate();

            try{
                // Update and remove exisitng sessions
                for (int i = 0; i < m_pSessions.Items.Count; i++)
                {
                    ListViewItem it = m_pSessions.Items[i];

                    // Update session info
                    if (m_pServer.Sessions.ConatainsID(((Session)it.Tag).ID))
                    {
                        Session session = m_pServer.Sessions.GetSessionByID(((Session)it.Tag).ID);

                        it.Tag = session;
                        it.SubItems[1].Text = session.UserName;
                        it.SubItems[2].Text = session.LocalEndPoint;
                        it.SubItems[3].Text = session.RemoteEndPoint;
                        it.SubItems[4].Text = (session.ReadKbInSecond / (decimal)1000).ToString("f2");
                        it.SubItems[5].Text = (session.WriteKbInSecond / (decimal)1000).ToString("f2");
                        it.SubItems[6].Text = session.SartTime.ToString("yy.MM.dd HH:mm");
                        it.SubItems[7].Text = session.IdleTimeOutSeconds.ToString();
                    }
                    // Remove session
                    else
                    {
                        it.Remove();
                        i++;
                    }
                }

                // Add new sessions
                foreach (Session session in m_pServer.Sessions)
                {
                    //--- Show only sessions what wanted to see --------------------//
                    // ALL
                    if (m_pShow.SelectedIndex == 0)
                    {
                        // Do nothing
                    }
                    // SMTP
                    else if (m_pShow.SelectedIndex == 1 && session.Type != "SMTP")
                    {
                        continue;
                    }
                    // POP3
                    else if (m_pShow.SelectedIndex == 2 && session.Type != "POP3")
                    {
                        continue;
                    }
                    // IMAP
                    else if (m_pShow.SelectedIndex == 3 && session.Type != "IMAP")
                    {
                        continue;
                    }
                    // REALY
                    else if (m_pShow.SelectedIndex == 4 && session.Type != "RELAY")
                    {
                        continue;
                    }
                    //---------------------------------------------------------------//

                    bool contains = false;
                    foreach (ListViewItem item in m_pSessions.Items)
                    {
                        if (session.ID == ((Session)item.Tag).ID)
                        {
                            contains = true;
                            break;
                        }
                    }

                    if (!contains)
                    {
                        ListViewItem it = new ListViewItem();
                        it.ImageIndex = 0;
                        it.Text       = session.Type;
                        it.SubItems.Add(session.UserName);
                        it.SubItems.Add(session.LocalEndPoint);
                        it.SubItems.Add(session.RemoteEndPoint);
                        it.SubItems.Add((session.ReadKbInSecond / (decimal)1000).ToString("f2"));
                        it.SubItems.Add((session.WriteKbInSecond / (decimal)1000).ToString("f2"));
                        it.SubItems.Add(session.SartTime.ToString("yy.MM.dd HH:mm"));
                        it.SubItems.Add(session.IdleTimeOutSeconds.ToString());
                        it.Tag = session;
                        m_pSessions.Items.Add(it);
                    }
                }
            }
            catch {
            }

            m_pSessions.EndUpdate();
        }