Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi there,
I need some help where I want to create a small batch file that will search inside all the text files (email files to be precise - *.eml) in a specific given directory (d:\archive) for specific strings.
Basically my plan is this:
We receive a LOT of spam email that is archived. Rather than manually sift through the whole lot I would like to run a batch script on the directory that will search for the specific words such as "Viagra", or "Pills" or etc etc - you know, the normal spam related emails.
The script will have a look in each email; if it finds such a string it will simply delete the file and move on to the next one.
Doing this will automatically eliminate a lot of the bulk of spam, leaving us to search a much smaller amount for false positive emails caught up in the spam filter.
Unfortunately I don't know how to write such a file, so any help would be very gratefully appreciated.
Many thanks,
Dale.

Once you're satisfied it will work, remove the ECHO from the last line to 'activate' it.
=============================
:: delete emails containing spam words@echo off
setLocal EnableDelayedExpansionpushd d:\archive
for /f "tokens=* delims= " %%e in ('dir/b/a-d *.eml') do (
for /f "tokens=* delims= " %%a in (%%e) do (
echo %%a | find "viagra" > nul
if not errorlevel 1 echo del %%e
)
)
=====================================
If at first you don't succeed, you're about average.M2

Thanks very much for that, for the 'find' bit, what is the syntax for adding multiple entries?
i.e. Find "Viagra" and "Pills" and "Head" and "Arms" etc?
Many thanks again.

EDIT:
I've tried the script so far and I see these errors:
http://www.zen87038.zen.co.uk/image...
Any pointers?
Many thanks....

"IF" you are using Outlook or Outlook Express you can do this filtering using email rules. Many spam mails now add text in picture format so neither my suggestion or batch files will find these.
Once you get spam you are stuck with it and "it will keep growing". The only real answer is to change your email address then review your approach. Whatever else you do is fighting a losing battle - I've been down that road.
Never leave your email in "open text" on a website (for example). I have just found yours by simply clicking on your name here then using Google. If Google can find it then the spammers engines will also find it. By now it will be part of data bases that they sell to each other across the world so you can never undo this.
Machines won't click on your name so leaving your email set on this website is "reasonably" safe.
some other bloke...

Thanks Derek, unfortunately its not really a case of setting up junk email rules on local Outlook accounts. Basically as a company we receive an absolutely ludicrous amount of spam each day already (somewhere near 10,000).
Our external (Linux) mail server handles a fair amount of this, but a lot will sift through to Exchange where IMF filters out the rest. As a result end users actually don't receive much spam at all, but the problem is picking up all the false positives.
Now what we have at the moment is IMF archives all the spam it picks up, we then go through it to check for false positives.
But the majority of spam we receive is in fact text based, and using specific words (although I know exactly what you mean by the image spams) - if I can auto-filter these out with a little script that will delete them, then this is just going to make our job of sifting through the other emails that much quicker.
The issue I have is that I have ZERO experience in writing anything like this - hence the cry for help as I just don't know where to start...

I must have been having a senior moment.
::== DELspam3.bat
:: delete emails containing spam words@echo off
setLocal EnableDelayedExpansionpushd d:\archive
for /f "tokens=* delims= " %%w in (wordlist) do (
for /f "tokens=* delims= " %%e in ('dir/b/a-d *.eml') do (
find "%%w" < %%e > nul
if not errorlevel 1 del "%%e"
)
)
=====================================
If at first you don't succeed, you're about average.M2

Hi again,
Many thanks for that, I've posted up a link to a screenie of the latest 'error':
http://www.zen87038.zen.co.uk/image...
You can see that I tried to search for the word "afternoon" which was contained inside an email (also pictured) but the batch file returned the error: "The system cannot find the file afternoon."
Not sure if this is a user error by me though!
Thanks so much for all this help.

Hi,
I think I goofed. You'd asked if it could search for mulitple 'spam words' so I made the first FOR loop use a list of words {I called it WORDLIST]. You need to create your own list of words. Call it whatever you like, but it must be the file named in the first FOR loop.
I couldn't make anything of that error JPG
=====================================
If at first you don't succeed, you're about average.M2

![]() |
System won't boot after M...
|
Media Player won't play A...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |