def wrapped(message, host=None, address=None): """processes forwarding rules, and run the handler in the case of error, send a bounce email """ try: for rule in django_settings.LAMSON_FORWARD: if re.match(rule['pattern'], message.base['to']): relay = Relay(host=rule['host'], port=rule['port'], debug=1) relay.deliver(message) return except AttributeError: pass error = None try: reply_address = ReplyAddress.objects.get( address=address, allowed_from_email=message.From) #here is the business part of this function func(from_address=message.From, subject_line=message['Subject'], parts=get_parts(message), reply_address_object=reply_address) except ReplyAddress.DoesNotExist: error = _("You were replying to an email address\ unknown to the system or you were replying from a different address from the one where you\ received the notification.") except Exception, e: import sys sys.stderr.write(str(e)) import traceback sys.stderr.write(traceback.format_exc())
def PROCESS(message, address = None, host = None): """handler to process the emailed message and make a post to askbot based on the contents of the email, including the text body and the file attachments""" try: for rule in django_settings.LAMSON_FORWARD: if re.match(rule['pattern'], message.base['to']): relay = Relay(host=rule['host'], port=rule['port'], debug=1) relay.deliver(message) return except AttributeError: pass error = None try: reply_address = ReplyAddress.objects.get( address = address, allowed_from_email = message.From ) parts = get_parts(message) if reply_address.was_used: reply_address.edit_post(parts) else: reply_address.create_reply(parts) except ReplyAddress.DoesNotExist: error = _("You were replying to an email address\ unknown to the system or you were replying from a different address from the one where you\ received the notification.") except Exception, e: import sys sys.stderr.write(str(e)) import traceback sys.stderr.write(traceback.format_exc())
def PROCESS(message, address = None, host = None): """handler to process the emailed message and make a post to askbot based on the contents of the email, including the text body and the file attachments""" try: for rule in settings.LAMSON_FORWARD: if re.match(rule['pattern'], message.base['to']): relay = Relay(host=rule['host'], port=rule['port'], debug=1) relay.deliver(message) return except AttributeError: pass error = None try: reply_address = ReplyAddress.objects.get( address = address, allowed_from_email = message.From ) separator = _("======= Reply above this line. ====-=-=") parts = get_body(message).split(separator) attachments = get_attachments(message) if len(parts) != 2 : error = _("Your message was malformed. Please make sure to qoute \ the original notification you received at the end of your reply.") else: reply_part = parts[0] reply_part = '\n'.join(reply_part.splitlines(True)[:-3]) #the function below actually posts to the forum if reply_address.was_used: reply_address.edit_post( reply_part.strip(), attachments = attachments ) else: reply_address.create_reply( reply_part.strip(), attachments = attachments ) except ReplyAddress.DoesNotExist: error = _("You were replying to an email address\ unknown to the system or you were replying from a different address from the one where you\ received the notification.") except Exception, e: import sys sys.stderr.write(str(e)) import traceback sys.stderr.write(traceback.format_exc())
def wrapped(message, host = None, address = None): """processes forwarding rules, and run the handler in the case of error, send a bounce email """ try: for rule in django_settings.LAMSON_FORWARD: if re.match(rule['pattern'], message.base['to']): relay = Relay(host=rule['host'], port=rule['port'], debug=1) relay.deliver(message) return except AttributeError: pass error = None try: reply_address = ReplyAddress.objects.get( address = address, allowed_from_email = message.From ) #here is the business part of this function parts = get_parts(message) for part_type, content in parts: if part_type == 'body': print '===============================' print 'message :', content break else: continue func( from_address = message.From, subject_line = message['Subject'], parts = parts, reply_address_object = reply_address ) except ReplyAddress.DoesNotExist: error = _("You were replying to an email address\ unknown to the system or you were replying from a different address from the one where you\ received the notification.") except Exception, e: import sys sys.stderr.write(str(e)) import traceback sys.stderr.write(traceback.format_exc())
def wrapped(message, host = None, address = None): """processes forwarding rules, and run the handler in the case of error, send a bounce email """ try: for rule in django_settings.LAMSON_FORWARD: if re.match(rule['pattern'], message.base['to']): relay = Relay(host=rule['host'], port=rule['port'], debug=1) relay.deliver(message) return except AttributeError: pass error = None try: reply_address = ReplyAddress.objects.get(address = address) #allowed_from_email = message.From <- used to have this filter too #here is the business part of this function parts = get_parts(message) func( from_address = message.From, subject_line = message['Subject'], parts = parts, reply_address_object = reply_address ) except ReplyAddress.DoesNotExist: error = _("You were replying to an email address\ unknown to the system or you were replying from a different address from the one where you\ received the notification.") except Exception as e: import sys sys.stderr.write(unicode(e).encode('utf-8')) import traceback sys.stderr.write(unicode(traceback.format_exc()).encode('utf-8')) if error is not None: from askbot.mail.messages import ReplyByEmailError email = ReplyByEmailError({'error': error}) email.send([message.From])
def wrapped(message, host=None, address=None): """processes forwarding rules, and run the handler in the case of error, send a bounce email """ try: for rule in django_settings.LAMSON_FORWARD: if re.match(rule['pattern'], message.base['to']): relay = Relay(host=rule['host'], port=rule['port'], debug=1) relay.deliver(message) return except AttributeError: pass error = None try: reply_address = ReplyAddress.objects.get(address=address) # allowed_from_email = message.From <- used to have this filter too # here is the business part of this function parts = get_parts(message) func(from_address=message.From, subject_line=message['Subject'], parts=parts, reply_address_object=reply_address) except ReplyAddress.DoesNotExist: error = _("You were replying to an email address\ unknown to the system or you were replying from a different address from the one where you\ received the notification.") except Exception: import traceback traceback.print_exc() if error is not None: from askbot.mail.messages import ReplyByEmailError email = ReplyByEmailError({'error': error}) email.send([message.From])
def PROCESS(message, address = None, host = None): try: for rule in settings.LAMSON_FORWARD: if re.match(rule['pattern'], message.base['to']): relay = Relay(host=rule['host'], port=rule['port'], debug=1) relay.deliver(message) return except AttributeError: pass error = None try: reply_address = ReplyAddress.objects.get_unused(address, message.From) separator = _("======= Reply above this line. ====-=-=") parts = message.body().split(separator) if len(parts) != 2 : error = _("Your message was malformed. Please make sure to qoute \ the original notification you received at the end of your reply.") else: reply_part = parts[0] reply_part = '\n'.join(reply_part.splitlines(True)[:-3]) reply_address.create_reply(reply_part.strip()) except ReplyAddress.DoesNotExist: error = _("You were replying to an email address\ unknown to the system or you were replying from a different address from the one where you\ received the notification.") if error is not None: from askbot.utils import mail from django.template import Context from askbot.skins.loaders import get_template template = get_template('reply_by_email_error.html') body_text = template.render(Context({'error':error})) mail.send_mail( subject_line = "Error posting your reply", body_text = body_text, recipient_list = [message.From], )
import os import logging import logging.config from django.conf import settings from lamson.routing import Router from lamson.server import Relay, SMTPReceiver from lamson import queue import ecs.ecsmail.monkey relay = Relay(host= settings.EMAIL_HOST, port= settings.EMAIL_PORT, starttls= settings.EMAIL_USE_TLS, username = settings.EMAIL_HOST_USER, password= settings.EMAIL_HOST_PASSWORD) # Monkey Patch deliver so it will use ecsmail settings (and django backends) relay.deliver = ecs.ecsmail.monkey.deliver receiver = SMTPReceiver(settings.ECSMAIL ['listen'], settings.ECSMAIL ['port']) Router.defaults(host= '.+') Router.load(settings.ECSMAIL ['handlers']) Router.RELOAD = False Router.UNDELIVERABLE_QUEUE = queue.Queue(settings.ECSMAIL ['queue_dir'])