home *** CD-ROM | disk | FTP | other *** search
- /* sys:rexxc/rx
- * $VER: checkmail 1.0 (21.4.94)
- * Check for mail from POP3 host. Shows a summary of mail messages only
- *
- * Matt White <whitem@duke.usask.ca>
- *
- * Revision History
- * 1.0 April 21, 1994
- */
- cr = '0d'x
-
- TempFile = 'T:Mail.tmp'
- options results
- if exists('ENV:DEBUG') then
- debug=1
- else debug = 0
-
- call addlib('rexxarplib.library',0,-30,0)
- call addlib('rexxreqtools.library',0,-30,0)
-
- if exists('ENV:POPHOST') then
- pophost = getenv(POPHOST)
- else do
- say 'ERROR: POPHOST environment variable not set!'
- exit 10
- end
- if exists('ENV:PAGER') then
- pager = getenv(PAGER)
- if exists('ENV:USERNAME') then
- username = getenv(USERNAME)
- else do
- if debug then say 'ENV:USERNAME not set, using requester...'
- username = rtgetstring('','Please enter your username','Username',,,res)
- if res=0 then
- do
- if debug then say 'Password entry cancelled...aborting.'
- exit 10
- end
- end
- if exists('ENV:PASSWORD') then
- password = getenv(PASSWORD)
- else do
- if debug then say 'ENV:PASSWORD not set, using requester...'
- password = rtgetstring('','Please enter your password','Password',,'rtgl_invisible=true',res)
- if res=0 then
- do
- if debug then say 'Password entry cancelled...aborting.'
- exit 10
- end
- end
-
- netsend = 'TCP:'||pophost||'/pop3'
- open(net,netsend,'A')
- instring=readln(net)
- check = test_str(instring)
- if debug then say 'Sending: USER '||username
- writeln(net,'USER '||username)
- instring=readln(net)
- check = test_str(instring)
- if debug then say 'Sending: PASS '||password
- writeln(net,'PASS '||password)
- instring=readln(net)
- check = test_str(instring)
- if debug then say 'Sending: STAT'
- writeln(net,'STAT')
- instring=readln(net)
- check = test_str(instring)
- info = substr(instring,5,length(instring)-5)
- if debug then say 'Information: <'||info||'>'
- parse var info nmess ' ' noct
- if debug then say 'Messages: '||nmess||' Octets: '||noct
- if nmess = 0 then
- do
- ret = rtezrequest('Sorry, no messages...',,'No Mail',,check)
- exit 0
- end
- ret = rtezrequest('There are '||nmess||' message(s) in your mailbox','View _Headers|_Quit','Mail!',,check)
- if ret=0 then do
- close(net)
- exit 0
- end
-
- if ret=1 then do
- open(temp,TempFile,'W')
- do message = 1 to nmess
- if debug then say 'Sending: TOP '||message||' 0'
- writeln(net,'TOP '||message||' 0')
- instring = ''
- msgdate = ''
- msgfrom = ''
- msgsubj = ''
- do until (left(instring,2)='.'||cr)
- instring=readln(net)
- if debug then say 'Received: '||instring
- if left(instring,6)='Date: ' then
- do
- msgdate = right(instring,length(instring)-6)
- if debug then say 'Extracted: '||msgdate
- end
- if left(instring,6)='From: ' then
- do
- msgfrom = instring
- if debug then say 'Extracted: '||msgfrom
- end
- if left(instring,10)='Reply-to: ' then
- do
- msgrepl = instring
- if debug then say 'Extracted: '||msgrepl
- end
- if left(instring,9)='Subject: ' then
- do
- msgsubj = instring
- if debug then say 'Extracted: '||msgsubj
- end
- end
- if msgfrom = '' then msgfrom = msgrepl
- if msgfrom = '' then msgfrom = 'From: ???????????'
- writeln(temp,'Message '||message||': '||msgdate)
- writeln(temp,msgfrom)
- writeln(temp,msgsubj)
- writeln(temp,'-------------------------------------------------------')
- if debug then
- do
- say 'Message '||message||': '||msgdate
- say msgfrom
- say msgsubj
- say '-------------------------------------------------------'
- end
- end
- close(temp)
- address command pager||' '||tempfile
- end
- exit 0
-
-
- /* ------------------------------------------------------------ */
- /* test_str tests the response from the POP server: +OK or -ERR */
- /* ------------------------------------------------------------ */
-
- test_str:
-
- test = arg(1)
- if debug then say 'Server Response: '||test
- if pos('+OK',test)~=0 then
- return 1
- else
- say 'Error from server: '||test
- exit 10
-