How do I set up a email whitelist using only procmailrc to protect my kids from unwanted email?

2

2

How do I set up a email whitelist using only procmailrc to protect my kids from unwanted email?

I currently us the OS parental controls, but that is only good for the computer it is enabled on.

I understand that as my kids grow up, they'll figure out work arounds to any technical parental restrictions imposed upon them, but I want to at least understand the options that I have until then.

hanleyp

Posted 2009-09-05T12:59:08.533

Reputation: 6 519

I've done this for sending reminders to my phone - I'll post the recipe when I can ssh to my server :) – warren – 2009-09-14T12:33:05.397

added the whitelist recipe as promised :) – warren – 2009-09-16T12:59:36.397

Nice stuff. I'll have to try this out as well. – pave – 2009-09-16T13:07:11.707

Answers

1

procmail can filter by the From header, and there are many recipe examples.

# This one discards all mail sent from the address below.
:0
* ^From: idiot@somehost.com
/dev/null

But don't forget that procmail only works with locally delivered mail. It won't affect mailboxes accessed over IMAP or webmail.

user1686

Posted 2009-09-05T12:59:08.533

Reputation: 283 655

This is a blacklist recipe. Do you know how to do it the opposite? Such as only allow mail from certain addresses. – hanleyp – 2009-09-05T16:59:42.247

1Just change the recipe to use ${DEFAULT} as the mailbox, then add a second recipe that routes the rest to /dev/null. – user1686 – 2009-09-06T08:07:09.100

@RoninTom's answer is simpler and more to the point. – tripleee – 2013-05-17T08:10:09.180

1

I'm not at all sure where I got this from (I know I didn't write it myself), but I've been using it in a .procmailrc for a while now to forward only messages from an address listed in a separate whitelist file to a given target email address:

PMDIR=$HOME/Procmail      # Make sure this directory exists!
TARGET=something@example.com

# allow any addresses listed in $PMDIR/whitelist
WHITELIST=$PMDIR/whitelist
FROM_ADDR=`formail -zxFrom: | sed 's/\(.*[^-_\.0-9a-zA-Z]\)\?\([-_\.0-9a-zA-Z]\+@[-_\.0-9a-zA-Z]\+\).*/\2/'`
:0
* ? fgrep -xs "$FROM_ADDR" "$WHITELIST"
! $TARGET

Isaac

Posted 2009-09-05T12:59:08.533

Reputation: 192

1

The one I use to send messages from myself to my phone:

VERBOSE=off
LOGFILE=/dev/null

# if it comes from a specific address(es), send to my cell
# it's be just as easy to whitelist a domain by adding another `|domain.tld` section to the bracketed regex
:0
* ^From.*[main.email.domain.tld|other.email.domain.tld]
* ^To.*datente
! 0000000000@vtext.com

# push everything else to my normal user
:0 
* .
! mainuser

warren

Posted 2009-09-05T12:59:08.533

Reputation: 8 599

also note: I intentionally only gather email sent to the one domain, not any others hosted on the same server – warren – 2009-09-18T05:23:24.663

1

I think we have not any solution yet, that exactly solves the initial problem. Therefore, I would like to provide a more explicit approach. Lets suppose, that our whitelist looks like this:

white.domain.tld
light.domain.tld

Then I would try the following reciept:

:0
* !^From.*@white\.domain\.tld
* !^From.*@light\.domain\.tld
/dev/null

This would send all emails that are not from somebody@white.domain.tld and not from somebody@light.domain.tld to /dev/null. The remaining emails are send to the default destination. Be aware to use \. in your pattern if you like to match a single dot. The pattern . matches a single character.

If you have a short whitelist, you could try to get an even shorter reciept by combining the patterns:

:0
* !^From.*@(white|light)\.domain\.tld
/dev/null

Be aware to use ( ) here. Using [ ] would be a mistake.

Ronin Tom

Posted 2009-09-05T12:59:08.533

Reputation: 111