Computing.Net > Forums > Linux > perl scripts for filtering mail

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

perl scripts for filtering mail

Reply to Message Icon

Name: Joe
Date: September 3, 2002 at 11:39:28 Pacific
Comment:

Hello,

I'm quite new to linux and am trying to figure out the best way to filter mail on a linux server the office I work at uses. I've tried learning about procmail, but it seems like I could really cause damage to our email configuration if I tinkered with it. I'm considering using a perl script to filter mail.
But before I do I was wondering about a few things. For one, it looks like perl is included with our installation of linux under the path /usr/bin/perl. Is this an adequate version of perl to use for filtering emails?
Also, I have very little scripting experience, so is there any good resources (books, websites) that anyone can recommend for using perl with linux.
What it is we need to filter are emails with .exe, .pif, and .scr attachments. We dont want those. If anyone has sample perl code for blocking mail like this, could you please email it to me (or post it)?
One last question. Even once I have a script for doing this, where would I place it so that it executes on every email that's sent?

Thank you,
Joe



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: September 4, 2002 at 04:39:32 Pacific
Reply:

Procmail is a powerful and helpful utility for filtering and processing mail before it is delivered to the user's mail box. Worth spending the time to understand.

http://www.procmail.org
http://www.ling.helsinki.fi/users/reriksso/procmail/mini-faq.html

Here is a sample procmail recipe that denies the deliver of executables.

ext = '\.(scr|vbs|shs|bat|com|exe|pif|pdf)'
ws = '[ ]*($[ ]+)*'
dotstar = '.*($[ ].*)*'

:0 B
* ! ^FROM_DAEMON
* ! ^X-Loop: virusfilter
* $ ^Content-(Type|Disposition)*:${dotstar}name${ws}=${ws}${dq}.*${ext}${dq}
{
:0af
| (formail -fr \
-i"Subject: Returned email -- file type rejected" \
-A"X-Loop: virusfilter" ; \
echo "***********************************************************************" ; \
echo "* This is a computer-generated response *" ;\
echo "***********************************************************************" ; \
echo "We apologize but the Acme email server does not allow employees" ; \
echo "to receive executable (EXE) files through email transmissions. Executable" ; \
echo "files often contain viruses that have not been sent by the actual person" ; \
echo "but by a virus. If you will "zip" the file up and resend your message then" ; \
echo "the intended recipient will receive the message." ; \
echo "Again we apologize for the inconvenience.") \
| /usr/sbin/sendmail -t

:0:
$TYPE_REJECT
}


0

Response Number 2
Name: ugh
Date: September 4, 2002 at 04:51:19 Pacific
Reply:

If you have "very little scripting expertise" you are likely to cause a lot more trouble writing your own script than by putting in a little procmail directive. It could be as simple as

:0 B:
* ^Content-Transfer-Encoding: base64
* name=.*\.(exe|bat|scr|pif)
$VIRUSBOX

which would place such stuff to a file previously assigned to a variable VIRUSBOX.

Read some procmail guide for further details, e.g. http://www.spambouncer.org/proctut.shtml


0

Response Number 3
Name: 3Dave
Date: September 4, 2002 at 09:19:10 Pacific
Reply:

Back to perl (just 'coz I like it!=o) try O'Reilly's "Perl in a Nutshell". You may not use it for filtering mail but I'm sure you can come across other uses for it.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Partition error (Redhat 7... anyone else tired of poor...



Post Locked

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


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: perl scripts for filtering mail

Script for read files in a director www.computing.net/answers/linux/script-for-read-files-in-a-director/28504.html

bash script for generating mails www.computing.net/answers/linux/bash-script-for-generating-mails/19428.html

Perl scripts? www.computing.net/answers/linux/perl-scripts/5282.html