Jaymon / stockton

Quickly setup an email server to forward a personal domain to any email address
Other
4 stars 0 forks source link

I would like a script to run for each email that comes into the server #52

Open Jaymon opened 3 years ago

Jaymon commented 3 years ago

I'd like to run a script that looks at each email that comes through the server, it looks like Postfix only supports one script being ran, and that's currently being filled using SpamAssassin:

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

And here is the SpamAssassin content filter definition:

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

So I'm thinking I should create a pipeline script that can be configured to run other scripts, the idea is I could do something like this in /etc/postfix/master.cf:

smtp      inet  n       -       n       -       -       smtpd
  -o content_filter=pipeline
...
pipeline unix  -       n       n       -       -       pipe
  user=debian-pipeline argv=/usr/bin/pipeline.py
  --script "/some/random/script/runs/before/spamc --arg val"
  --script "user=debian-spamd /usr/bin/spamc -s 1536000"
  --script "/some/random/script/runs/after/spamc --arg val"
  --script "/usr/sbin/sendmail -oi -f ${sender} ${recipient}"

The /usr/sbin/sendmail -oi -f ${sender} ${recipient} could probably be built-in to pipeline script with an option to override it I guess, but the idea is that the pipeline script would be called, and then it would run through it's configured scripts, reading the email in from stdin and then passing the output of the previous script to the stdin of the next script until it finishes running all the scripts and calls /usr/sbin/sendmail -oi -f ${sender} ${recipient}

There would need to be a way to tell pipeline what user to use for each script. I don't know if the above would actually work, but I would like to start testing this out and figuring out a path forward to support this. For instance, I'm uncertain if the -argv can be configured with a script that takes even more flags since most examples I see don't have flags.

Stuff I had open while Researching

Search