When I started typing this it didn't work- I've now got it working.

A few days ago I mentioned on the mailing list that I wanted to come up with
an MTA-independant way of generating a file suitable for use as the
LocalAddresses flatfile. This is what I have so far, it is damned ugly all
piped together, but this is how I have to do things as I don't know any
programming languages, I would love to rewrite this in perl and have it read
the locations from assp.cfg-

grep -h "recipient accepted unchecked:" d:\assp\logs\*maillog.txt |cut -f
5- -d:|cut -b 2- |sort|uniq -i | grep -f d:\assp\lists\localdomains.txt|
grep -vf
d:\assp\lists\spamtrapaddresses.txt >d:\assp\lists\localaddresses.txt

This is one single command line, running on standard linux/bsd and windows
with the unxutil tools in the path. I'm so nearly there, it is just the very
last part that fails. I am hoping to have this as a bat file that I can run
and it will produce a file that I can use as my local addresses flatfile.


Let me explain how this all works-

grep -h "recipient accepted unchecked:" d:\assp\logs\*maillog.txt

grep searches files and returns the lines that match the text that you
specify. This command says 'find me all the lines that contain "recipient
accepted unchecked: " in the logs directory. I rotate my log files on a
daily basis and keep them in a directory called logs, this is all built in
to ASSP. The -h just keeps path and file names out of the output. The output
looks like this- Oct-21-06 01:51:06 193.111.201.133
<[EMAIL PROTECTED]> to: [EMAIL PROTECTED] recipient
accepted unchecked: [EMAIL PROTECTED]

The next bit is the pipe command "|" in most command lines this means send
the output from the previous command to the next one.

cut -f 5- -d:

Cut is another posix comand that will cut up text files. It has three modes,
two of which I use here. This bit was pure luck- the address I want is on
the end of the line. So, this says look along the line and break it into a
number of fields- these fields are normally delimited on the tab character,
we don't have any of them but we do have a number of colons. The -f says use
the fields based mode and -d: says use the colon as the field break and the
5- says use the fifth field to the end of the line. At this point the output
looks like this-
 [EMAIL PROTECTED]

cut -c 2-

The first cut takes everything after the fifth colon, which includes an
annoying space before the email address. This cut command uses the character
mode to cut everything from the second character to the end of the line,
i.e. ignore the space. The third mode is the binary mode (-b), in this
instance the -b and -c give the same output. I am not sure when they would
ever differ so I have stuck with -c. The output now looks like-
[EMAIL PROTECTED]

sort

This does an alphabetic sort on the output- this is needed for the next
command.

uniq -i

This command NEEDS an alphabeticaly sorted list but what it will do is
remove duplicates. The -i means ignore case.

grep -f d:\assp\lists\localdomains.txt

We are almost there- we have a file in a working format with a little bit of
cruft in there. We run this next command to remove all of the people we have
sent email to. It uses the local domains list to return only email addresses
contain OUR domains. This does the right thing with commented lines (tested
lots)

grep -vf d:\assp\lists\spamtrapaddresses.txt

We now have a list of all local addresses, the problem here is that it will
still contain addresses that haven't or hadn't yet been added to the spam
trap list. The email address I picked for the example is an address a
spammer has made up and KEEPS trying. In the last 25 hours I have had 249
attempts to send emails to addresses that have never been valid. This grep
uses the -v to invert the output, i.e. it will remove addresses that are
found on the spam trap list.

> d:\assp\lists\localaddresses.txt

This last command sends the output to a text file- this one being my final
goal, the list of valid local addresses. As this list is rebuilt from
scratch using a single > will overwrite the existing file. If you use a >>
it will append your output to an exisitng file, creating it if it doesn't
exist.

As I said, I'd like this in perl really. I have tested this on a box running
Windows NT4 with the unxutils from sourceforge. I have also tested this on
an OpenBSD 3.7 box. This is posix compliant meaning it should run on just
about all *nixes.

Bro
-- 
"I'm sick and tired of hearing that 'health and safety' is stopping people
doing worthwhile and enjoyable things. If you're using health and safety to
stop everyday activities, get a life and let others get on with theirs."
Bill Callaghan (Health and Safety Commission chair)



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Assp-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/assp-user

Reply via email to