ENDMAIL
Автор: Alex Samorukov
Скачать в ZIP архиве.
ENDMAIL is an utility for IPS mail server for sending mail using command line. It can be used like "sendmail" replacement for software which use sendmail program for sending mail (e.g. PHP mail() function). Endmail will create message directly in IPS queue. So message will be delivered even if IPS mail relaying is disabled or IPS currently is not running.
/* ENDMAIL */
queue_path="d:\server\ips\queue\mail\" /* path to IPS queue */
logfile="D:\Server\ips\endmail\endmail.log" /* path to script logfile (use "nul" to disable logging) */
fromadress="admin@os2.kiev.ua" /* default from address. Used if "From:" header is not exist */
/* Code staring there */
Call Rxfuncadd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
Call SysLoadFuncs
toadress="";
msgtext="";
headertext="[MESSAGE.HEADER]"||d2c(13)||d2c(10);
headersize=0;
header=1
do while lines("STDIN") <> 0
newline=linein("stdin")
if header=1 then do
if translate(left(newline,3))='TO:' then do
if pos("<",newline,1)<>0 & pos(">",newline,1)<>0 then parseline="To: "||substr(newline,pos("<",newline,1)+1,(pos(">",newline,1)-pos("<",newline,1)-1))
else parseline=newline
parse value parseline with 'To: ' toadress
toadress=space(toadress)
end
if translate(left(newline,5))='FROM:' then do
if pos("<",newline,1)<>0 & pos(">",newline,1)<>0 then parseline="From: "||substr(newline,pos("<",newline,1)+1,(pos(">",newline,1)-pos("<",newline,1)-1))
else parseline=newline
parse value parseline with 'From: ' fromadress
fromadress=space(fromadress)
end
headerarg="";headervalue="";
parse value newline with headerarg ': ' headervalue
headersize=headersize+length(newline)+2;
if headerarg<>"" & headervalue<>"" & substr(newline,1,1)<>" " & translate(headerarg)<>"RECEIVED" THEN
headertext=headertext||translate(headerarg)||"="||space(headervalue)||d2c(13)||d2c(10)
end
msgtext=msgtext||newline
if lines("STDIN")<>0 then msgtext=msgtext||d2c(13)||d2c(10)
if newline='' then header=0
end
if toadress="" then sayhelp();
call lineout logfile, date("U")||" "||time()||" Mail to: "||toadress||", from: "||fromadress
rc=STREAM("D:\Server\rexx\endmail.log","c","close");
incname=SysTempFileName(queue_path||'?????.inc');
parse value time() with hh ':' mm ':' ss;
rc=STREAM(incname,"c","open write");
rc=lineout(incname,"[HEADER]");
rc=lineout(incname,'ReceivedAt='||date("sorted")||hh||mm||ss||'.0');
parse value fromadress with from.user '@' from.domain
parse value toadress with to.user '@' to.domain
rc=lineout(incname,"RemoteDomain="||from.domain);
rc=lineout(incname,"ReversePath="||fromadress);
rc=lineout(incname,"Domains=@"||to.domain);
rc=lineout(incname,"[@"||to.domain||"]");
rc=lineout(incname,"Idents="||to.user);
rc=lineout(incname,headertext||"[MESSAGE.BODY]");
rc=lineout(incname,"BodyPosition="||headersize);
call charout left(incname,length(incname)-4)||".msg",msgtext
rc=STREAM(incname,"c","close");
'@ren 'incname||' '||left(filespec("name",incname),length(filespec("name",incname))-4)||".hdr >nul"
exit 0
sayhelp:
say "Endmail v 0.9"
say " Usage: endmail.cmd