| Using System; Using System.Collections.Generic; Using System.Linq; Using System.Text; Using System.Net; Using System.IO; Using System.Text.RegularExpressions; Using System.Xml; Namespace Getemailaddress { public class ADDRESSQQ { Mailbox Entry Definition Const string MAILQQ = "Https://mail.qq.com/cgi-bin/loginpage"; protected static string Cookieheader = String. Empty; Defines a public Cookie Header variable protected static string Nexturl = String. Empty; Define URL variables for next access Cookiecontainer Cookiecon = new Cookiecontainer (); private string UName;
private string pwd;
Private GetEmailAddress.Address163.Entrys en;
Regex reg;
Match m;
Byte[] B;
<summary>
Constructors
</summary>
<param name= "name" > Mailbox name </param>
<param name= "pwd" > Mailbox password </param>
<param name= "Type" ></param>
Public addressqq (string name, string pwd, GetEmailAddress.Address163.Entrys type)
{
This.uname = name;
This.pwd = pwd;
En = type;
Log the username and password of the login mailbox
StringBuilder sb = new StringBuilder ();
sid=ykambzyz%2c2%2czh_cn&firstlogin=false&starttime=1281074395894&redirecturl=&f=html& p=starking521&ept=0&delegate_url=& s=&ts=1281072399&from=&ppp=&chg=0& Checkisweblogin=15&uin=kongwei1314521&aliastype= @qq. com&pp=00000000000&verifycode=
Sb. Append ("&SID=YKAMBZYZ%2C2%2CZH_CN");//Field
Sb. Append ("&firstlogin=false");//language
Sb. Append ("&redirecturl=");//language
Sb. Append ("&f=html");
Sb. Append ("&p=" + pwd);//password
Sb. Append ("&ept=0");
Sb. Append ("&delegate_url=");
Sb. Append ("&s="); Sb. Append ("&from=");
Sb. Append ("&ppp="); Sb. Append ("&chg=0"); Style Sb. Append ("&uin=" + name.) Replace ("@qq. com", ""));//Login name Sb. Append ("&aliastype= @qq. com"); Sb. Append ("&pp=00000000000"); Sb. Append ("&verifycode=");
b = Encoding.ASCII.GetBytes (sb.) ToString ());
}
<summary>
Get Web page data
</summary>
<returns> get HTML data for Web pages </returns>
private String gethtml ()
{
String entryurl = Getentryurl ();
Return Process126mail (Entryurl);
}
<summary>
Analysis 126
</summary>
<param name= "Entryurl" > Resolution address </param>
<returns></returns>
private string Process126mail (String entryurl)
{
Try
{
#region//First request for landing address
Get the content of the request
HttpWebRequest HWR = (HttpWebRequest) httpwebrequest.create (new Uri (Entryurl));
Hwr. method = ' Get ';
Hwr. ContentType = "application/x-www-form-urlencoded";
Hwr. useragent = "mozilla/4.0" (compatible; MSIE 6.0; Windows NT 5.2; SV1; GTB6. NET CLR 1.1.4322;. NET CLR 2.0.50727;. NET CLR 3.0.04506.648;. NET CLR 3.5.21022) ";
Hwr. Cookiecontainer = Cookiecon;
Send data using (Stream s = hwr. GetRequestStream ()) { S.write (b, 0, b.length); } String RB = String. Empty; Get return information using (HttpWebResponse WR = (HttpWebResponse) hwr. GetResponse ()) { StreamReader sr = new StreamReader (WR. GetResponseStream (), Encoding.UTF8);
RB = Sr. ReadToEnd ();
Sr. Close ();
}
Add username and password to head cookies
Uri nurl1 = new Uri ("Https://mail.qq.com/cgi-bin/loginpage"); foreach (System.Net.Cookie Cookie in Cookiecon.getcookies (NURL1)) { Cookie. Domain = ". Mail.qq.com"; Cookie. Expires = DateTime.Now.AddHours (1); } Cookiecon.add (Cookiecon.getcookies (NURL1)); #endregion return RB; } catch (Exception ex) { Return ex. ToString () + "Login failed, please check user name and password"; } }
Regular filter private static string Transcode (String str) { Regex r = new Regex (@ "&# ([d]{1,5})", Regexoptions.none); StringBuilder s = new StringBuilder (); foreach (Match m in R.matches (str))
{
char C = (char) int. Parse (m.groups[1]. Value);
S.append (C.tostring ());
}
return s.tostring ();
}
<summary>
Get the contents of the 126 Address book
</summary>
<returns> Address Book Collection </returns>
Public list<person> getcontact ()
{
list<person> ls = new list<person> ();
Read the XML data and make a selection match filter out the matching mailboxes
String reshtml = Encoding.UTF8.GetString (Encoding.convert (Encoding.UTF8, Encoding.UTF8, Encoding.UTF8.GetBytes (this . Gethtml ()));
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.loadxml (reshtml); XmlNodeList XNL = xmldoc.selectnodes ("/result/array/object"); if (xnl = null | | xnl. Count <= 0) return LS; XmlNodeList Linknodes = xnl[0]. SelectNodes ("Array/object");
foreach (XmlNode linknode in Linknodes)
{
person PS = new person ();
foreach (XmlNode xn2 in Linknode.childnodes)
{
Get email address
if (xn2. attributes["Name"]. Value = = "EMAIL; Pref ")
{
Ps. Email = xn2. InnerText;
}
if (xn2. attributes["Name"]. Value = = "FN")
{
if (!string. IsNullOrEmpty (xn2. innertext))
{
Ps. Name = xn2. InnerText;
}
Else
{
Ps. name = "No Name temporarily";
}
}
}
Ls. ADD (PS);
} return LS;
}
<summary>
Enumeration how the request was requested
</summary>
Private Enum Reqmethod
{
POST,
Get
}
<summary>
Get the request address
</summary>
<returns> GET request Address </returns>
private String Getentryurl ()
{
String Entryurl = String. Empty;
Switch (en)
{
Case GetEmailAddress.Address163.Entrys.mailQQ:
Entryurl = MAILQQ;
Break
Default
Break
}
return string. Format (Entryurl, UName, PWD);
}
Private ADDRESSQQ ()
{
}//Closed interface } } |