home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / madpop10.zip / madpop.cmd next >
OS/2 REXX Batch file  |  1994-09-21  |  8KB  |  204 lines

  1. /*
  2.  
  3.                 ***** READ THIS WHOLE SECTION BEFORE USING *****
  4.  
  5.         I wouldn't want for you to use this software while laboring
  6.         under misconceptions that could lead to a bad end.
  7.  
  8.     Copyright:
  9.  
  10.         MADPOP.CMD - Ultra-simple REXX-based POP3 Client for OS/2 2.X,
  11.         Copyright 1994, Michael Alan Dorman.
  12.  
  13.     Warranty:
  14.  
  15.         This software comes with absolutely no warranty.  While it was
  16.         not written with destructive intent, Michael Alan Dorman shall
  17.         not be held responsible for any loss or damages of or to
  18.         person or property resulting from the use of this software. 
  19.         Use at your own risk.  You have the source code.
  20.  
  21.     Distribution:
  22.  
  23.         There is no restriction on the distribution of this software,
  24.         as long as it is not altered. If you decide that you simply
  25.         must ignore this and change or "enhance" a few things anyway,
  26.         please at least be polite enough to take my name off it and
  27.         change the name of the file so I don't spend time looking at
  28.         questions about someone else's changes.  If you want to send
  29.         me copies of your changes, feel free--I'll certainly look at
  30.         them--but don't expect me to support them.
  31.  
  32.     Requirements:
  33.  
  34.         This package requires IBM TCP/IP 2.0 with the REXX Sockets
  35.         (RxSock) interface (which was a separate package until the
  36.         June 1994 CSD).  You are responsible for making sure they are
  37.         installed and working correctly.  You should thank Paul
  38.         Mueller for producing this package in the first place, but
  39.         don't bug him about problems with MADPOP.
  40.  
  41.     Support:
  42.  
  43.         This software comes with absolutely no support.  OK, it might
  44.         come with just a little.  Mail me at mdorman@mallet.tiac.net
  45.         (for the moment, not valid after 10/14/94) if you have a
  46.         problem.  If I have an easy answer, I'll almost certainly give
  47.         it to you.  If it requires research on my part, I may do it,
  48.         it depends on whether or not I think the problem you need
  49.         solved might apply to others.  Do not expect any significant
  50.         enhancements to the functionality of this software.
  51.  
  52.         I know this might seem unkind, but you have to remember that I
  53.         was not (and am not) looking to produce an add-on for another
  54.         mailer--this was a first pass at routines for my shareware
  55.         mailer to use, and I'm releasing them because I like basking
  56.         in the adulation of worshipful users, and I figure it might
  57.         make some people well-disposed to looking at (and maybe paying
  58.         the shareware fee for) my mailer once it's done.  Nothing else.
  59.  
  60.     Usage:
  61.  
  62.         Assuming that you've read the above, and haven't been so
  63.         offended as to feel that it is your moral obligation to
  64.         eradicate this program from your HD, here's what you do:
  65.  
  66.             madpop llama.tdkcs.com mdorman ziggurat
  67.  
  68.         where 'madpop' is the name of this REXX file, 'llama.tdkcs.com'
  69.         is replaced by the name of your POP3 host, 'mdorman' is
  70.         replaced by the name of your account on the POP3 host, and
  71.         'ziggurat' is replaced by the password for your account on the
  72.         POP3 host.  The program will then retrieve mail from the host
  73.         and leave it in its current directory in files named
  74.         ?????.pop, where the five '?' characters are guaranteed to
  75.         produce an unique filename.
  76.  
  77.         That's it.  Nothing more.  No fancy 'periodic checks', no
  78.         deleting of mail, no adding to inbox files.  If you're using
  79.         LaMail, you should be able to use the MAKENDX executable found
  80.         in LAMPOP to update the INBOX.NDX file--but I've not even
  81.         tested this (since it would have required installing
  82.         LaMail--which is what I'm writing my own mailer to avoid), so
  83.         I don't know.  Any other mail system (elm, UltiMail) and
  84.         you're on your own, though if you're successful I'd love to
  85.         have a copy of the instructions.
  86.  
  87.         Anyway, my boss is looking over my shoulder, so I gotta go.
  88.  
  89.         Mike Dorman, 9/21/94
  90. */
  91.  
  92. main:
  93.     parse arg servername username password
  94.  
  95.     call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  96.     call SysLoadFuncs
  97.  
  98.     call RxFuncAdd 'SockLoadFuncs', 'RxSock', 'SockLoadFuncs'
  99.     call SockLoadFuncs
  100.  
  101.     if SockGetHostByName(servername, 'host.') \= 0 then do
  102.         socket = SockSocket('AF_INET', 'SOCK_STREAM', 0)
  103.         if socket \= -1 then do
  104.             server.family = 'AF_INET'
  105.             server.port = 110
  106.             server.addr = host.addr
  107.             if SockConnect(socket, 'server.') \= -1 then do
  108.                 if GetReply(socket) then do
  109.                     call SendLine socket, 'USER ' || username
  110.                     if GetReply(socket) then do
  111.                         call SendLine socket, 'PASS ' || password
  112.                         if GetReply(socket) then do
  113.                             call SendLine socket, 'STAT'
  114.                             if GetReply(socket) then do
  115.                                 parse var response.1 status messages octets
  116.                                 say 'You have ' || messages || ' messages waiting, ' || octets || ' bytes.'
  117.                                 do msgi = 1 to messages
  118.                                     say 'Getting message ' || msgi
  119.                                     call SendLine socket, 'RETR ' || msgi
  120.                                     if GetReply(socket, 1) then do
  121.                                         mailfile = SysTempFileName('?????.mmm')
  122.                                         do line = 2 to response.0
  123.                                             call lineout mailfile, response.line
  124.                                         end
  125.                                     end ; else do
  126.                                         say 'Failed at RETR ' || msgi || ': ' || errno
  127.                                     end
  128.                                 end
  129.                             end ; else do
  130.                                 say 'Failed at STAT: ' || errno
  131.                             end
  132.                         end ; else do
  133.                             say 'Failed at PASS: ' || errno
  134.                         end
  135.                     end ; else do
  136.                         say 'Failed at USER: ' || errno
  137.                     end
  138.                 end ; else do
  139.                     say 'Failed at OPEN: ' || errno
  140.                 end
  141.                 call SendLine socket, 'QUIT'
  142.             end ; else do
  143.                 say 'Failed at Connect: ' || errno
  144.             end
  145.             call SockSoClose socket
  146.         end ; else do
  147.             say 'Failed at Socket: ' || errno
  148.         end
  149.     end ; else do
  150.         say 'Failed at Resolve: ' || errno
  151.     end
  152. exit
  153.  
  154. GetReply: procedure expose response.
  155.     socket = arg(1)
  156.  
  157.     response.0 = 1
  158.     response.1 = GetLine(socket)
  159.  
  160.     if arg(2) = 1 then do
  161.         do forever
  162.             o = response.0 + 1
  163.             response.o = GetLine(socket)
  164.             if (response.o = '.') then do
  165.                 leave
  166.             end
  167.             response.0 = o
  168.         end
  169.     end
  170.  
  171.     if left(response.1, 1) = '+' then do
  172.         return 1
  173.     end
  174. return 0
  175.  
  176. GetLine: procedure expose lb
  177.     socket = arg(1)
  178.  
  179.     if symbol('lb') = 'LIT' then do
  180.         lb = ''
  181.     end
  182.  
  183.     do while pos('0d0a'x, lb) = 0
  184.         rc = SockRecv(socket, 'data', 8000)
  185.         lb = lb || data
  186.     end
  187.  
  188.     p = pos('0d0a'x,lb)
  189.  
  190.     line = substr(lb,1,p-1)
  191.     lb = substr(lb,p+2)
  192. return line
  193.  
  194. SendLine: procedure
  195.     socket = arg(1)
  196.     sent = SockSend(socket, arg(2) || '0d0a'x)
  197.  
  198.     if (sent <= 0) then do
  199.         say 'Failed at SEND: ' || errno
  200.         call SockSoClose socket
  201.         exit
  202.     end
  203. return 0
  204.