Last active
December 14, 2015 20:48
-
-
Save Mortal/5146330 to your computer and use it in GitHub Desktop.
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
import logging | |
from lamson.routing import route, route_like, stateless | |
from config.settings import relay | |
from config import settings | |
from lamson import view, mail | |
recipients = { | |
'red': frozenset(['foo@bar.com', 'baz@example.com']), | |
'chefred': frozenset(['christina@gottsche.com']), | |
} | |
recipients['drfoek'] = recipients['red'] | |
recipients['indlaeg'] = recipients['red'] | |
catch_all = 'red' | |
@route("(address)@(host)", address=".+") | |
@stateless | |
def RELAY(message, address, host): | |
if not address in recipients: | |
emails = recipients[catch_all] | |
#rcp = [] | |
else: | |
emails = recipients[address] | |
logging.debug(u"Got a message for "+address.decode('utf-8')+u", forwarding to "+unicode(len(emails))+u" recipients") | |
if emails: | |
relay.deliver(message, To=list(emails)) | |
return RELAY | |
def relay_unknown(message, address, host): | |
"""Let the admin know that the message could not be delivered.""" | |
emails = recipients['admin'] | |
dest = 'admin@madsfoek.dk' | |
body = u'Failed to deliver the following message to '+unicode(address)+u'@'+unicode(host)+u'.\n\n' | |
for k in message.keys(): | |
body += unicode(k)+u': '+unicode(message[k])+u'\n' | |
body += u'\n'+unicode(message.body()) | |
resp = mail.MailResponse( | |
To=dest, | |
From=settings.default_from, | |
Subject=u'[lamson unknown dest] '+unicode(message['subject']), | |
Body=body) | |
#resp.attach_all_parts(message) | |
relay.deliver(resp, To=emails) | |
return True | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment