1,593
社区成员
发帖
与我相关
我的任务
分享
type
THttpComponent = TIdHttp;
procedure InitHttpComponent(const Http : THttpComponent);
var
ssl : TIdSSLIOHandlerSocketOpenSSL;
begin
Http.AllowCookies := True;
Http.HandleRedirects := True;
Http.Request.Accept := 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
Http.Request.AcceptEncoding := 'deflate';
Http.Request.Connection := 'keep-alive';
Http.Request.ContentType := 'application/x-www-form-urlencoded';
Http.Request.BasicAuthentication := True;
Http.Request.UserAgent := 'Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.1';
SetAHttpSSLAndProxy(Http, True);
ssl := TIdSSLIOHandlerSocketOpenSSL.Create(Http);
Http.IOHandler := ssl;
ssl.SSLOptions.SSLVersions := [sslvSSLv23];
end;
function CheckNewMail_Yahoo_Indy(
const ALoginURL : string;
const APostURL : string;
const APostReferer : string;
const APostHeader : string;
const APostContent : string;
const AEmail : string;
const APassword : string
):integer;
var
http : THttpComponent;
resultstream : TStringStream;
poststream : TStringStream;
html : string;
params : array[0..2] of string;
postdata : string;
rurl : string;
sUnRead : string;
p : Integer;
begin
Result := -1;
http := THttpComponent.Create(nil);
resultstream := TStringStream.Create;
poststream := TStringStream.Create;
try
InitHttpComponent(http);
try
http.Get(ALoginURL, resultstream);
if http.ResponseCode <> HTTP_OK then Exit;
html := resultstream.DataString;
params[0] := FindTagContent(html, 1, ' name=.done value="', '"', True);
if params[0] = '' then
params[0] := FindTagContent(html, 1, ' name=".done" value="', '"', True);
params[1] := FindTagContent(html, 1, ' name=".challenge" value="', '"', True);
params[2] := FindTagContent(html, 1, ' name=".cnrid" value="', '"', True);
if (params[0] <> '') and (params[1] <> '') then
begin
postdata := APostContent;
postdata := StringReplace(postdata, '$EMAIL$', URLEncode(AEmail), [rfReplaceAll]);
postdata := StringReplace(postdata, '$PASSWORD$', URLEncode(APassword), [rfReplaceAll]);
postdata := StringReplace(postdata, '$PARAM_0$', URLEncode(params[0]), [rfReplaceAll]);
postdata := StringReplace(postdata, '$PARAM_1$', URLEncode(params[1]), [rfReplaceAll]);
postdata := StringReplace(postdata, '$PARAM_2$', URLEncode(params[2]), [rfReplaceAll]);
poststream.WriteString(postdata);
http.Request.Referer := http.URL.URI;
resultstream.Clear;
http.Post(APostURL, poststream, resultstream);
if http.ResponseCode <> HTTP_OK then
Exit;
html := resultstream.DataString;
rurl := FindTagContent(html, 1, 'window.location.replace("', '")', True);
if rurl = '' then Exit;
resultstream.Clear;
http.Get(rurl, resultstream);
if http.ResponseCode <> HTTP_OK then Exit;
html := resultstream.DataString;
rurl := FindTagContent(html, 1, 'window.location.replace("', '")', True);
sUnRead := FindTagContent(html, 1, '<span id="unread_count"', '</span>', True);
if sUnRead = '' then
begin
resultstream.Clear;
http.Get(http.URL.URI + '&ymv=3', resultstream);
if http.ResponseCode <> HTTP_OK then Exit;
html := resultstream.DataString;
sUnRead := FindTagContent(html, 1, '<span id="unread_count"', '</span>', True);
end;
if sUnRead <> '' then
begin
p := Pos('>', sUnRead);
if p > 0 then
Delete(sUnRead, 1, p);
sUnRead := Trim(sUnRead);
sUnRead := StringReplace(sUnRead, '(', '', [rfReplaceAll]);
sUnRead := StringReplace(sUnRead, ')', '', [rfReplaceAll]);
Result := StrToIntDef(Trim(sUnRead), 0);
end;
end;
except
end;
finally
poststream.Free;
resultstream.Free;
http.Free;
end;
end;