Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to pass emails from specific senders to a shell script via procmail.

Here's my original starter script:

LOGFILE=/home/foouser/procmail-log
VERBOSE=yes
MAILDIR=/var/spool/mail/foouser
DEFAULT=/var/spool/mail/foouser
SHELL=/bin/sh

:0
! `/home/foouser/fooscript.sh`

This works fine but it applies to all messages going to foouser. I'd like to set a condition so it only sends the message to the script if the email is from specific people on a whitelist. Is this possible?

share|improve this question
1  
Incidentally, are you sure the delivery syntax is what you intend? This will try to forward the message to the address which is the output of the script /home/foouser/fooscript.sh. The script does receive the message as its standard input, but if your intent is to just pass the message to the script, the regular syntax for that is to drop the backticks and use a pipe character instead of an exclamation mark; i.e. | /home/foouser/fooscript.sh –  tripleee Aug 15 '12 at 11:14
    
@tripleee Interesting. Yes, that's exactly what I'm trying to do. I grabbed the syntax from somewhere else online. Is there any other major difference/vulnerability to using the backticks? I'm wondering if there would be an issue if the email had potentially dangerous content in it (e.g. rm -fr /). I've already hardened the script to protect against this but what about procmail? –  Mike B Aug 15 '12 at 15:02
    
If you don't intend to forward the message, definitely don't use the forwarding syntax. As far as security considerations are involved, nothing you have shown us indicates that the contents of the email are going to be evaluated as code; but if fooscript.sh does something like that internally, that's a genuine and serious concern, and you should definitely have an expert audit it. –  tripleee Aug 15 '12 at 17:56
add comment

1 Answer

up vote 3 down vote accepted

Sure, the point of procmail is to filter messages ;-)

:0
* ^From:(.*\<)?(alice@example\.org|bob@example\.com)\>
! `/home/foouser/fooscript.sh`

Edit: Fix the missing asterisk on the condition line, and reinstate the (admittedly weird) action line.

share|improve this answer
    
You sir, are my hero. Thank you. –  Mike B Aug 14 '12 at 6:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.