Skip to content

Commit

Permalink
split envelope.body into text and html strings
Browse files Browse the repository at this point in the history
.. that can be individually edited and will form the plaintext and html
alternatives in constructed emails.
  • Loading branch information
pazz committed Jan 10, 2020
1 parent 5286b5b commit e067ea2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion alot/buffers/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def rebuild(self):
self.attachment_wgt = urwid.Pile(lines)
displayed_widgets.append(self.attachment_wgt)

self.body_wgt = urwid.Text(string_sanitize(self.envelope.body))
self.body_wgt = urwid.Text(string_sanitize(self.envelope.body_txt))
displayed_widgets.append(self.body_wgt)
self.body = urwid.ListBox(displayed_widgets)

Expand Down
2 changes: 1 addition & 1 deletion alot/commands/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def openEnvelopeFromTmpfile():
headertext += '%s: %s\n' % (key, value)

# determine editable content
bodytext = self.envelope.body
bodytext = self.envelope.body_txt
if headertext:
content = '%s\n%s' % (headertext, bodytext)
self.edit_only_body = False
Expand Down
2 changes: 1 addition & 1 deletion alot/commands/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ async def apply(self, ui):
for line in self.message.get_body_text().splitlines():
mailcontent += quote_prefix + line + '\n'

envelope.body = mailcontent
envelope.body_txt = mailcontent

for a in self.message.get_attachments():
envelope.attach(a)
Expand Down
14 changes: 8 additions & 6 deletions alot/db/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class Envelope:
"""
dict containing the mail headers (a list of strings for each header key)
"""
body = None
"""mail body as unicode string"""
body_txt = None
"""mail body (plaintext) as unicode string"""
body_html = None
"""mail body (html) as unicode string"""
tmpfile = None
"""template text for initial content"""
attachments = None
Expand Down Expand Up @@ -77,8 +79,8 @@ def __init__(
if template:
self.parse_template(template)
logging.debug('PARSED TEMPLATE: %s', template)
logging.debug('BODY: %s', self.body)
self.body = bodytext or ''
logging.debug('BODY: %s', self.body_txt)
self.body_txt = bodytext or ''
# TODO: if this was as collections.defaultdict a number of methods
# could be simplified.
self.headers = headers or {}
Expand All @@ -96,7 +98,7 @@ def __init__(
self.account = account

def __str__(self):
return "Envelope (%s)\n%s" % (self.headers, self.body)
return "Envelope (%s)\n%s" % (self.headers, self.body_txt)

def __setitem__(self, name, val):
"""setter for header values. This allows adding header like so:
Expand Down Expand Up @@ -183,7 +185,7 @@ def construct_mail(self):
"""
# Build body text part. To properly sign/encrypt messages later on, we
# convert the text to its canonical format (as per RFC 2015).
canonical_format = self.body.encode('utf-8')
canonical_format = self.body_txt.encode('utf-8')
textpart = MIMEText(canonical_format, 'plain', 'utf-8')

# wrap it in a multipart container if necessary
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/test_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_get_template_decode(self):
self.assertEqual({'To': [to],
'From': [_from],
'Subject': [subject]}, cmd.envelope.headers)
self.assertEqual(body, cmd.envelope.body)
self.assertEqual(body, cmd.envelope.body_txt)


class TestExternalCommand(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/db/test_envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ def test_parse_template(self):
'To': ['bar@example.com, baz@example.com'],
'Subject': ['Fwd: Test email']
})
self.assertEqual(envlp.body,
self.assertEqual(envlp.body_txt,
'Some body content: which is not a header.')

0 comments on commit e067ea2

Please sign in to comment.