Hiya,

I'm having sort of a strange problem with my postfix installation.

I have Local users and users with forwards. Some can have more than one 
forward, say we have Original-Recipient a...@a.test<mailto:a...@a.test> that 
forwards to local b...@a.test<mailto:b...@a.test> and remote 
c...@b.test<mailto:c...@b.test> . At first, my remote user did not get the mail 
at all. I suspected the remote end, but some debugging showed that it was the 
Postfix that simply did not deliver to remote destinations when forwarding. 
Having thought about this for some time I ended up with a solution that at 
least managed to ship mails to the remote user. But now the local user gets 2 
mails, one that is clearly destined for b...@a.test<mailto:b...@a.test>, but 
also one that is destined for c...@b.test<mailto:c...@b.test>.

Postfix receives the mail, handles greylisting, quota, spf, dkim and other 
lovelies. Then sends it off via "content_filter=scan:127.0.0.1:10025" to 
clamsmtp. This returns on port 10026 with this listener from master.cf

127.0.0.1:10026 inet    n       -       -       -       -       smtpd
        -o spamassassin_destination_recipient_limit=1
        -o content_filter=spamassassin
        -o 
receive_override_options=no_header_body_checks,no_unknown_recipient_checks
        -o smtpd_helo_restrictions=
        -o smtpd_client_restrictions=
        -o smtpd_sender_restrictions=
        -o smtpd_recipient_restrictions=permit_mynetworks,reject
        -o mynetworks_style=host
        -o default_transport=smtp:
        -o smtpd_authorized_xforward_hosts=127.0.0.0/8


Here it then sends it further into the content_filter=spamassassin

spamassassin unix - n n - - pipe
    flags=DROXhu user=vmail:vmail argv=/usr/local/bin/xMTPDeliver ${sender} 
${user} ${nexthop}

xMTPDeliver examines ${user} and ${nexthop} to see where it is supposed to go 
local/remote. If it is local, we use dovecot-lda to deliver it directly into 
users spam-folder if marked as spam, otherwise into users inbox. Fairly 
straight forward.


#!/bin/bash

# Author: s...@danskkabeltv.dk - 20170507
# Description:
# Check if USER@DOMAIN is a local delivery.
# If it is - deliver through dovecot-LDA after scanning.
# Otherwise ship via SMTP (probably localhost..)

SMTP="/usr/sbin/sendmail -oi"
LMTP="/usr/lib/dovecot/deliver"
SPAM="/usr/bin/spamc"
LOG="/usr/bin/logger -p mail.info -t filter"

## Final Destination delivery.
SENDER=$1
USER=$2
DOMAIN=$3

# Note: aliases/forwards should be resolved at this point -
# otherwise they will be put in queue again.
# If 0 - then
IS_LOCAL=`/usr/sbin/postmap -q ${USER}@${DOMAIN} 
mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf | wc -l`

## This local. Send to spamc + dovecot-LDA
if [ ${IS_LOCAL} -gt 0 ] ; then
        ${LOG} "Delivering to local user (${USER}@${DOMAIN})"
        ${SPAM} -f -e ${LMTP} -f ${SENDER} -d ${USER}@${DOMAIN}
else
## External domain - deliver through SMTP
        ${LOG} "Delivering to remote user (${USER}@${DOMAIN})"
        ${SPAM} -f -e ${SMTP} -f ${SENDER} -t ${USER}@${DOMAIN}


But somehow, somewhere - b...@a.test<mailto:b...@a.test> gets 2 mails, second 
mail b...@a.test<mailto:b...@a.test> does not even mention 
b...@a.test<mailto:b...@a.test> - but through and through looks like a mail to 
c...@b.test<mailto:c...@b.test> .. The debug shows that 2 mails are being 
generated as expected, one goes through the IS_LOCAL statement, whereas the 
other goes through the "Deliver through SMTP" and I suspect it is here 
something goes awry, that it sees "Oi, this one is really for 
a...@a.test<mailto:a...@a.test> - which is also aliased to 
b...@a.test<mailto:b...@a.test>". But I cannot see where to fix that particular 
problem.

Any takers (or suggestions for changes)

Best regards
Søren P. Skou

Reply via email to