# Path: courriers/backends/base.py
# class BaseBackend(object):
#     def register(self, email, lang=None, user=None):
#         raise NotImplemented
# 
#     def unregister(self, email, user=None):
#         raise NotImplemented
# 
#     def exists(self, email, user=None):
#         raise NotImplemented
# 
#     def send_mails(self, newsletter):
#         raise NotImplemented
# 
# Path: courriers/settings.py
# DEFAULT_FROM_EMAIL = getattr(
#     settings, "COURRIERS_DEFAULT_FROM_EMAIL", settings.DEFAULT_FROM_EMAIL
# )
# 
# PRE_PROCESSORS = getattr(settings, "COURRIERS_PRE_PROCESSORS", ())
# 
# Path: courriers/utils.py
# def load_class(class_path, setting_name=None):
#     """
#     Loads a class given a class_path. The setting value may be a string or a
#     tuple.
# 
#     The setting_name parameter is only there for pretty error output, and
#     therefore is optional
#     """
#     if not isinstance(class_path, str):
#         try:
#             class_path, app_label = class_path
#         except Exception:
#             if setting_name:
#                 raise exceptions.ImproperlyConfigured(
#                     CLASS_PATH_ERROR % (setting_name, setting_name)
#                 )
#             else:
#                 raise exceptions.ImproperlyConfigured(
#                     CLASS_PATH_ERROR % ("this setting", "It")
#                 )
# 
#     try:
#         class_module, class_name = class_path.rsplit(".", 1)
#     except ValueError:
#         if setting_name:
#             txt = "%s isn't a valid module. Check your %s setting" % (
#                 class_path,
#                 setting_name,
#             )
#         else:
#             txt = "%s isn't a valid module." % class_path
#         raise exceptions.ImproperlyConfigured(txt)
# 
#     try:
#         mod = import_module(class_module)
#     except ImportError as e:
#         if setting_name:
#             txt = 'Error importing backend %s: "%s". Check your %s setting' % (
#                 class_module,
#                 e,
#                 setting_name,
#             )
#         else:
#             txt = 'Error importing backend %s: "%s".' % (class_module, e)
# 
#         raise exceptions.ImproperlyConfigured(txt)
# 
#     try:
#         clazz = getattr(mod, class_name)
#     except AttributeError:
#         if setting_name:
#             txt = (
#                 'Backend module "%s" does not define a "%s" class. Check'
#                 " your %s setting" % (class_module, class_name, setting_name)
#             )
#         else:
#             txt = 'Backend module "%s" does not define a "%s" class.' % (
#                 class_module,
#                 class_name,
#             )
#         raise exceptions.ImproperlyConfigured(txt)
#     return clazz


from .base import BaseBackend
from django.core import mail
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
from django.utils import translation
from django.contrib.auth import get_user_model
from ..settings import DEFAULT_FROM_EMAIL, PRE_PROCESSORS
from ..utils import load_class
                    {"object": newsletter, "subscriber": subscriber},
                ),
                DEFAULT_FROM_EMAIL,
                [subscriber.email],
                connection=connection,
            )

            html = render_to_string(
                "courriers/newsletter_raw_detail.html",
                {
                    "object": newsletter,
                    "items": newsletter.items.all().prefetch_related("newsletter"),
                    "subscriber": subscriber,
                },
            )

            for pre_processor in PRE_PROCESSORS:
                html = load_class(pre_processor)(html)

            email.attach_alternative(html, "text/html")

            emails.append(email)

        translation.activate(old_language)

        results = connection.send_messages(emails)

        newsletter.sent = True
        newsletter.save(update_fields=("sent",))


# Path: courriers/backends/base.py
# class BaseBackend(object):
#     def register(self, email, lang=None, user=None):
#         raise NotImplemented
# 
#     def unregister(self, email, user=None):
#         raise NotImplemented
# 
#     def exists(self, email, user=None):
#         raise NotImplemented
# 
#     def send_mails(self, newsletter):
#         raise NotImplemented
# 
# Path: courriers/settings.py
# DEFAULT_FROM_EMAIL = getattr(
#     settings, "COURRIERS_DEFAULT_FROM_EMAIL", settings.DEFAULT_FROM_EMAIL
# )
# 
# PRE_PROCESSORS = getattr(settings, "COURRIERS_PRE_PROCESSORS", ())
# 
# Path: courriers/utils.py
# def load_class(class_path, setting_name=None):
#     """
#     Loads a class given a class_path. The setting value may be a string or a
#     tuple.
# 
#     The setting_name parameter is only there for pretty error output, and
#     therefore is optional
#     """
#     if not isinstance(class_path, str):
#         try:
#             class_path, app_label = class_path
#         except Exception:
#             if setting_name:
#                 raise exceptions.ImproperlyConfigured(
#                     CLASS_PATH_ERROR % (setting_name, setting_name)
#                 )
#             else:
#                 raise exceptions.ImproperlyConfigured(
#                     CLASS_PATH_ERROR % ("this setting", "It")
#                 )
# 
#     try:
#         class_module, class_name = class_path.rsplit(".", 1)
#     except ValueError:
#         if setting_name:
#             txt = "%s isn't a valid module. Check your %s setting" % (
#                 class_path,
#                 setting_name,
#             )
#         else:
#             txt = "%s isn't a valid module." % class_path
#         raise exceptions.ImproperlyConfigured(txt)
# 
#     try:
#         mod = import_module(class_module)
#     except ImportError as e:
#         if setting_name:
#             txt = 'Error importing backend %s: "%s". Check your %s setting' % (
#                 class_module,
#                 e,
#                 setting_name,
#             )
#         else:
#             txt = 'Error importing backend %s: "%s".' % (class_module, e)
# 
#         raise exceptions.ImproperlyConfigured(txt)
# 
#     try:
#         clazz = getattr(mod, class_name)
#     except AttributeError:
#         if setting_name:
#             txt = (
#                 'Backend module "%s" does not define a "%s" class. Check'
#                 " your %s setting" % (class_module, class_name, setting_name)
#             )
#         else:
#             txt = 'Backend module "%s" does not define a "%s" class.' % (
#                 class_module,
#                 class_name,
#             )
#         raise exceptions.ImproperlyConfigured(txt)
#     return clazz


# Path: courriers/backends/simple.py
from .base import BaseBackend
from django.core import mail
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
from django.utils import translation
from django.contrib.auth import get_user_model
from ..settings import DEFAULT_FROM_EMAIL, PRE_PROCESSORS
from ..utils import load_class

                    {"object": newsletter, "subscriber": subscriber},
                ),
                DEFAULT_FROM_EMAIL,
                [subscriber.email],
                connection=connection,
            )

            html = render_to_string(
                "courriers/newsletter_raw_detail.html",
                {
                    "object": newsletter,
                    "items": newsletter.items.all().prefetch_related("newsletter"),
                    "subscriber": subscriber,
                },
            )

            for pre_processor in PRE_PROCESSORS:
                html = load_class(pre_processor)(html)

            email.attach_alternative(html, "text/html")

            emails.append(email)

        translation.activate(old_language)

        results = connection.send_messages(emails)

        newsletter.sent = True
        newsletter.save(update_fields=("sent",))


        return results