Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Replace hacky functions with html2text library for automatic HTML to …
Browse files Browse the repository at this point in the history
…Text conversion when only HTML is provided in the email message
  • Loading branch information
jpsca committed Apr 17, 2016
1 parent f0d04dd commit 29dbc89
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 149 deletions.
2 changes: 1 addition & 1 deletion mailshake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@

Mailer = ToConsoleMailer

__version__ = '0.11.2'
__version__ = '0.12.0'
67 changes: 0 additions & 67 deletions mailshake/html2text.py

This file was deleted.

10 changes: 7 additions & 3 deletions mailshake/mailers/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
"""
SMTP mailer.
"""
import smtplib
import ssl
import threading
try:
import smtplib
import ssl
import threading
except ImportError:
pass

from .base import BaseMailer
from ..utils import sanitize_address, DNS_NAME


class SMTPMailer(BaseMailer):

"""A wrapper that manages the SMTP network connection.
"""

Expand Down
10 changes: 8 additions & 2 deletions mailshake/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
import mimetypes
import os

import html2text

from . import _compat as compat
from .html2text import extract_text_from_html
from .utils import forbid_multi_line_headers, make_msgid


textify = html2text.HTML2Text()

# Don't BASE64-encode UTF-8 messages
email.charset.add_charset('utf-8', email.charset.SHORTEST, None, 'utf-8')
utf8_charset = email.charset.Charset('utf-8')
Expand All @@ -26,6 +29,7 @@


class MIMEMixin(object):

def as_string(self, unixfrom=False):
"""Return the entire formatted message as a string.
Optional `unixfrom' when True, means include the Unix From_ envelope
Expand Down Expand Up @@ -85,8 +89,10 @@ def __setitem__(self, name, val):


class EmailMessage(object):

"""A container for email information.
"""

content_subtype = 'plain'
mixed_subtype = 'mixed'
html_subtype = 'html'
Expand Down Expand Up @@ -135,7 +141,7 @@ def __init__(self, subject='', text='', from_email=None, to=None,
text = compat.force_text(text or text_content or '')
html = compat.force_text(html or html_content or '')
if html and not text:
text = extract_text_from_html(html)
text = textify.handle(html)
self.text = text
self.html = html

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
html2text
76 changes: 0 additions & 76 deletions tests/test_html2text.py

This file was deleted.

0 comments on commit 29dbc89

Please sign in to comment.