from base64 import b64encode

from django.conf import settings

from mail_factory.messages import EmailMultiRelated


class PreviewMessage(EmailMultiRelated):
    def has_body_html(self):
        """Test if a message contains an alternative rendering in text/html"""
        return 'text/html' in self.alternatives

    @property
    def body_html(self):
        """Return an alternative rendering in text/html"""
        return self.alternatives.get('text/html', '')

    @property
    def body_html_escaped(self):
        """Return an alternative rendering in text/html escaped to work in a iframe"""
        return b64encode(self.body_html)


class BasePreviewMail(object):
    """Abstract class that helps creating preview emails.

    You also may overwrite:
     * get_context_data: to add global context such as SITE_NAME
    """
    message_class = PreviewMessage

    def get_message(self, lang=None):
        """Return a new message instance based on your MailClass"""
        return self.mail.create_email_msg(self.get_email_receivers(),
                                          lang=lang,
                                          message_class=self.message_class)

    @property
    def mail(self):
        return self.mail_class(self.get_context_data())

    def get_email_receivers(self):
        """Returns email receivers."""
        return [settings.SERVER_EMAIL, ]

    def get_context_data():
        """Returns automatic context_data."""
        return {}

    @property
    def mail_class(self):
        raise NotImplementedError

@@ -1,33 +1,27 @@
-from base64 import b64encode%0A
+# -*- coding: utf-8 -*-
 %0Afro
@@ -49,16 +49,60 @@
 settings
+%0Afrom django.utils.encoding import smart_str
 %0A%0Afrom m
@@ -333,27 +333,32 @@
 in self.
-alternative
+rendering_format
 s%0A%0A    @
@@ -470,27 +470,32 @@
 rn self.
-alternative
+rendering_format
 s.get('t
@@ -536,25 +536,25 @@
 def 
-body_html_escaped
+rendering_formats
 (sel
@@ -569,126 +569,56 @@
     
-%22%22%22R
+r
 eturn 
-an alternative rendering in text/html escaped to work in a iframe%22%22%22%0A        return b64encode(self.body_html
+dict((v, k) for k, v in self.alternatives
 )%0A%0A%0A

Remove `body_html_escaped`. Add rendering filtered by formats.