Exemplo n.º 1
0
        public void ShowMail(NewMailInfo mailinfo, String _server, int _port, String _user, String _pwd)
        {
            try
            {
                this.initButton();
                Monitor.Enter(this.lockObj);
                if (!formSwitchFlag)
                {
                    formSwitchFlag = true;

                    receive.mailmsg          = new NewMailMessage();
                    receive.mailmsg.MailInfo = mailinfo;
                    receive.pop3server       = _server;
                    receive.pop3port         = _port;
                    receive.user             = _user;
                    receive.pwd = _pwd;
                    receive.ShowMailMessage();

                    this.ShowForm(pnlCenter, receive);

                    formSwitchFlag = false;
                }
                else
                {
                    return;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                Monitor.Exit(this.lockObj);
            }
        }
Exemplo n.º 2
0
 private void SetNewMailInfo(int n)
 {
     try
     {
         Login();
         if (!login)
         {
             WarningMessage("请重试");
             return;
         }
         // 获取uidl
         order = "uidl " + n.ToString() + "\r\n";
         String      tmp;
         NewMailInfo mailinfo = null;
         if (SendOrder(order))
         {
             tmp      = recv.Split(' ')[2];
             mailinfo = new NewMailInfo(n, tmp);
         }
         else
         {
             WarningMessage("获取失败");
             return;
         }
         // 获取头部信息
         order = "top " + n.ToString() + " 0\r\n";
         if (SendOrder(order))
         {
             PrintRecv(recv = sr.ReadLine());
             while ((recv = sr.ReadLine()) != ".")
             {
                 if (recv.ToLower().StartsWith("from"))
                 {
                     tmp           = recv.Substring(5);
                     mailinfo.From = new MailAddress(tmp);
                 }
                 else if (recv.ToLower().StartsWith("to"))
                 {
                     mailinfo.To = new MailAddress(recv.Substring(3));
                 }
                 else if (recv.ToLower().StartsWith("subject"))
                 {
                     tmp = recv.Substring(8);
                     mailinfo.Subject = tmp;
                 }
                 else if (recv.ToLower().StartsWith("date"))
                 {
                     mailinfo.Date = Convert.ToDateTime(recv.Substring(5, recv.IndexOf("+0800") - 5).Trim());
                 }
             }
         }
         mailmsg.MailInfo = mailinfo;
     }
     catch (Exception e)
     {
         PrintRecv(e.StackTrace);
     }
     finally
     {
         Disconnect();
     }
 }
Exemplo n.º 3
0
        private void GetMsgInfoList()
        {
            // 邮件数量
            msgcount = GetMsgCount();

            int start = Math.Max(msgcount - (curpage - 1) * cntperpage, 0);

            if (start == 0)
            {
                WarningMessage("已是最后一页");
                curpage--;
                return;
            }
            int end = Math.Max(msgcount - curpage * cntperpage, 0);

            // 邮件头部信息列表
            msglist = new ArrayList();
            try
            {
                Login();
                if (!login)
                {
                    PrintRecv("登陆失败");
                    return;
                }
                String      input;
                String      recv;
                String      uid;
                NewMailInfo mailinfo = null;
                for (int n = start; n > end; n--)
                {
                    // 获取uid
                    input = "uidl " + n.ToString() + "\r\n";
                    if (SendOrder(input))
                    {
                        PrintRecv(recv = sr.ReadLine());
                        uid            = recv.Split(' ')[2];
                    }
                    else
                    {
                        WarningMessage("获取邮件失败");
                        return;
                    }

                    // 获取基本信息
                    input = "top " + n.ToString() + " 0\r\n";
                    if (SendOrder(input))
                    {
                        recv     = sr.ReadLine();
                        mailinfo = new NewMailInfo(n, uid);
                        String tmp;
                        while ((recv = sr.ReadLine()) != ".")
                        {
                            if (recv.ToLower().StartsWith("from"))
                            {
                                tmp = recv.Substring(5);

                                if (tmp.Contains("<"))
                                {
                                    tmp = tmp.Trim(' ', '"').Split('<')[1].Trim(' ', '>');
                                }

                                mailinfo.From = new MailAddress(tmp);
                            }
                            else if (recv.ToLower().StartsWith("to"))
                            {
                                mailinfo.To = new MailAddress(recv.Substring(3));
                            }
                            else if (recv.ToLower().StartsWith("subject"))
                            {
                                tmp = recv.Substring(8).Trim();

                                if (tmp.Contains("=?GBK?") || tmp.Contains("=?gbk?") || tmp.Contains("=?utf-8?") || tmp.Contains("=?UTF-8?"))
                                {
                                    tmp = Tools.GetReadText(tmp);
                                }

                                mailinfo.Subject = tmp;
                            }
                            else if (recv.ToLower().StartsWith("date"))
                            {
                                mailinfo.Date = Convert.ToDateTime(recv.Substring(5, recv.IndexOf("+0800") - 5).Trim());
                            }
                        }
                        msglist.Add(mailinfo);
                    }
                    else
                    {
                        WarningMessage("获取邮件失败");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                PrintRecv(ex.StackTrace);
            }
            finally
            {
                Disconnect();
            }

            // 更改DataGridView
            ChangeDGVMail(msglist);
        }