public List <string> GetHrefFromString(string pageSrcHtml) { Chilkat.HtmlUtil obj = new Chilkat.HtmlUtil(); Chilkat.StringArray dataImage = obj.GetHyperlinkedUrls(pageSrcHtml); List <string> list = new List <string>(); for (int i = 0; i < dataImage.Length; i++) { string hreflink = dataImage.GetString(i); list.Add(hreflink); } return(list); }
public void getEmail(int emailNum) //获取email_num封邮件,将邮件总数保存到all_num { bool success = mailman.UnlockComponent("30-day trial"); if (success != true) { Console.WriteLine("Component unlock failed"); return; } mailman.MailHost = "smail.ecnu.edu.cn"; mailman.PopUsername = userName; mailman.PopPassword = pwd; Chilkat.StringArray saUidls = null; // Get the complete list of UIDLs saUidls = mailman.GetUidls(); if (saUidls == null) { Console.WriteLine(mailman.LastErrorText); return; } // Get the 10 most recent UIDLs // The 1st email is the oldest, the last email is the newest // (usually) int i; int n; int startIdx; //n = saUidls.Count; n = mailman.GetMailboxCount(); if (n > emailNum) { startIdx = n - emailNum; } else { startIdx = 0; } Chilkat.StringArray saUidls2 = new Chilkat.StringArray(); for (i = startIdx; i <= n - 1; i++) { saUidls2.Append(saUidls.GetString(i) /*string.Format("{0}@ecnu.cn", i + 2)*/); } // Download in full the 10 most recent emails: Chilkat.EmailBundle bundle = null; bundle = mailman.FetchMultiple(saUidls2); if (bundle == null) { Console.WriteLine(mailman.LastErrorText); return; } Chilkat.Email email = null; int count = 0; mailList = new mail[bundle.MessageCount]; for (i = 0; i < bundle.MessageCount; i++) { email = bundle.GetEmail(i); DateTime time = email.LocalDate; string timeStr = time.ToString(); mailList[count].fromAddress = email.FromAddress; mailList[count].fromName = email.FromName; mailList[count].subject = email.Subject; mailList[count].time = timeStr; mailList[count].body = email.Body; count++; } mailman.Pop3EndSession(); all_num = n; return; }