def get_backends(): from mailserver import get_setting backends = [] for backend_path in get_setting("MAIL_AUTHENTICATION_BACKENDS"): backends.append(load_backend(backend_path)) return backends
def get_response(self, request): # Helper method to provide nice responses for errors. # 'cause you know people do not read Mailer Delivery errors... from_email = get_setting('MAIL_DAEMON_ADDRESS') context = self.get_context(request) if self.template_name is None: body = "Temporary delivery failure" else: t = loader.get_template(self.template_name) body = t.render(RequestContext(request, context)) subject = self.subject if subject is None: subject = "Mail delivery problem" response = EmailResponse(from_email=from_email, to=request['From'], body=body, subject=subject) response.status_code = self.status_code return response
def __call__(self, environ, request): resolver = None try: mailconf = getattr(request, "mailconf", get_setting('ROOT_MAILCONF')) resolver = resolvers.RegexMailResolver(r'', mailconf) response = self.call(resolver, environ, request) return self.handle_response(response) except SystemExit: raise except: exc_info = sys.exc_info() exc = exc_info[1] if hasattr(exc, 'get_response'): response = exc.get_response(request) if response is not None: return self.handle_response(response) self.handle_uncaught_exception(request, resolver, exc_info) raise DeliveryError("Unhandled temporary error")
def get_standard_processors(): from mailserver import get_setting global _standard_context_processors if _standard_context_processors is None: processors = [] for path in get_setting('MAIL_TEMPLATE_CONTEXT_PROCESSORS'): i = path.rfind('.') module, attr = path[:i], path[i+1:] try: mod = __import__(module, {}, {}, [attr]) except ImportError, e: raise ImproperlyConfigured('Error importing request processor module %s: "%s"' % (module, e)) try: func = getattr(mod, attr) except AttributeError: raise ImproperlyConfigured('Module "%s" does not define a "%s" callable request processor' % (module, attr)) processors.append(func) _standard_context_processors = tuple(processors)
def load_middleware(self): """ Populate middleware lists from settings.MAIL_MIDDLEWARE_CLASSES. """ from django.core import exceptions from mailserver import get_setting self._view_middleware = [] self._response_middleware = [] self._exception_middleware = [] request_middleware = [] for middleware_path in get_setting('MAIL_MIDDLEWARE'): try: dot = middleware_path.rindex('.') except ValueError: raise exceptions.ImproperlyConfigured, '%s isn\'t a middleware module' % middleware_path mw_module, mw_classname = middleware_path[:dot], middleware_path[dot+1:] try: mod = __import__(mw_module, {}, {}, ['']) except ImportError, e: raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e) try: mw_class = getattr(mod, mw_classname) except AttributeError: raise exceptions.ImproperlyConfigured, 'Middleware module "%s" does not define a "%s" class' % (mw_module, mw_classname) try: mw_instance = mw_class() except exceptions.MiddlewareNotUsed: continue if hasattr(mw_instance, 'process_request'): request_middleware.append(mw_instance.process_request) if hasattr(mw_instance, 'process_view'): self._view_middleware.append(mw_instance.process_view) if hasattr(mw_instance, 'process_response'): self._response_middleware.insert(0, mw_instance.process_response) if hasattr(mw_instance, 'process_exception'): self._exception_middleware.insert(0, mw_instance.process_exception)
def get_resolver(mailconf): if mailconf is None: from mailserver import get_setting mailconf = get_setting('ROOT_MAILCONF') return RegexMailResolver(r'', mailconf)