借助于PHP页面ASP代码也能从新闻组中读取.发送邮件了

2018-09-06 12:48

阅读:678

  下面的代码作为从新闻组取信的中转,生成特定格式的XML文档,等待其它页面来提取.

<?php
function head($date,$string) {
$head=split( ,$date,18);
$i=0;
while (trim($head[$i])!=.$head[$i])
{
$ph=split(:,$head[$i],2);
if ($ph[0]==$string) return htmlspecialchars($ph[1], ENT_QUOTES);
$i++;}
}
function getnews($server,$port,$group,$id){
$newsconn = fsockopen($server, $port, $errno, $errstr, 20);
if(!$newsconn) {
//echo 偿试连接服务器<span class=red>.$cfgTimeOut.</span>后失败. ;
exit();
}
else ;
; //echo 服务器<span class=red>.$server.</span>连接已成功!^_^<br>;
fwrite($newsconn,GROUP .$group. );
fwrite($newsconn,HEAD .$id. );
$tmp=;
$headall=;

while (trim($tmp)!=.) {
$tmp=fgets($newsconn,1024);
$headall.=$tmp;
}

fwrite($newsconn,BODY .$id. );
$tmp=;
$bodyall=;
fgets($newsconn,1024);
while (trim($tmp)!=.) {
$tmp=fgets($newsconn,1024);
$bodyall.=$tmp;
$bodyall=str_replace(<, lt;, $bodyall);
$bodyall=str_replace(>, gt;, $bodyall);
}

#开始输出为XML文档
header(Content-type: text/xml);
echo <?xml version=1.0 encoding=GB2312?> ;
echo <article> ;
echo <head> ;
echo <group>.head($headall,Newsgroups).</group> ;
echo <id>.$id.</id> ;
echo <from>.head($headall,From).</from> ;
echo <date>.head($headall,Date).</date> ;
echo <subject>.head($headall,Subject).</subject> ;
echo </head> ;
echo <body>.$bodyall.</body> ;
echo </article>;
fclose($newsconn);
}
getnews($_POST[server],$_POST[port],$_POST[group],$_POST[id])
?>

ASP通过PHP页面中转从指定的新闻组中取出特定的文章的代码如下

<%@LANGUAGE=VBSCRIPT CODEPAGE=936%>
<%
Dim news(6)
getDate
============================
function getData(url,group,id)
dim xmlHttp
dim data
data=newsgroup=groupid=id

set xmlHttp=Server.createObject(MSXML2.ServerXMLHTTP)
On Error Resume Next
xmlHttp.open POST,url,false
xmlHttp.setRequestHeader Content-Type,application/x-
xmlHttp.send data
if xmlHttp.readystate<>4 then
exit function
end if
getData=bytesToBSTR(xmlHttp.responseBody,GB2312)
set xmlhttp=nothing
if err.number<>0 then err.Clear
end function
=============================

=============================
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.createObject(adodb.stream)
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
=======================

具体应用
------------------------------------------------
Function main(url,group,id)

xmlDoc = getData(url,group,id)
Set objDom = Server.createObject(Microsoft.XMLDOM)
objDom.async=false
objDom.loadXML(xmlDoc)
news(0)=objDom.getElementsByTagName(group)(0).Text
news(1)=objDom.getElementsByTagName(id)(0).Text
news(2)=objDom.getElementsByTagName(from)(0).Text
news(3)=objDom.getElementsByTagName(date)(0).Text
news(4)=objDom.getElementsByTagName(subject)(0).Text
news(5)=objDom.getElementsByTagName(body)(0).Text
End Function
-----------------------------------------------
Call main(

Response.write(news(0))
Response.write(news(1))
Response.write(news(2))
Response.write(news(5))
%>


评论


亲,登录后才可以留言!