Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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.htmlHere 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
}

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)
$VIRUSBOXwhich 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

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.

![]() |
Partition error (Redhat 7...
|
anyone else tired of poor...
|

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