Skip to content

Commit

Permalink
Allow optional text/plain mailcap entry.
Browse files Browse the repository at this point in the history
My use case is to constrain width:

    text/plain; fmt -w 80 -s %s
  • Loading branch information
ryneeverett authored and pazz committed Mar 21, 2020
1 parent ee919c3 commit b1c93c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
17 changes: 9 additions & 8 deletions alot/db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,16 +486,17 @@ def extract_body(mail):
return ""

displaystring = ""

if body_part.get_content_type() == 'text/plain':
rendered_payload = render_part(
body_part,
**{'field_key': 'view'} if body_part.get_content_type() == 'text/plain'
else {})
if rendered_payload: # handler had output
displaystring = string_sanitize(rendered_payload)
elif body_part.get_content_type() == 'text/plain':
displaystring = string_sanitize(remove_cte(body_part, as_string=True))
else:
rendered_payload = render_part(body_part)
if rendered_payload: # handler had output
displaystring = string_sanitize(rendered_payload)
else:
if body_part.get_content_type() == 'text/html':
displaystring = MISSING_HTML_MSG
if body_part.get_content_type() == 'text/html':
displaystring = MISSING_HTML_MSG
return displaystring


Expand Down
14 changes: 14 additions & 0 deletions tests/db/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,8 @@ def test_prefer_html_only(self):

self.assertEqual(actual, expected)

@mock.patch('alot.db.utils.settings.mailcap_find_match',
mock.Mock(return_value=(None, None)))
def test_simple_utf8_file(self):
mail = email.message_from_binary_file(
open('tests/static/mail/utf8.eml', 'rb'),
Expand All @@ -708,6 +710,18 @@ def test_simple_utf8_file(self):

self.assertEqual(actual, expected)

@mock.patch('alot.db.utils.settings.get', mock.Mock(return_value=True))
@mock.patch('alot.db.utils.settings.mailcap_find_match',
mock.Mock(return_value=(
None, {'view': 'sed "s/ is/ was/"'})))
def test_plaintext_mailcap(self):
expected = 'This was an email\n'
mail = self._make_mixed_plain_html()
actual = utils.extract_body(mail)

self.assertEqual(actual, expected)


class TestMessageFromString(unittest.TestCase):

"""Tests for decrypted_message_from_string.
Expand Down

0 comments on commit b1c93c4

Please sign in to comment.