home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / networking / tcpip / amitcp-support / checkmail / chkmail
Encoding:
Text File  |  1994-06-29  |  4.6 KB  |  149 lines

  1. /* sys:rexxc/rx
  2.  *  $VER: checkmail 1.0 (21.4.94) 
  3.  *  Check for mail from POP3 host.  Shows a summary of mail messages only
  4.  *  
  5.  *     Matt White <whitem@duke.usask.ca>
  6.  *     
  7.  *   Revision History
  8.  *      1.0   April 21, 1994
  9.  */
  10.    cr = '0d'x
  11.  
  12.    TempFile = 'T:Mail.tmp'
  13.    options results
  14.    if exists('ENV:DEBUG') then
  15.       debug=1
  16.    else debug = 0
  17.  
  18.    call addlib('rexxarplib.library',0,-30,0)
  19.    call addlib('rexxreqtools.library',0,-30,0)
  20.  
  21.    if exists('ENV:POPHOST') then
  22.       pophost = getenv(POPHOST)
  23.    else do
  24.           say 'ERROR: POPHOST environment variable not set!'
  25.           exit 10
  26.         end
  27.    if exists('ENV:PAGER') then
  28.       pager = getenv(PAGER)
  29.    if exists('ENV:USERNAME') then
  30.       username = getenv(USERNAME)
  31.    else do
  32.           if debug then say 'ENV:USERNAME not set, using requester...'
  33.           username = rtgetstring('','Please enter your username','Username',,,res)
  34.           if res=0 then 
  35.              do 
  36.                if debug then say 'Password entry cancelled...aborting.'
  37.                exit 10
  38.              end
  39.         end
  40.    if exists('ENV:PASSWORD') then
  41.       password = getenv(PASSWORD)
  42.    else do
  43.           if debug then say 'ENV:PASSWORD not set, using requester...'
  44.           password = rtgetstring('','Please enter your password','Password',,'rtgl_invisible=true',res)
  45.           if res=0 then 
  46.              do 
  47.                if debug then say 'Password entry cancelled...aborting.'
  48.                exit 10
  49.              end
  50.         end
  51.  
  52.    netsend = 'TCP:'||pophost||'/pop3'
  53.    open(net,netsend,'A')
  54.    instring=readln(net)
  55.    check = test_str(instring)
  56.    if debug then say 'Sending: USER '||username
  57.    writeln(net,'USER '||username)
  58.    instring=readln(net)
  59.    check = test_str(instring)
  60.    if debug then say 'Sending: PASS '||password
  61.    writeln(net,'PASS '||password)
  62.    instring=readln(net)
  63.    check = test_str(instring)
  64.    if debug then say 'Sending: STAT'
  65.    writeln(net,'STAT')
  66.    instring=readln(net)
  67.    check = test_str(instring)
  68.    info = substr(instring,5,length(instring)-5)
  69.    if debug then say 'Information: <'||info||'>'
  70.    parse var info nmess ' ' noct
  71.    if debug then say 'Messages: '||nmess||'   Octets: '||noct
  72.    if nmess = 0 then 
  73.       do 
  74.         ret = rtezrequest('Sorry, no messages...',,'No Mail',,check)
  75.         exit 0
  76.       end
  77.    ret = rtezrequest('There are '||nmess||' message(s) in your mailbox','View _Headers|_Quit','Mail!',,check)
  78.    if ret=0 then do
  79.      close(net)
  80.      exit 0
  81.    end
  82.  
  83.    if ret=1 then do
  84.         open(temp,TempFile,'W')
  85.         do message = 1 to nmess
  86.            if debug then say 'Sending: TOP '||message||' 0'
  87.            writeln(net,'TOP '||message||' 0')
  88.            instring = ''
  89.            msgdate = ''
  90.            msgfrom = ''
  91.            msgsubj = ''
  92.            do until (left(instring,2)='.'||cr)
  93.               instring=readln(net)
  94.               if debug then say 'Received: '||instring
  95.               if left(instring,6)='Date: ' then
  96.                 do
  97.                  msgdate = right(instring,length(instring)-6)
  98.                  if debug then say 'Extracted: '||msgdate
  99.                 end
  100.               if left(instring,6)='From: ' then
  101.                 do
  102.                  msgfrom = instring
  103.                  if debug then say 'Extracted: '||msgfrom
  104.                 end
  105.               if left(instring,10)='Reply-to: ' then
  106.                 do
  107.                  msgrepl = instring
  108.                  if debug then say 'Extracted: '||msgrepl
  109.                 end
  110.               if left(instring,9)='Subject: ' then
  111.                 do
  112.                  msgsubj = instring
  113.                  if debug then say 'Extracted: '||msgsubj
  114.                 end
  115.            end
  116.            if msgfrom = '' then msgfrom = msgrepl
  117.            if msgfrom = '' then msgfrom = 'From: ???????????'
  118.            writeln(temp,'Message '||message||': '||msgdate)
  119.            writeln(temp,msgfrom)
  120.            writeln(temp,msgsubj)
  121.            writeln(temp,'-------------------------------------------------------')
  122.        if debug then 
  123.               do
  124.                 say 'Message '||message||': '||msgdate
  125.                 say msgfrom
  126.                 say msgsubj
  127.                 say '-------------------------------------------------------'
  128.           end
  129.         end
  130.         close(temp)
  131.         address command pager||' '||tempfile
  132.       end
  133.    exit 0
  134.  
  135.  
  136. /* ------------------------------------------------------------ */
  137. /* test_str tests the response from the POP server: +OK or -ERR */
  138. /* ------------------------------------------------------------ */
  139.  
  140. test_str:
  141.  
  142.    test = arg(1)
  143.    if debug then say 'Server Response: '||test
  144.    if pos('+OK',test)~=0 then
  145.      return 1
  146.    else
  147.      say 'Error from server: '||test
  148.      exit 10
  149.