home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / shackos2.zip / blamspam.cmd < prev    next >
OS/2 REXX Batch file  |  1997-05-21  |  11KB  |  304 lines

  1. /* To blow the spam right off the POP3 server before the mailer retrieves it */
  2. /* Copyright (c)1997 Kari Jackson for InnoVal Systems Solutions, Inc. */
  3. program="BlamSpam"
  4. infile=program||".T~$"
  5. cfgfile=program||".Cfg"
  6. interval=900 /* re-checks every 15 minutes */
  7. if stream(cfgfile,"c","query exists")="" then do
  8.    say
  9.    say "Configuration file ("cfgfile") not found."
  10.    exit
  11. end
  12. call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  13. signal on syntax name NoREXX
  14. call SysLoadFuncs
  15. signal on syntax name Syntax
  16. signal on halt name Halt
  17. "@ECHO OFF"
  18. parse arg args
  19. if translate(left(args,3))="/F:" then do
  20.    if pos('"',args)=4 then parse var args . '"' savefile '"' hackargs
  21.    else parse var args . ":" savefile hackargs
  22.    if stream(savefile,"c","query exists")="" then newfile=1
  23.    if lineout(savefile) then do
  24.       say
  25.       say "Cannot write to file" savefile"."
  26.       exit
  27.    end
  28.    if newfile=1 then call sysfiledelete savefile
  29. end
  30. else hackargs=args
  31. hackargs=strip(hackargs)
  32. again=0
  33. do forever
  34.    if again then do
  35.       parse value syscurpos() with row column
  36.       call syscurpos row, 0
  37.       say "Process complete....sleeping for" interval/60 "minutes...."
  38.       say "or press Ctrl-C to exit...."
  39.       call syssleep interval
  40.    end
  41.    else again=1
  42.    "hacksaw email get localfile("infile")" hackargs
  43.    if rc<0 then do
  44.       call TellUser CENTER 80 "HACKSAW returned error code" rc "when trying to retrieve mail. Will keep trying...."
  45.       iterate
  46.    end
  47.    if rc=0 then iterate
  48.    total=rc
  49.    headerlines="NOBODY" /* will check all header lines but not the message body */
  50.    z=0
  51.    do while lines(cfgfile)
  52.       line=translate(strip(linein(cfgfile)))
  53.       if line="" then iterate
  54.       if left(line,2)="/*" then iterate
  55.       if left(line,13)="<HEADERLINES>" then do
  56.          parse var line . "=" headerlines
  57.          iterate
  58.       end
  59.       z=z+1
  60.       parse upper var line spammer "09"x headers
  61.       if strip(headers)="" then headers=headerlines
  62.       headers=translate(headers," ",",")
  63.       spammers.z=strip(spammer)||"09"x||space(headers,1)
  64.    end
  65.    if z>0 then spammers.0=z
  66.    call lineout cfgfile
  67.    if spammers.0=0 then do
  68.       say ""
  69.       say "Configuration file ("cfgfile") does not seem to contain any entries."
  70.       exit
  71.    end
  72.    message=0
  73.    messagenumbers=""
  74.    killit=0
  75.    say ""
  76.    do while lines(infile)
  77.       origline=linein(infile)
  78.       first=1
  79.       line=translate(strip(origline))
  80.       select
  81.          when left(line,13)="-=-=-=-=-=-= " & pos(" MESSAGE [",line)>27 & ,
  82.             /* .... */ right(line,14)="] =-=-=-=-=-=-" then do
  83.             message=message+1
  84.             parse value syscurpos() with row column
  85.             call syscurpos row, 0
  86.             call charout ,"Processing message" message "of" total"...."
  87.             if savefile<>"SAVEFILE" then do
  88.                if killit then do
  89.                   call lineout savefile,"Message killed for presence of string:" reason
  90.                   do u=1 to temp.0
  91.                      call lineout savefile,temp.u
  92.                   end
  93.                end
  94.                temp.0=1
  95.                temp.1=origline
  96.             end
  97.             killit=0
  98.             r=0
  99.             do while lines(infile)
  100.                hdrline=linein(infile)
  101.                if savefile<>"SAVEFILE" then do
  102.                   temp.0=temp.0+1
  103.                   u=temp.0
  104.                   temp.u=hdrline
  105.                end
  106.                hdrline=translate(translate(hdrline," ","09"x))
  107.                select
  108.                   when left(hdrline,1)=" " then do
  109.                      msghdrs.r=msghdrs.r space(hdrline)
  110.                   end
  111.                   when strip(hdrline)="" then nop
  112.                   otherwise do
  113.                      r=r+1
  114.                      msghdrs.r=space(hdrline)
  115.                   end
  116.                end
  117.                if strip(hdrline)="" then leave
  118.             end
  119.             msghdrs.0=r
  120.             do i=1 to spammers.0
  121.                parse var spammers.i spammer "09"x headers
  122.                if headers<>oldheaders & headers<>"NOBODY" & headers<>"ENTIRE" then do
  123.                   tags.0=0
  124.                   parsethem=headers
  125.                   do until parsethem=""
  126.                      parse var parsethem this parsethem
  127.                      tags.0=tags.0+1
  128.                      q=tags.0
  129.                      if right(this,1)<>":" then this=this||":"
  130.                      tags.q=this
  131.                   end
  132.                   oldheaders=headers
  133.                end
  134.                do n=1 to msghdrs.0
  135.                   parse var msghdrs.n tag content
  136.                   hit=0
  137.                   if headers<>"ENTIRE" & headers<>"NOBODY" then do
  138.                      do j=1 to tags.0
  139.                         if tag<>tags.j then iterate
  140.                         hit=1
  141.                         leave
  142.                      end
  143.                   end
  144.                   if (hit | headers="NOBODY" | headers="ENTIRE") & ,
  145.                      pos(spammer,content)>0 then do
  146.                      killit=1
  147.                      messagenumbers=strip(messagenumbers||" "||message)
  148.                      parse value syscurpos() with row column
  149.                      call syscurpos row, 0
  150.                      string="Message #"||message||":" spammer
  151.                      say string||copies(" ",79-length(string))
  152.                      reason=spammer
  153.                   end
  154.                   if killit then leave
  155.                end
  156.                if killit then leave
  157.             end
  158.          end
  159.          when killit=0 then do i=1 to spammers.0
  160.             if first & savefile<>"SAVEFILE" then do
  161.                temp.0=temp.0+1
  162.                u=temp.0
  163.                temp.u=origline
  164.                first=0
  165.             end
  166.             parse var spammers.i spammer "09"x headers
  167.             if headers="NOBODY" then iterate
  168.             if wordpos("MSGTEXT",headers)=0 & headers<>"ENTIRE" then iterate
  169.             if pos(spammer,line)>0 then do
  170.                killit=1
  171.                messagenumbers=strip(messagenumbers||" "||message)
  172.                parse value syscurpos() with row column
  173.                call syscurpos row, 0
  174.                string="Message #"||message||":" spammer
  175.                say string||copies(" ",79-length(string))
  176.                reason=spammer
  177.             end
  178.             if killit then leave
  179.          end
  180.          otherwise if savefile<>"SAVEFILE" then do
  181.             temp.0=temp.0+1
  182.             u=temp.0
  183.             temp.u=origline
  184.          end
  185.       end
  186.    end
  187.    if killit & savefile<>"SAVEFILE" then do
  188.       call lineout savefile,"Message killed for presence of string:" reason
  189.       do u=1 to temp.0
  190.          call lineout savefile,temp.u
  191.       end
  192.       call lineout savefile,origline
  193.    end
  194.    if messagenumbers<>"" then do until rc=0
  195.       "hacksaw email mw" hackargs
  196.       if rc<0 then do
  197.          call TellUser CENTER 80 "HACKSAW returned error code" rc "when checking the number of messages on the server before deleting message(s)" messagenumbers".  Will keep trying...."
  198.          iterate
  199.       end
  200.       if rc<message then do
  201.          longline=program "wants to delete message number(s)" messagenumbers", but the POP3 server says there are fewer messages present now than there were a moment ago. "
  202.          longline=longline||"This must mean that some other program has deleted some messages from the server. Therefore," program "cannot delete these messages since there's no "
  203.          longline=longline||"way of knowing that the old message numbers still refer to the same messages!"
  204.          call TellUser CENTER 80 longline
  205.          rc=0
  206.          iterate
  207.       end
  208.       nospace=translate(messagenumbers,","," ")
  209.       "hacksaw email del mn("nospace")" hackargs
  210.       if rc=200 then do
  211.          call TellUser CENTER 80 "POP3 server says there are no messages present.  User must have deleted them before" program "could, using some other program."
  212.          rc=0
  213.       end
  214.       else if rc<>0 then do
  215.          call TellUser CENTER 80 "HACKSAW returned error code" rc "when trying to delete message number(s)" messagenumbers".  Will keep trying...."
  216.       end
  217.    end
  218.    else do
  219.       parse value syscurpos() with row column
  220.       call syscurpos row, 0
  221.       say "No messages matched the search strings.                                        "
  222.    end
  223.    call lineout infile
  224.    call sysfiledelete infile
  225.    if words(hackargs)>1 | (translate(left(hackargs,5))<>"PORT(" & hackargs<>"") then leave
  226. end
  227. exit
  228. Syntax:
  229.   say ""
  230.   say "Error" rc "in line" sigl":" errortext(rc)
  231.   say sigl":" sourceline(sigl)
  232.   exit
  233. return
  234. Halt:
  235.    say ""
  236.    say Program "interrupted by Ctrl-C, ShutDown, or closing of WorkArea."
  237.    exit
  238. return
  239. NoREXX:
  240.    call TellUser CENTER 80 "Unable to load the REXXUtil functions.  Either the REXXUTIL.DLL file is not on the LIBPATH or REXX support is not installed on this system."
  241.    exit
  242. return
  243. TellUser: procedure
  244. /* Copyright (c)1995 Kari Jackson */
  245.    parse arg format width message
  246.    if wordpos(format,"CENTER center LEFT left LINES lines")=0 then return "ERROR1"
  247.    if datatype(width,"W")=0 then return "ERROR2"
  248.    if width>80 then return "ERROR3"
  249.    if width=80 then width=79
  250.    if message="" then return "ERROR4"
  251.    width=width-4
  252.    if wordpos(format,"LINES lines")=0 then do
  253.       testing=message
  254.       testlen1=0
  255.       do until testing=""
  256.          parse var testing test testing
  257.          testlen2=length(test)
  258.          if testlen2>testlen1 then testlen1=testlen2
  259.       end
  260.       if testlen1>width then width=testlen1
  261.       if width>75 then return "ERROR5"
  262.       do q=1 until message=""
  263.          if msg.q="MSG."q then parse var message msg.q message
  264.          do until message=""
  265.             parse var message nextword message
  266.             if length(msg.q nextword) > width then do
  267.                message=nextword message
  268.                iterate q
  269.             end
  270.             else msg.q=msg.q nextword
  271.          end
  272.       end
  273.    end
  274.    else do
  275.       parse var message delimiter 2 message
  276.       do q=1 until message=""
  277.          parse var message msg.q (delimiter) message
  278.       end
  279.       testlen4=0
  280.       do c=1 to q
  281.          testlen5=length(msg.c)
  282.          if testlen5>testlen4 then testlen4=testlen5
  283.       end
  284.       if testlen4>width then width=testlen4
  285.    end
  286.    if format="left"|format="LEFT" then do
  287.       width=0
  288.       do c=1 to q
  289.          width2=length(msg.c)
  290.          if width2>width then width=width2
  291.       end
  292.    end
  293.    say
  294.    say "┌"copies("─",width+2)"┐"
  295.    if format="LEFT"|format="left" then do b=1 to q
  296.       say "│ "msg.b||copies(" ",width-length(msg.b))" │"
  297.    end
  298.    else do b=1 to q
  299.       say "│ "center(msg.b,width)" │"
  300.    end
  301.    say "└"copies("─",width+2)"┘"
  302.    say
  303. return "SUCCESS"
  304.