Postfix/procmail – preventing duplicate email in procmailrc

postfixprocmail

I've postfix on my server, I'm using procmail and customized shell script to process incoming emails for one of user accounts on my local domain/machine. (work@domain.com)

Everything was just working fine when I had only one recipient in email, but as soon as I add another recipient in email list .. I get same message twice ! (ex: sending message to work+123@doamin.com, work+456@domain.com)

There is no special configuration on main.cf, but:

mailbox_command = /usr/bin/procmail -a "EXTENSION"

and .procmailrc is as follow:

TO=`formail -xTo:`
SUBJECT=`formail -xSubject: \
| expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g'`
SENDER=`formail -xFrom: \
| expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g'`
BODY=`formail -I "" \
| expand | sed -e '1,/^$/ d' -e '1,/^$/ d'`
BODY=`formail -I "" `
SENDER=`formail -rtzxTo:`
:0 
| $HOME/bin/work.sh "$TO" "$BODY"

I was thinking to manage this issue in procmailrc , but my knowledge is so low in this case.

Best Answer

Well, obviously the solution is lock/cache file to filter duplicate Message-IDs :

:0 Wh: msgid.lock
| formail -D 8192 msgid.cache

Thanks everyone :)