Esempio n. 1
0
        public void GetMailContent(string cookie, MMail mail)
        {
            HttpHelper hh = new HttpHelper();
            // Step4. Get Mail Content
            //HttpResult hr4 = hh.GetHtml(new HttpItem()
            //{
            //    URL = "http://220.181.130.174/webmail/index.php?action=readmail&fid="+ mail.FolderId +"&inputid="+ mail.MailId +"%40" + mail.FolderId,
            //    Cookie = cookie,
            //    Referer = "http://220.181.130.174/webmail/index.php?action=mail",
            //    ProxyIp = "ieproxy",
            //    UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36"
            //});

            HttpResult hr42 = hh.GetHtml(new HttpItem()
            {
                URL       = "http://220.181.130.174/webmail/cgijson/mailnext.php?fid=" + mail.FolderId + "&mid=" + mail.MailId + "%40" + mail.FolderId + "&optype=undefined&checktime=" + Checktime(),
                Cookie    = cookie,
                Referer   = "http://220.181.130.174/webmail/index.php?action=readmail&fid=" + mail.FolderId + "&inputid=" + mail.MailId + "%40" + mail.FolderId,
                ProxyIp   = "ieproxy",
                UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36"
            });

            Sleep(1);
            ReadMail(hr42.Html, mail);
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            labelResult.Text = "Saving ...";
            txtAttach.Text   = "";
            Worker w    = new Worker();
            MMail  mail = w.Do(this.txtUsername.Text, this.txtMail.Text.Trim());

            labelResult.Text = string.Format("Saved. {0:yyyy/MM/dd HH:mm:ss}", DateTime.Now);
            txtAttach.Text   = mail.Attachments;
        }
Esempio n. 3
0
        //通过Form1界面、手工补漏
        public MMail Do(string username, string mailJson)
        {
            DA    da   = new DA();
            MMail mail = new MMail();

            ReadMail(mailJson, mail);
            mail.Id       = da.GetMailId(username, mail.MailId);
            mail.Username = username;
            da.SaveMail(mail);
            return(mail);
        }
Esempio n. 4
0
 public void AddMailIds(string username, string folderId, IEnumerable <string> mailIds)
 {
     foreach (string mid in mailIds)
     {
         MMail mail = db.FirstOrDefault <MMail>("WHERE mail_id=@0", mid);
         if (mail == null)
         {
             mail          = new MMail();
             mail.Username = username;
             mail.FolderId = folderId;
             mail.MailId   = mid;
             db.Save(mail);
         }
     }
 }
Esempio n. 5
0
        public void ReadMail(string json, MMail mail)
        {
            JObject obj = JsonConvert.DeserializeObject(json) as JObject;

            mail.MailId      = obj["mid"].ToString();
            mail.FolderId    = obj["fid"].ToString();
            mail.MailFrom    = obj["minfo"]["from"].ToString();
            mail.MailTo      = obj["minfo"]["to"].ToString();
            mail.MailCc      = obj["minfo"]["cc"].ToString();
            mail.MailBcc     = obj["minfo"]["bcc"].ToString();
            mail.MailSubject = obj["minfo"]["subject"].ToString();
            mail.MailBody    = obj["minfo"]["body"].ToString();
            mail.IsHtml      = (byte)(obj["minfo"]["ishtml"].ToString().ToLower() == "true" ? 1 : 0);
            mail.MailDate    = DateTime.ParseExact(obj["minfo"]["date"].ToString(), "yy-MM-dd HH:mm:ss", null);

            List <MAttachment> list = new List <MAttachment>();

            if (obj["minfo"]["attlist"] is JObject)
            {
                int     i    = 0;
                JObject atts = (JObject)obj["minfo"]["attlist"];
                while (atts[i.ToString()] != null)
                {
                    JObject     att = atts[i.ToString()] as JObject;
                    MAttachment a   = new MAttachment();
                    a.Filename = att["0"].ToString();
                    a.FileSize = att["1"].ToString();
                    a.FileType = att["3"].ToString();
                    a.AttInfo  = string.Format("{0}-{1}-{2}-{3}", att["2"], att["4"], att["5"], att["6"]);
                    a.FolderId = mail.FolderId;
                    a.MailId   = mail.MailId;
                    list.Add(a);
                    i++;
                }
            }
            mail.AttachList = list;
            StringBuilder sb = new StringBuilder();

            foreach (MAttachment a in list)
            {
                if (sb.Length > 0)
                {
                    sb.Append("\r\n");
                }
                sb.Append(a.ToString());
            }
            mail.Attachments = sb.ToString();
        }
Esempio n. 6
0
 public void SaveMail(MMail mail)
 {
     db.Save(mail);
 }
Esempio n. 7
0
        public int GetMailId(string username, string mailId)
        {
            MMail mail = db.FirstOrDefault <MMail>("WHERE username=@0 AND mail_id=@1", username, mailId);

            return(mail == null ? 0 : mail.Id);
        }
Esempio n. 8
0
        public MMail GetNextMail(string username)
        {
            MMail mail = db.FirstOrDefault <MMail>("WHERE mail_date IS NULL AND username=@0 ORDER BY id DESC", username);

            return(mail);
        }
Esempio n. 9
0
        public void Do()
        {
            Console.WriteLine("现在开始:{0:yyyy/MM/dd HH:mm}", DateTime.Now);

            MUser user = da.GetNextUser();

            while (user != null)
            {
                Console.WriteLine("---------------用户 " + user.Username);

                da.ClearData(user.Username);
                string attachFolder = ConfigurationManager.AppSettings["AttachFolder"] + user.Username;
                if (System.IO.Directory.Exists(attachFolder))
                {
                    System.IO.Directory.Delete(attachFolder, true);
                }
                System.IO.Directory.CreateDirectory(attachFolder);

                string cookie = Login(user.Username);

                if (user.Finished == 0)
                {
                    List <MailFolder> folders = GetFolders(cookie);
                    if (folders.Count == 0)
                    {
                        user = da.GetNextUser();
                        break;
                    }
                    user.Finished = 1;
                    da.AddFolders(user.Username, folders);
                    Console.WriteLine("{0}个归档文件夹", folders.Count);
                }

                if (user.Finished == 1)
                {
                    MFolder folder = da.GetNextFolder(user.Username);

                    while (folder != null)
                    {
                        int           totalPages  = 1;
                        int           currentPage = 1;
                        List <string> mailIds     = GetMailList(cookie, folder.FolderId, currentPage, ref totalPages);
                        if (mailIds.Count > 0)
                        {
                            da.AddMailIds(user.Username, folder.FolderId, mailIds);
                            while (currentPage < totalPages)
                            {
                                currentPage++;
                                mailIds = GetMailList(cookie, folder.FolderId, currentPage, ref totalPages);
                                if (mailIds.Count > 0)
                                {
                                    da.AddMailIds(user.Username, folder.FolderId, mailIds);
                                }
                            }
                        }
                        da.UpdateFolderFinished(folder);
                        folder = da.GetNextFolder(user.Username);
                    }
                    user.Finished = 2;
                }

                if (user.Finished == 2)
                {
                    int mailCount = da.GetMailCount(user.Username);
                    Console.WriteLine("{0}封邮件待下载", mailCount);
                    MMail mail = da.GetNextMail(user.Username);
                    while (mail != null)
                    {
                        GetMailContent(cookie, mail);
                        if (mail.AttachList.Count() > 0)
                        {
                            foreach (MAttachment att in mail.AttachList)
                            {
                                DownloadMailAttach(cookie, att, user.Username);
                            }
                        }
                        da.SaveMail(mail);
                        Console.WriteLine("{2}... {0:yyyy/MM/dd HH:mm} {1}", mail.MailDate, mail.MailSubject, mailCount);
                        mail = da.GetNextMail(user.Username);
                        mailCount--;
                    }

                    user.Finished = 9;
                    da.UpdateUserFinished(user);
                }

                Sleep(20);
                user = da.GetNextUser();
            }
        }