/* 
 * This short script sends everybody who send a mail
 * to the Sysop a notice that the Sysop is on holiday
 * and will answer his mail later.
 *
 * You may change the answer to your needs, add lines or
 * remove them - it's a simple ARexx scripts so don't worry!
 *
 * Put a line like this in your JS_Toss.cfg file:
 *
 * TRACK <path&name_of_this_scripts> <your_address>
 *
 * Make this for every address you have and you want to give
 * automatic answers.
 *
 */

parse arg command_line 

/* the first two arguments we got from JS-Toss is
   the name of the received message and a directory
   where we should put our replys.
*/
msg=word(command_line,1)
dir=word(command_line,2)

/* remove some characters */
if left(msg,1)='"' then
do
 msg=delstr(msg,1,1)
end
if right(msg,1)='"' then
do
 msg=delstr(msg,length(msg),1)
end

if left(dir,1)='"' then
do
 dir=delstr(dir,1,1)
end
if right(dir,1)='"' then
do
 dir=delstr(dir,length(dir),1)
end

/* make our reply file name */
if right(dir,1)='/' then
do
 dir=delstr(dir,length(dir),1)
end
if right(dir,1)=':' then
do
 dir=dir"answer"
end
else
do
 dir=dir"/answer"
end

/* now we start reading the mail */
if open(datei,msg,"R") then
do
/* this mails have a simple header:
    from name
    from address
    to name
    to address
    subject
    our address
*/


 fromn=readln(datei)
 froma=readln(datei)
 ton  =readln(datei)
 toa  =readln(datei)
 subj =readln(datei)
 addr =readln(datei)

/* the from address and to address have some additions
   to the normal fidonet addressing:
   @SYSOP and @BBS
   Now we look out for them because they make this script
   much easier!
*/

 _toa=toa
 b=pos("@",toa)
 if b>0 then
 do
  _toa=left(toa,b-1)
 end

 _froma=froma
 b=pos("@",froma)
 if b>0 then
 do
  _froma=left(froma,b-1)
 end

/* check to address - we use the one without the
   additionals
   then check if this mail is for the Sysop
*/

 if (addr=_toa & addr~=_froma) then     /* addr~=_froma to avoid endless loops! */
 do
  if (right(toa,6)="@SYSOP") then
  do
/* aha, we got it, now give the reply */

   if open(wdatei,dir,"W") then
   do
    writeln(wdatei,"JS_Toss automailer")
    writeln(wdatei,addr)
    writeln(wdatei,fromn)
    writeln(wdatei,froma)
    writeln(wdatei,"I'm on holiday")    /* change subject to your needs */
    writeln(wdatei,"LATIN")             /* we use LATIN charset - but you may remove this */
    writeln(wdatei,"###")               /* end mark */
    writeln(wdatei,"Hello "word(fromn,1))       /* use first name of sender */
    writeln(wdatei,"")
    writeln(wdatei,"I'm currently on holidays so I can't answer your mail.")
    writeln(wdatei,"But I'll be back soon and then I will give you a reply.")
    writeln(wdatei,"You mail isn't lost - it's waiting for me and nearly nothing")
    writeln(wdatei,"can hurt it (only a hard disk crash....).")
    writeln(wdatei,"")
    writeln(wdatei,"Here are the first 5 lines of your mail:")
    writeln(wdatei,"")

    writeln(wdatei,"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
    writeln(wdatei,"")

    /* now we MUST read the message until the end mark (###) is recognized */
    do until (eof(datei) | zeile="###")
      zeile=readln(datei)
    end

    l=1
    do until (eof(datei) | l>4)
      zeile=readln(datei)
      writeln(wdatei,zeile)
      l=l+1
    end
    writeln(wdatei,"")
    writeln(wdatei,"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")

    writeln(wdatei,"")
    writeln(wdatei,"Yours")
    writeln(wdatei,"")
    writeln(wdatei,"  Sysop")
    call close(wdatei)
   end
  end
 end
 call close(datei)
end
