Created
January 11, 2016 23:01
-
-
Save unconfigured/e72a18f3dd12f7c4fc5c to your computer and use it in GitHub Desktop.
opensmtpd table plugin which supports regex in emails for alias lookups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install table-python to /usr/libexec/opensmtpd (https://github.com/OpenSMTPD/OpenSMTPD-extras) | |
# create file /etc/aliases with entires like | |
# mail-.*@domain.com: username | |
# use python table in opensmtpd.conf, example for vusers: | |
# table aliases python:/path/to/opensmtpd_filter_userwildcard.py | |
# table userinfo file:/etc/opensmtpd/users | |
# accept from any for domain domain.com virtual <aliases> userbase <userinfo> deliver to lmtp 127.0.0.1:2 | |
# | |
# Debug: | |
# comment out 'from table import *' and comment in last two lines, run with python | |
# run opensmtpd with smtpd -vd | |
# after starting opensmtpd, try 'smtpctl trace lookup' and look in /var/log/maillog | |
from table import * | |
import re | |
def table_update(): | |
return | |
def table_check(service, dict, key): | |
return | |
def table_lookup(service, dict, key): | |
if (service != K_ALIAS): | |
return | |
for line in open("/etc/aliases"): | |
if line.startswith("#"): | |
continue | |
if not line.strip(): | |
continue | |
(mail, alias) = line.split(':', 2) | |
if re.match(mail, key): | |
return alias.strip() | |
return | |
def table_fetch(service, dict): | |
return | |
#K_ALIAS=1 | |
#print table_lookup(K_ALIAS, {}, "mail-.*@domain.com") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment