home *** CD-ROM | disk | FTP | other *** search
- /* rexx:uuclean.rexx, (c) Tue, 10 May 1994 16:51:36 +0200 by "Kai 'wusel' Siering" <wusel@3jean[.uucp|.hanse.de]> */
- /*
- * $Header: rexx:uuclean.rexx,v 1.6 1994/05/12 01:38:43 wusel Exp wusel $
- * $Log: uuclean.rexx,v $
- # Revision 1.6 1994/05/12 01:38:43 wusel
- # On `Precedence: junk'áor `bulk', no warning message is sent.
- #
- # Revision 1.5 1994/05/11 03:22:23 wusel
- # Final fixes; now honours `Precedence:' header (does not include body if
- # `junk'áor `bulk'). Installed at hactar.
- #
- # Revision 1.4 1994/05/11 02:38:06 wusel
- # Testversion; now includes warning message (can be switched off).
- #
- # Revision 1.3 1994/05/11 00:55:21 wusel
- # Added args argument, `ccpostmaster' will sent a copy of all bounces to the
- # local postmaster.
- #
- # Revision 1.2 1994/05/11 00:42:33 wusel
- # Now uses new getreturnaddr() instead of relying on `R'áentry in X-file.
- #
- # Revision 1.1 1994/05/10 19:27:21 wusel
- # Minor changes; installed at hactar.
- #
- # Revision 1.0 1994/05/10 19:09:19 wusel
- # Initial revision
- #
- */
-
- parse arg spooldir wdays xdays args
-
- mailfile = 't:uuclean.'pragma('ID')'.tmp'
-
- if((right(spooldir, 1)~=":") & (right(spooldir, 1)~="/")) then spooldir=spooldir||"/"
-
- say "Cleaning UUCP spool directory "spooldir"."
-
- ccpostmaster= 0
- dowarn = 1
-
- if(index(upper(args), "NOWARN")>0) then dowarn = 0
- if(index(upper(args), "CCPOSTMASTER")>0) then ccpostmaster = 1
-
- if(dowarn) then say "Sending warnings after "wdays" days and wiping jobs older than "xdays" days."
- else say "Wiping jobs older than "xdays" days."
-
- if(dowarn) then
- do
- if(xdays <= wdays) then
- do
- say "Error: xdays must be greater than wdays, aborting."
- exit 21
- end
- end
-
- if(ccpostmaster) then say "Will send copies to local postmaster."
-
- /* open the Rexx support library */
-
- if ~show('L',"rexxsupport.library") then do
- if addlib('rexxsupport.library',0,-30,0) then do
- say 'Added rexxsupport.library'
- end
- else do
- say 'Support library (LIBS:rexxsupport.library) not available.'
- say 'Aborting...'
- exit(30)
- end
- end
-
- HostName = ''
- DomainName = ''
-
- if(open(conf, "uulib:config", r)) then do
- do while ~eof(conf)
- in=readln(conf)
-
- in2 = Translate(in, ' ', D2C(9))
- parse var in2 key cont .
-
- select
- when upper(key)="NODENAME" then HostName = strip(cont)
- when upper(key)="DOMAINNAME" then DomainName = strip(cont)
- otherwise nop
- end
- end
- err=close(conf)
- end
- else do
- say 'UUCP configuration file (UUlib:config) not found, aborting.'
- exit(20)
- end
-
- ThisSite = HostName||DomainName
- dirs = showdir(spooldir, "dir")
- numdirs = words(dirs)
- xdate = date('i') - xdays
- wdate = date('i') - wdays
-
- do dir=1 to numdirs
- currdir=spooldir||word(dirs, dir)
-
- say "Processing files in "currdir" ..."
-
- list = showdir(currdir)
- number = words(list)
- fdate = 0
-
- do i=1 to number
- filename = word(list, i)
- if(left(filename, 2) = "C.") then
- do
- fullfilename=currdir||"/"||filename
- fstat = statef(fullfilename)
- fdate = word(fstat, 5)
-
- if(word(fstat, 1) = 'FILE') then
- do
- select
- when(dowarn & (fdate = wdate)) then /* send warning message only */
- do
- files2process=parsecfile(fullfilename)
- if(words(files2process)==2) then
- do
- /*say "Processing "word(files2process, 2)" ..."*/
- xfiledata=parsexfile(currdir||"/"word(files2process, 2))
- if(words(xfiledata)>=1) then
- do
- if(compare(word(xfiledata, 1), "rmail")==0) then
- do
- isjunkmail=0
- precedence=""
- numrcpts=words(xfiledata)-2
- msgboundary=date('i')||pragma('ID')||time('s')
- retaddr=getreturnaddress(currdir||"/"word(files2process, 1))
- daysleft=xdays-wdays
-
- say "Send warning message (`"word(files2process, 1)"'): `"xfiledata"'."
- if (open(mail, mailfile, w)) then
- do
- call writeln(mail, "From: uucp@"ThisSite" (UUCP Administrator)")
- call writeln(mail, "To: "retaddr)
- if(ccpostmaster) then call writeln(mail, "Cc: postmaster@"ThisSite" (PostMaster of "hostname")")
- call writeln(mail, "Subject: Delivery delayed: cannot connect to host "word(dirs, dir)" for "wdays" days.")
- call writeln(mail, "MIME-Version: 1.0")
- call writeln(mail, "X-Version: $Id: uuclean.rexx,v 1.6 1994/05/12 01:38:43 wusel Exp wusel $")
- call writeln(mail, "Message-ID: <"msgboundary"@"ThisSite">")
- call writeln(mail, 'Content-Type: multipart/mixed; boundary="Boundary (ID 'msgboundary')"')
- call writeln(mail, "Content-Transfer-Encoding: 8bit")
- call writeln(mail, "")
- call writeln(mail, "This is a MIME encapsulated message. If you read this, you don't have a")
- call writeln(mail, "MIME compliant mail user agent, you therefore might have trouble reading")
- call writeln(mail, "this message. You have been warned ;)")
- call writeln(mail, "")
- call writeln(mail, "--Boundary (ID "msgboundary")")
- call writeln(mail, "")
- call writeln(mail, " *** THIS IS A WARNING MESSAGE ONLY ***")
- call writeln(mail, "")
- call writeln(mail, "We can't connect to host "word(dirs, dir)" for "wdays" days, your message will remain en-")
- call writeln(mail, "queued and attempts to deliver it will continue for "daysleft" more days. If the")
- call writeln(mail, "situation won't change until then, your message will be returned to you")
- call writeln(mail, "as being undeliverable. Sorry for any inconvenience.")
- call writeln(mail, "")
- call writeln(mail, "Your message is on hold for delivery to:")
- do rcpt=1 to numrcpts
- call writeln(mail, " "word(xfiledata, rcpt+2)" (via "word(dirs, dir)")")
- end
- call writeln(mail, "")
- call writeln(mail, "--Boundary (ID "msgboundary")")
- call writeln(mail, "Content-Type: message/RFC822")
- call writeln(mail, "Content-Transfer-Encoding: 8bit")
- call writeln(mail, "")
- if(open(datafile, currdir||"/"word(files2process, 1), r)) then
- do
- /* Skip `From ' line ... */
- in = readln(datafile)
- /* Copy message */
- do while ~eof(datafile)
- in = readln(datafile)
- call writeln(mail, in)
- if(left(upper(in), 11)="PRECEDENCE:") then
- do
- parse var in precedence ' ' precedence
- if((precedence="junk") | (precedence="bulk")) then isjunkmail=1
- end
- if(in = "") then break
- end
- call close(datafile)
- call writeln(mail, "[Body not included, this is just a warning message.]")
- end
- else
- do
- call writeln(mail, "[OOPS?! Can't access "currdir||"/"word(files2process, 1)"?]")
- end
- call writeln(mail, "")
- call writeln(mail, "--Boundary (ID "msgboundary")--")
- call close(mail)
- if(isjunkmail) then say "`Precedence: "precedence"', no mail sent."
- else address COMMAND "sendmail >nil: <"mailfile
- address COMMAND "delete >nil: "mailfile
- end
- end
- end
- else
- do
- say "Skipping: numargs<1 ("words(xfiledata)"); xfiledata: `"xfiledata"'."
- end
- end
- end /* when */
-
- when(fdate < xdate) then /* bounce message */
- do
- files2process=parsecfile(fullfilename)
- if(words(files2process)==2) then
- do
- /*say "Processing "word(files2process, 2)" ..."*/
- xfiledata=parsexfile(currdir||"/"word(files2process, 2))
- if(words(xfiledata)>=1) then
- do
- if(compare(word(xfiledata, 1), "rmail")==0) then
- do
- isjunkmail=0
- precedence=""
- numrcpts=words(xfiledata)-2
- msgboundary=date('i')||pragma('ID')||time('s')
- retaddr=getreturnaddress(currdir||"/"word(files2process, 1))
-
- say "Bounce email (`"word(files2process, 1)"'): `"xfiledata"'."
- if (open(mail, mailfile, w)) then
- do
- call writeln(mail, "From: uucp@"ThisSite" (UUCP Administrator)")
- call writeln(mail, "To: "retaddr)
- if(ccpostmaster) then call writeln(mail, "Cc: postmaster@"ThisSite" (PostMaster of "hostname")")
- call writeln(mail, "Subject: Returned mail: cannot connect to host "word(dirs, dir)" for "xdays" days.")
- call writeln(mail, "MIME-Version: 1.0")
- call writeln(mail, "X-Version: $Id: uuclean.rexx,v 1.6 1994/05/12 01:38:43 wusel Exp wusel $")
- call writeln(mail, "Message-ID: <"msgboundary"@"ThisSite">")
- call writeln(mail, 'Content-Type: multipart/mixed; boundary="Boundary (ID 'msgboundary')"')
- call writeln(mail, "Content-Transfer-Encoding: 8bit")
- call writeln(mail, "")
- call writeln(mail, "This is a MIME encapsulated message. If you read this, you don't have a")
- call writeln(mail, "MIME compliant mail user agent, you therefore might have trouble reading")
- call writeln(mail, "this message. You have been warned ;)")
- call writeln(mail, "")
- call writeln(mail, "--Boundary (ID "msgboundary")")
- call writeln(mail, "")
- call writeln(mail, "Can't connect to host "word(dirs, dir)" for "xdays" days, your message is therefore")
- call writeln(mail, "considered undeliverable and returned to you. Sorry for any incon-")
- call writeln(mail, "venience.")
- call writeln(mail, "")
- call writeln(mail, "Your message could not be delivered to:")
- do rcpt=1 to numrcpts
- call writeln(mail, " "word(xfiledata, rcpt+2)" (via "word(dirs, dir)")")
- end
- call writeln(mail, "")
- call writeln(mail, "--Boundary (ID "msgboundary")")
- call writeln(mail, "Content-Type: message/RFC822")
- call writeln(mail, "Content-Transfer-Encoding: 8bit")
- call writeln(mail, "")
- if(open(datafile, currdir||"/"word(files2process, 1), r)) then
- do
- /* Skip `From ' line ... */
- in = readln(datafile)
- /* Copy message */
- do while ~eof(datafile)
- in = readln(datafile)
- call writeln(mail, in)
- if(left(upper(in), 11)="PRECEDENCE:") then
- do
- parse var in precedence ' ' precedence
- if((precedence="junk") | (precedence="bulk")) then isjunkmail=1
- end
- if(isjunkmail & in="") then break
- end
- call close(datafile)
- if(isjunkmail) then call writeln(mail, "[Low priority message, body suppressed.]")
- end
- else
- do
- call writeln(mail, "[OOPS?! Can't access "currdir||"/"word(files2process, 1)"?]")
- end
- call writeln(mail, "")
- call writeln(mail, "--Boundary (ID "msgboundary")--")
- call close(mail)
- address COMMAND "sendmail >nil: <"mailfile
- address COMMAND "delete >nil: "mailfile
- address COMMAND "delete >nil: "currdir||"/"word(files2process, 1)" "currdir||"/"word(files2process, 2)" "fullfilename
- end
- end
-
- if(compare(word(xfiledata, 1), "rnews")==0) then
- do
- say "Delete newsbatch (`"word(files2process, 1)"'): `"xfiledata"'."
- address COMMAND "delete >nil: "currdir||"/"word(files2process, 1)" "currdir||"/"word(files2process, 2)" "fullfilename
- end
- end
- else
- do
- say "Skipping: numargs<1 ("words(xfiledata)"); xfiledata: `"xfiledata"'."
- end
- end
- end /* when */
-
- otherwise nop
- end /* select */
- end /* if FILE */
- end /* if C.* */
- end /* do ... end */
- end
- exit 0
-
-
- /* parsexfile(file)
- *
- * Parses a given uucp remote execution file and returns a string con-
- * sisting of the command and, in terms of `rmail' jobs, a blank, the
- * notification address according to the `R' line, and the receipient(s)
- * of this message. Returns an empty string if it isn't sure what kind
- * of file it deals with.
- *
- * (c) 10 May 1994 by Kai 'wusel'áSiering <wusel@hactar.hanse.de>
- */
- parsexfile: procedure
- arg filename
-
- out = ""
- cmd = ""
- sender= ""
- rcpt = ""
-
- if(open(file, filename, r)) then
- do
- do forever
- in = readln(file)
- if(eof(file)) then break
-
- parse var in type ' ' rest
-
- select
- when type="R" then sender=rest
- when type="C" then parse var rest cmd ' ' rcpt
- otherwise nop
- end
- end
-
- if(cmd="rmail") then out=cmd sender rcpt
- else out=cmd
-
- close(file)
- end
- else
- do
- say "Can not read from "filename"!"
- end
- return out
-
-
- /* parsecfile(file)
- *
- * Parses a given uucp control file and returns a string consisting
- * of the datafile, a blank, and the remote execution file. Returns
- * an empty string if it isn't sure what kind of command file it
- * deals with. This routine WILL NOT work with control files for
- * less or more than exactly two files.
- *
- * (c) 10 May 1994 by Kai 'wusel'áSiering <wusel@hactar.hanse.de>
- */
- parsecfile: procedure
- arg filename
-
- out = ""
- if(open(file, filename, r)) then
- do
- in = readln(file)
- parse var in direction1 srcfile1 destfile1 user1 flgs1 tmpfile1 mode1
- in = readln(file)
- if ~eof(file) then
- do
- parse var in direction2 srcfile2 destfile2 user2 flgs2 tmpfile2 mode2
- in = readln(file)
- if eof(file) then
- do
- if(left(destfile2, 2) = "X.") then
- do
- if((compare(direction1, direction2)=0) & (compare(direction1, "S")=0)) then
- do
- out = srcfile1 srcfile2
- end
- else
- do
- say "Expected two 'S' requests, got '"direction1"'/'"direction2"'."
- end
- end
- else
- do
- say "Unexpected destfile2: "destfile2"."
- end
- end
- else
- do
- say filename" has more than two files!"
- end
- end
- else
- do
- say "Can not read second line in "filename"!"
- end
- close(file)
- end
- else
- do
- say "Can not read from "filename"!"
- end
- return out
-
-
- /* getreturnaddress(file)
- *
- * Return envelope return address of given file; standard uucp mail format
- * is expected, i. e. the first line MUST read:
- *
- * "From " address " " date " remote from " remote
- *
- * `address'áis checked to contain `!', `%' or `@', if it lacks all of
- * them, the returnaddress reads `address||"@"||remote', otherwise it's
- * simply `address'. This is both simply and somewhat secure in what we
- * might find in `address'. At least we don't make the addresse worse ;)
- *
- * In case of problems, the returned argument is set to `POSTMASTER',
- * so there need to be no error checking, the returned argument is
- * always a valid address.
- *
- * (c) 11 May 1994 by Kai 'wusel'áSiering <wusel@hactar.hanse.de>
- */
-
- getreturnaddress: procedure
- arg filename
-
- addr = "POSTMASTER"
- if(open(file, filename, r)) then
- do
- in = readln(file)
- parse var in first second rest 'remote from 'remote
-
- if(first="From") then
- do
- if((index(second, "!")>0) | (index(second, "%")>0) | (index(second, "@")>0)) then do
- addr=second
- end
- else
- do
- addr=second||"@"||remote
- end
- end
- else
- do
- say "Illegal format, this is no mail?! line=`"in"'"
- end
- close(file)
- end
- else
- do
- say "Can not read from "filename"!"
- end
- return addr
-