Beispiel #1
0
 /// <summary>
 /// Raises <b>Envelope</b> event.
 /// </summary>
 /// <param name="envelope">Envelope value.</param>
 internal void OnEnvelope(IMAP_Envelope envelope)
 {
     if (this.Envelope != null)
     {
         this.Envelope(this, new EventArgs <IMAP_Envelope>(envelope));
     }
 }
        public void getEmail(string login, string password)
        {
            IMAP_Client client = new IMAP_Client();

            client.Connect("imap.yandex.ru", 993, true);
            client.Login(login, password);
            client.SelectFolder("INBOX");

            IMAP_SequenceSet sequence = new IMAP_SequenceSet();
            //sequence.Parse("*:1"); // from first to last
            IMAP_Client_FetchHandler fetchHandler = new IMAP_Client_FetchHandler();

            fetchHandler.NextMessage += new EventHandler(delegate(object s, EventArgs e)
            {
                Console.WriteLine("next message");
            });

            fetchHandler.Envelope += new EventHandler <EventArgs <IMAP_Envelope> >(delegate(object s, EventArgs <IMAP_Envelope> e)
            {
                IMAP_Envelope envelope = e.Value;
                if (envelope.From != null && !String.IsNullOrWhiteSpace(envelope.Subject))
                {
                    Console.WriteLine(envelope.Subject);
                }
            });
            // the best way to find unread emails is to perform server search
            int[] unseen_ids = client.Search(false, "UTF-8", "unseen");
            Console.WriteLine("unseen count: " + unseen_ids.Count().ToString());
            // now we need to initiate our sequence of messages to be fetched
            sequence.Parse(string.Join(",", unseen_ids));
            // fetch messages now
            client.Fetch(false, sequence, new IMAP_Fetch_DataItem[] { new IMAP_Fetch_DataItem_Envelope() }, fetchHandler);
            // uncomment this line to mark messages as read
            // client.StoreMessageFlags(false, sequence, IMAP_Flags_SetType.Add, IMAP_MessageFlags.Seen);
        }
 private void LoadData()
 {
     try
     {
         this.Cursor = Cursors.WaitCursor;
         this.m_pMessages.Items.Clear();
         DataTable messagesInfo = this.m_pVirtualServer.RecycleBin.GetMessagesInfo(this.m_pUser.UserName, this.m_pStartDate.Value.Date, this.m_pEndDate.Value.Date);
         foreach (DataRow dataRow in messagesInfo.Rows)
         {
             dataRow["User"].ToString();
             DateTime      arg_A8_0      = Convert.ToDateTime(dataRow["DeleteTime"]).Date;
             IMAP_Envelope iMAP_Envelope = null;
             try
             {
                 iMAP_Envelope = IMAP_Envelope.Parse(new System.NetworkToolkit.StringReader(dataRow["Envelope"].ToString()));
             }
             catch
             {
             }
             ListViewItem listViewItem = new ListViewItem(dataRow["Folder"].ToString());
             listViewItem.SubItems.Add(iMAP_Envelope.Subject);
             if (iMAP_Envelope.Sender != null && ((Mail_t_Mailbox)iMAP_Envelope.Sender[0]).DisplayName != null && ((Mail_t_Mailbox)iMAP_Envelope.Sender[0]).DisplayName != "")
             {
                 listViewItem.SubItems.Add(((Mail_t_Mailbox)iMAP_Envelope.Sender[0]).DisplayName);
             }
             else if (iMAP_Envelope.Sender != null)
             {
                 listViewItem.SubItems.Add(iMAP_Envelope.Sender.ToString());
             }
             else
             {
                 listViewItem.SubItems.Add("<none>");
             }
             listViewItem.SubItems.Add(iMAP_Envelope.Date.ToString());
             listViewItem.SubItems.Add(Convert.ToDateTime(dataRow["DeleteTime"]).ToString());
             listViewItem.SubItems.Add((Convert.ToDecimal(dataRow["Size"]) / 1000m).ToString("f2"));
             listViewItem.ImageIndex = 0;
             listViewItem.Tag        = dataRow;
             this.m_pMessages.Items.Add(listViewItem);
         }
         this.mt_Info.Text = string.Concat(new object[]
         {
             "User '",
             this.m_pUser.UserName,
             "' Recyclebin messages (",
             messagesInfo.Rows.Count,
             ")"
         });
     }
     finally
     {
         this.Cursor = Cursors.Default;
     }
 }
        /// <summary>
        /// Loads user recyclebin messages to UI.
        /// </summary>
        private void LoadData()
        {
            try{
                this.Cursor = Cursors.WaitCursor;
                m_pMessages.Items.Clear();

                DataTable dtMessages = m_pVirtualServer.RecycleBin.GetMessagesInfo(m_pUser.UserName, m_pStartDate.Value.Date, m_pEndDate.Value.Date);
                foreach (DataRow dr in dtMessages.Rows)
                {
                    string   user       = dr["User"].ToString();
                    DateTime deleteTime = Convert.ToDateTime(dr["DeleteTime"]).Date;

                    IMAP_Envelope envelope = null;
                    try{
                        envelope = IMAP_Envelope.Parse(new LumiSoft.Net.StringReader(dr["Envelope"].ToString()));
                    }
                    catch {
                    }

                    ListViewItem it = new ListViewItem(dr["Folder"].ToString());
                    it.SubItems.Add(envelope.Subject);
                    if (envelope.Sender != null && ((Mail_t_Mailbox)envelope.Sender[0]).DisplayName != null && ((Mail_t_Mailbox)envelope.Sender[0]).DisplayName != "")
                    {
                        it.SubItems.Add(((Mail_t_Mailbox)envelope.Sender[0]).DisplayName);
                    }
                    else
                    {
                        if (envelope.Sender != null)
                        {
                            it.SubItems.Add(envelope.Sender.ToString());
                        }
                        else
                        {
                            it.SubItems.Add("<none>");
                        }
                    }
                    it.SubItems.Add(envelope.Date.ToString());
                    it.SubItems.Add(Convert.ToDateTime(dr["DeleteTime"]).ToString());
                    it.SubItems.Add(((decimal)(Convert.ToDecimal(dr["Size"]) / 1000)).ToString("f2"));
                    it.ImageIndex = 0;
                    it.Tag        = dr;
                    m_pMessages.Items.Add(it);
                }

                mt_Info.Text = "User '" + m_pUser.UserName + "' Recyclebin messages (" + dtMessages.Rows.Count + ")";
            }
            finally{
                this.Cursor = Cursors.Default;
            }
        }
Beispiel #5
0
        private void m_pGet_Click(object sender, EventArgs e)
        {
            try{
                this.Cursor = Cursors.WaitCursor;
                m_pMessages.Items.Clear();

                foreach (DataRow dr in m_pVirtualServer.RecycleBin.GetMessagesInfo(m_pUser.Text, m_pSince.Value.Date, m_pTo.Value.Date).Rows)
                {
                    string   user       = dr["User"].ToString();
                    DateTime deleteTime = Convert.ToDateTime(dr["DeleteTime"]).Date;

                    IMAP_Envelope envelope = null;
                    try{
                        envelope = IMAP_Envelope.Parse(new LumiSoft.Net.StringReader(dr["Envelope"].ToString()));
                    }
                    catch {
                    }

                    ListViewItem it = new ListViewItem(user);
                    it.SubItems.Add(dr["Folder"].ToString());
                    it.SubItems.Add(envelope.Subject);
                    if (envelope.Sender != null && ((Mail_t_Mailbox)envelope.Sender[0]).DisplayName != null && ((Mail_t_Mailbox)envelope.Sender[0]).DisplayName != "")
                    {
                        it.SubItems.Add(((Mail_t_Mailbox)envelope.Sender[0]).DisplayName);
                    }
                    else
                    {
                        if (envelope.Sender != null)
                        {
                            it.SubItems.Add(envelope.Sender.ToString());
                        }
                        else
                        {
                            it.SubItems.Add("<none>");
                        }
                    }
                    it.SubItems.Add(envelope.Date.ToString());
                    it.SubItems.Add(Convert.ToDateTime(dr["DeleteTime"]).ToString());
                    it.SubItems.Add(((decimal)(Convert.ToDecimal(dr["Size"]) / 1000)).ToString("f2"));
                    it.ImageIndex = 0;
                    it.Tag        = dr;
                    m_pMessages.Items.Add(it);
                }
            }
            finally{
                this.Cursor = Cursors.Default;
            }
        }
Beispiel #6
0
        public static void StoreToRecycleBin(string folderOwner, string folder, string messageFile)
        {
            string text  = Guid.NewGuid().ToString().Replace("-", "");
            string text2 = "";
            int    num   = 0;

            try
            {
                Mail_Message entity = Mail_Message.ParseFromFile(messageFile);
                text2 = IMAP_Envelope.ConstructEnvelope(entity);
                num   = (int)new FileInfo(messageFile).Length;
            }
            catch
            {
            }
            if (!Directory.Exists(RecycleBinManager.m_RecycleBinPath))
            {
                try
                {
                    Directory.CreateDirectory(RecycleBinManager.m_RecycleBinPath);
                }
                catch
                {
                }
            }
            File.Copy(messageFile, RecycleBinManager.m_RecycleBinPath + text + ".eml");
            using (FileStream file = RecycleBinManager.GetFile())
            {
                file.Position = file.Length;
                byte[] bytes = Encoding.UTF8.GetBytes(string.Concat(new object[]
                {
                    text,
                    " ",
                    DateTime.Now.ToString("yyyyMMddHHmmss"),
                    " ",
                    folderOwner,
                    " ",
                    TextUtils.QuoteString(folder),
                    " ",
                    num,
                    " ",
                    TextUtils.QuoteString(text2),
                    "\r\n"
                }));
                file.Write(bytes, 0, bytes.Length);
            }
        }
        /// <summary>
        /// Stores specified message to recycle bin.
        /// </summary>
        /// <param name="folderOwner">Folder woner user.</param>
        /// <param name="folder">Folder what message it is.</param>
        /// <param name="messageFile">Message file name with path.</param>
        public static void StoreToRecycleBin(string folderOwner, string folder, string messageFile)
        {
            string messageID = Guid.NewGuid().ToString().Replace("-", "");
            string envelope  = "";
            int    size      = 0;

            try{
                // Parse message
                Mail_Message m = Mail_Message.ParseFromFile(messageFile);

                // Construct envelope
                envelope = IMAP_Envelope.ConstructEnvelope(m);

                size = (int)new FileInfo(messageFile).Length;
            }
            catch {
            }

            if (!Directory.Exists(m_RecycleBinPath))
            {
                try{
                    Directory.CreateDirectory(m_RecycleBinPath);
                }
                catch {
                }
            }

            // Store recycle bin copy of message
            File.Copy(messageFile, m_RecycleBinPath + messageID + ".eml");

            // Update index file
            using (FileStream fs = GetFile()){
                fs.Position = fs.Length;

                // MessageID DeleteDate UserName Folder InternalDate Flags Subject
                byte[] record = System.Text.Encoding.ASCII.GetBytes(
                    messageID + " " +
                    DateTime.Now.ToString("yyyyMMddHHmmss") + " " +
                    folderOwner + " " +
                    TextUtils.QuoteString(folder) + " " +
                    size + " " +
                    TextUtils.QuoteString(envelope) + "\r\n"
                    );
                fs.Write(record, 0, record.Length);
            }
        }
 private void m_pGet_Click(object sender, EventArgs e)
 {
     try
     {
         this.Cursor = Cursors.WaitCursor;
         this.m_pMessages.Items.Clear();
         foreach (DataRow dataRow in this.m_pVirtualServer.RecycleBin.GetMessagesInfo(this.m_pUser.Text, this.m_pSince.Value.Date, this.m_pTo.Value.Date).Rows)
         {
             string        text          = dataRow["User"].ToString();
             DateTime      arg_A6_0      = Convert.ToDateTime(dataRow["DeleteTime"]).Date;
             IMAP_Envelope iMAP_Envelope = null;
             try
             {
                 iMAP_Envelope = IMAP_Envelope.Parse(new StringReader(dataRow["Envelope"].ToString()));
             }
             catch
             {
             }
             ListViewItem listViewItem = new ListViewItem(text);
             listViewItem.SubItems.Add(dataRow["Folder"].ToString());
             listViewItem.SubItems.Add(iMAP_Envelope.Subject);
             if (iMAP_Envelope.Sender != null && ((Mail_t_Mailbox)iMAP_Envelope.Sender[0]).DisplayName != null && ((Mail_t_Mailbox)iMAP_Envelope.Sender[0]).DisplayName != "")
             {
                 listViewItem.SubItems.Add(((Mail_t_Mailbox)iMAP_Envelope.Sender[0]).DisplayName);
             }
             else if (iMAP_Envelope.Sender != null)
             {
                 listViewItem.SubItems.Add(iMAP_Envelope.Sender.ToString());
             }
             else
             {
                 listViewItem.SubItems.Add("<none>");
             }
             listViewItem.SubItems.Add(iMAP_Envelope.Date.ToString());
             listViewItem.SubItems.Add(Convert.ToDateTime(dataRow["DeleteTime"]).ToString());
             listViewItem.SubItems.Add((Convert.ToDecimal(dataRow["Size"]) / 1000m).ToString("f2"));
             listViewItem.ImageIndex = 0;
             listViewItem.Tag        = dataRow;
             this.m_pMessages.Items.Add(listViewItem);
         }
     }
     finally
     {
         this.Cursor = Cursors.Default;
     }
 }
 /// <summary>
 /// Raises <b>Envelope</b> event.
 /// </summary>
 /// <param name="envelope">Envelope value.</param>
 internal void OnEnvelope(IMAP_Envelope envelope)
 {
     if(this.Envelope != null){
         this.Envelope(this,new EventArgs<IMAP_Envelope>(envelope));
     }
 }