Postfix to Spamassassin, then to PHP script

Explanation

I have been using a pipe as follows to pipe incoming mail to my laravel app, but check if for spam first. The following is being used as a virtual transport

myhook unix - n n - - pipe
  flags=F user=apache argv=/usr/bin/spamc -e /usr/bin/php -f /var/www/laravel/artisan mail:incoming ${sender} ${size} ${recipient}

But really, spamc should be run with the spamd user, but if I do that then then apache cannot store the mail file as required as those files are owned by apache and laravel will try to chown newly added files.

What I'm asking

There has to be a better way to redirect mail first to spamassassin as the spamd user, then after send the output to php as apache. Or is this just not possible? Any better way to do this?

Thank you.


Solution 1:

I found success using a separate pipe for smtp such as

smtp      inet  n       -       n       -       -       smtpd
  -o content_filter=spamassassin

# ...
spamassassin unix -     n       n       -       -       pipe
    user=spamd argv=/usr/bin/spamc -f -e  
    /usr/sbin/sendmail -oi -f ${sender} ${recipient}

myhook unix - n n - - pipe
  flags=F user=apache argv=/usr/bin/php -f /var/www/laravel/artisan mail:incoming ${sender} ${size} ${recipient}

This means only incoming mail from the outside is sent to spamc, then spamc sends it back to postfix to be transported as it should be.

At first I was confused and didn't try this because I thought it would end up an endless loop of the mail sending to itself