/***************************************/
/* $VER: OnlyMail.rexx 1.3 (31.Dec.96) */
/* written by:  Dirk Busse             */
/*              Kropsburgstrasse 8     */
/*              D-67141 Neuhofen       */
/*              Germany                */
/* E-Mail: dbusse@metronet.de          */        
/************************************************************/
/* What is OnlyMail.rexx?                                   */
/* 1. This script will receive and send Mail automatically  */
/*    with AmiPOP and SMTPpost (for example with Voodoo)    */
/*    when Miami is Online. Therefor you must define it     */
/*    as the Online-Event in the Miami-Settings.            */
/* 2. If you create an projekt icon for OnlyMail.rexx, set  */
/*    the DefaultTool to "Rx" and create a ToolType         */
/*    "CONSOLE=NIL:", you can doubleclick the icon and this */
/*    script will do something more (you must not run Miami */
/*    before):                                              */
/*    the script starts Miami, goes Online, gets your new   */
/*    mail, sends your Mail, goes Offline and quits Miami.  */
/************************************************************/
/* Installation:                                 */
/* - Copy this Script into the Miami directory.  */
/* - Look in the Script for three question-marks */
/*   (???) and set there your own parameters.    */
/* - Define it as the Online-Event in Miami.     */
/* (- create an icon if you wish.)               */
/******************************************************/
/* This script will work with AmiPOP V1.18 and V1.19, */
/* but not with AmiPOP V1.91. Because 1.91 will crash */
/* with a guru when running from ARexx or Shell.      */
/******************************************************/

OPTIONS RESULTS
ADDRESS command
IF ~SHOW('ports','MIAMI.1') THEN DO
   Run '>NIL: Miami'
   WaitForPort 'MIAMI.1'
   IF RC=5 THEN DO
      CALL OPEN('out','con:50/20/340/50/OnlyMail.rexx - Error !/Close/Wait','write')
      CALL WRITELN('out',"   I couldn't start Miami or")
      CALL WRITELN('out',"   find his ARexx-Port !")
      CALL CLOSE('out')
      EXIT 10
   END
   ELSE DO
      SETENV 'OnlyMail.tmp "OnlyMail"'
      ADDRESS 'MIAMI.1' ONLINE
      EXIT 0
   END
END

ADDRESS 'MIAMI.1' ISONLINE
IF ~RC THEN DO
   CALL OPEN('out','con:50/20/340/50/OnlyMail.rexx - Error !/Close/Wait','write')
   CALL WRITELN('out',"    Miami is OFFLINE !")
   CALL CLOSE('out')
   EXIT 10
END

ADDRESS 'MIAMI.1' HIDE

Run '/Voodoo/AmiPOP Username=dbusse??? Password=yourpassword??? POPHost=192.168.100.2??? MailBox=DFÜ:Internet/Voodoo/MailIN/dbusse??? Delete Append Once'

List '$SMTPSpoolDir files lformat="Echo *"**NSending %P%N*"*NSMTPPost %P%N*NDelete %P%N" >ram:SMTPPost.bat'
CALL OPEN('test','ram:SMTPPost.bat','read') /* Looks if outgoing mail available */
CALL READCH('test',1)
EndOfFile=EOF('test')
CALL CLOSE('test')
IF EndOfFile=0 THEN DO
   CALL CLOSE('STDOUT')
   CALL OPEN('STDOUT','con:0/70/640/200/Sending Mail/Close/Wait')
   Resident '/Voodoo/SMTPPost PURE'
   IF RC~=0 THEN DO
      CALL OPEN('out','con:50/20/340/50/OnlyMail.rexx - Error !/Close/Wait','write')
      CALL WRITELN('out',"  I couldn't find SMTPPost !")
      CALL CLOSE('out')
   END
   ELSE DO
      Execute 'ram:SMTPPost.bat'
      IF RC~=0 THEN DO
         CALL OPEN('out','con:50/20/340/50/OnlyMail.rexx - Error !/Close/Wait','write')
         CALL WRITELN('out',"Error while sending mail !")
         CALL CLOSE('out')
      END
      Resident 'SMTPPost REMOVE'
   END
END

Resident 'c:Wait PURE'
Resident 'c:Status PURE'
STAT=0
DO WHILE STAT=0
   Wait '1 sec' /* Don't kill this line! It saves CPU activity */
   Status 'command /Voodoo/AmiPOP >NIL:'
   STAT=RC
END

GetEnv '>NIL: OnlyMail.tmp'
IF RC=0 THEN DO
   ADDRESS 'MIAMI.1' OFFLINE
   UnSetEnv 'OnlyMail.tmp'
   ADDRESS 'MIAMI.1' QUIT
   EXIT 0
END
ELSE ADDRESS 'MIAMI.1' SHOW

