Skip to content

Instantly share code, notes, and snippets.

@mallardduck
Last active February 15, 2020 23:09
Show Gist options
  • Save mallardduck/2daa41ce6c591aa898de10c947c80c1e to your computer and use it in GitHub Desktop.
Save mallardduck/2daa41ce6c591aa898de10c947c80c1e to your computer and use it in GitHub Desktop.
An Exim System Filter to create a Domain Jail for Emails
# Block example.com from sending to any other domain
if first_delivery
and ("$h_from:" contains "@example.com")
and ("$h_to:" matches "@(?!example.com)[a-z0-9_.]+")
or ("$h_cc:" matches "@(?!example.com)[a-z0-9_.]+")
or ("$h_bcc:" matches "@(?!example.com)[a-z0-9_.]+")
then
headers add "X-Org-Subject: $h_subject"
headers remove Subject
headers add "Subject: EmailJail'd: $h_x-org-subject"
headers add "X-EmailJail: This domain is under an Email Jail and cannot send mail to external domains."
seen fail "Your domain is under an Email Jail. This means you cannot send emails to external domains."
endif
@mallardduck
Copy link
Author

mallardduck commented Feb 15, 2020

UPDATE: Fixed in Rev 3.

This has a flaw when sending to multiple to addresses - if a single address has our domain, then it will send to all TO addresses.

Not sure how to fix or improve this...
https://gist.github.com/mallardduck/2daa41ce6c591aa898de10c947c80c1e#file-email_jail-L6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment