private void test(MailPwd mp) { Pop3Client pop3Client = new Pop3Client(); data sev = m_dicPopServers[emailToDomain(mp.email)]; pop3Client.Connect(sev.pop3,sev.port , sev.isSSL); pop3Client.Authenticate(mp.email, mp.pwd); // int count = pop3Client.GetMessageCount(); int messageCount = pop3Client.GetMessageCount(); // init index list List<EmailMap> em = new List<EmailMap>(); try { string dirPath = @"data\inbox\" + mp.email; //serilize index.xml /* if (File.Exists(dirPath+"\\index.xml")) { string confPath = dirPath + "\\index.xml"; var serializer = new XmlSerializer(typeof(List<EmailMap>)); using (var stream = File.OpenRead(confPath)) { var other = (List<EmailMap>)(serializer.Deserialize(stream)); em.AddRange(other); stream.Close(); } }*/ List<EmailMap> emTmp = new List<EmailMap>(); // string[] paths= Directory.GetFiles(dirPath, "*", SearchOption.AllDirectories); List<Message> allMessages = new List<Message>(messageCount); int nCurCount = m_dicEmails[mp.email].Count; // Messages are numbered in the interval: [1, messageCount] // Ergo: message numbers are 1-based. // Most servers give the latest message the highest number for (int i = nCurCount + 1; i <= messageCount; i++) { // allMessages.Add(pop3Client.GetMessage(i)); Message msg=pop3Client.GetMessage(i); string strSubject=msg.Headers.Subject; string filename=pop3Client.GetMessageHeaders(i).MessageId; emTmp.Add(new EmailMap { title = strSubject,file=filename }); //write to htm file // If the selected node is not a subnode and therefore does not // have a MessagePart in it's Tag property, we genericly find some content to show // Find the first text/plain version MessagePart plainTextPart = msg.FindFirstPlainTextVersion(); string strContent; if (plainTextPart != null) { // The message had a text/plain version - show that one strContent = plainTextPart.GetBodyAsText(); } else { // Try to find a body to show in some of the other text versions List<MessagePart> textVersions = msg.FindAllTextVersions(); if (textVersions.Count >= 1) strContent = textVersions[0].GetBodyAsText(); else strContent = "<<KibodWapon>> Cannot find a text version body in this message to show <<contact me qq408079058>>"; } string strMailPath = dirPath + "\\" + filename + ".htm"; using (System.IO.StreamWriter file = new System.IO.StreamWriter(strMailPath)) { file.WriteLine("<head><meta charset=\"UTF-8\"></head>"); file.WriteLine(strContent); file.Close(); } File.WriteAllText(dirPath + "\\" + filename + ".eml", Encoding.ASCII.GetString(msg.RawMessage)); } //serilize index.xml m_dicEmails[mp.email].AddRange(emTmp); try { string confPath =@"data\inbox\" + mp.email+"\\index.xml"; File.Delete(confPath); var serializer = new XmlSerializer(typeof(List<EmailMap>)); using (var stream = File.OpenWrite(confPath)) { serializer.Serialize(stream, em); stream.Close(); } } catch (Exception ee) { Console.WriteLine(ee.Message); } } catch (Exception UAEx) { Console.WriteLine(UAEx.Message); } pop3Client.Disconnect(); }
private void buttonStartRecv_Click(object sender, EventArgs e) { buttonStartRecv.Enabled = false; labelRecvStatus.Text = "正在收取所有邮件请稍等。。"; storeAccount(); //create recv email threads int n=listStoredAccount.Count; m_nTotalRecvAccounts = 0; for (int i = 0; i < n; i++) { MailPwd mp = new MailPwd() ; mp = listStoredAccount[i]; Thread t = new Thread(() => recvEmail(mp)); t.Start(); // recvEmail(listStoredAccount[i]); } //recvEmail(listStoredAccount[0]); }