forked from pazz/alot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It is suggested in pazz#862: > something like select to display a rendered version of the current mime part > (either inside the tree or in a new buffer) I played around with these options before arriving at the current behavior. Adding the mime part content to the mimetree seemed made for a very busy/over-nested screen and didn't seem all that useful. Likewise opening in another buffer doesn't seem useful and might need a new Buffer subclass in order to be well labeled. The `select` behavior I ended up going with was to change the mime part chosen by default in the Message itself. This should make implementing other commands (e.g. pipeto) on the mime parts trivial. I took `select` a step further by also having it conveniently togglemimetree off. I can't think of any use case for remaining in the mimetree view after making a selection.
- Loading branch information
1 parent
aaff899
commit 7c2906f
Showing
7 changed files
with
112 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,12 @@ | |
from ..utilities import make_key, make_uid, TestCaseClassCleanup | ||
|
||
|
||
def set_basic_headers(mail): | ||
mail['Subject'] = 'Test email' | ||
mail['To'] = '[email protected]' | ||
mail['From'] = '[email protected]' | ||
|
||
|
||
class TestGetParams(unittest.TestCase): | ||
|
||
mailstring = '\n'.join([ | ||
|
@@ -598,51 +604,11 @@ def test_encrypted_signed_in_multipart_mixed(self): | |
self.assertIn(utils.X_SIGNATURE_MESSAGE_HEADER, m) | ||
|
||
|
||
class TestExtractBody(unittest.TestCase): | ||
|
||
@staticmethod | ||
def _set_basic_headers(mail): | ||
mail['Subject'] = 'Test email' | ||
mail['To'] = '[email protected]' | ||
mail['From'] = '[email protected]' | ||
|
||
def test_single_text_plain(self): | ||
mail = EmailMessage() | ||
self._set_basic_headers(mail) | ||
mail.set_content('This is an email') | ||
actual = utils.extract_body(mail) | ||
|
||
expected = 'This is an email\n' | ||
|
||
self.assertEqual(actual, expected) | ||
|
||
@unittest.expectedFailure | ||
# This makes no sense | ||
def test_two_text_plain(self): | ||
mail = email.mime.multipart.MIMEMultipart() | ||
self._set_basic_headers(mail) | ||
mail.attach(email.mime.text.MIMEText('This is an email')) | ||
mail.attach(email.mime.text.MIMEText('This is a second part')) | ||
|
||
actual = utils.extract_body(mail) | ||
expected = 'This is an email\n\nThis is a second part' | ||
|
||
self.assertEqual(actual, expected) | ||
|
||
def test_text_plain_with_attachment_text(self): | ||
mail = EmailMessage() | ||
self._set_basic_headers(mail) | ||
mail.set_content('This is an email') | ||
mail.add_attachment('this shouldnt be displayed') | ||
|
||
actual = utils.extract_body(mail) | ||
expected = 'This is an email\n' | ||
|
||
self.assertEqual(actual, expected) | ||
class TestGetBodyPart(unittest.TestCase): | ||
|
||
def _make_mixed_plain_html(self): | ||
mail = EmailMessage() | ||
self._set_basic_headers(mail) | ||
set_basic_headers(mail) | ||
mail.set_content('This is an email') | ||
mail.add_alternative( | ||
'<!DOCTYPE html><html><body>This is an html email</body></html>', | ||
|
@@ -651,9 +617,9 @@ def _make_mixed_plain_html(self): | |
|
||
@mock.patch('alot.db.utils.settings.get', mock.Mock(return_value=True)) | ||
def test_prefer_plaintext_mixed(self): | ||
expected = 'This is an email\n' | ||
expected = "text/plain" | ||
mail = self._make_mixed_plain_html() | ||
actual = utils.extract_body(mail) | ||
actual = utils.get_body_part(mail).get_content_type() | ||
|
||
self.assertEqual(actual, expected) | ||
|
||
|
@@ -663,15 +629,15 @@ def test_prefer_plaintext_mixed(self): | |
@mock.patch('alot.db.utils.settings.mailcap_find_match', | ||
mock.Mock(return_value=(None, {'view': 'cat'}))) | ||
def test_prefer_html_mixed(self): | ||
expected = '<!DOCTYPE html><html><body>This is an html email</body></html>\n' | ||
expected = 'text/html' | ||
mail = self._make_mixed_plain_html() | ||
actual = utils.extract_body(mail) | ||
actual = utils.get_body_part(mail).get_content_type() | ||
|
||
self.assertEqual(actual, expected) | ||
|
||
def _make_html_only(self): | ||
mail = EmailMessage() | ||
self._set_basic_headers(mail) | ||
set_basic_headers(mail) | ||
mail.set_content( | ||
'<!DOCTYPE html><html><body>This is an html email</body></html>', | ||
subtype='html') | ||
|
@@ -681,9 +647,9 @@ def _make_html_only(self): | |
@mock.patch('alot.db.utils.settings.mailcap_find_match', | ||
mock.Mock(return_value=(None, {'view': 'cat'}))) | ||
def test_prefer_plaintext_only(self): | ||
expected = '<!DOCTYPE html><html><body>This is an html email</body></html>\n' | ||
expected = 'text/html' | ||
mail = self._make_html_only() | ||
actual = utils.extract_body(mail) | ||
actual = utils.get_body_part(mail).get_content_type() | ||
|
||
self.assertEqual(actual, expected) | ||
|
||
|
@@ -693,9 +659,49 @@ def test_prefer_plaintext_only(self): | |
@mock.patch('alot.db.utils.settings.mailcap_find_match', | ||
mock.Mock(return_value=(None, {'view': 'cat'}))) | ||
def test_prefer_html_only(self): | ||
expected = '<!DOCTYPE html><html><body>This is an html email</body></html>\n' | ||
expected = 'text/html' | ||
mail = self._make_html_only() | ||
actual = utils.extract_body(mail) | ||
actual = utils.get_body_part(mail).get_content_type() | ||
|
||
self.assertEqual(actual, expected) | ||
|
||
|
||
class TestExtractBodyPart(unittest.TestCase): | ||
|
||
def test_single_text_plain(self): | ||
mail = EmailMessage() | ||
set_basic_headers(mail) | ||
mail.set_content('This is an email') | ||
body_part = utils.get_body_part(mail) | ||
actual = utils.extract_body_part(body_part) | ||
|
||
expected = 'This is an email\n' | ||
|
||
self.assertEqual(actual, expected) | ||
|
||
@unittest.expectedFailure | ||
# This makes no sense | ||
def test_two_text_plain(self): | ||
mail = email.mime.multipart.MIMEMultipart() | ||
set_basic_headers(mail) | ||
mail.attach(email.mime.text.MIMEText('This is an email')) | ||
mail.attach(email.mime.text.MIMEText('This is a second part')) | ||
body_part = utils.get_body_part(mail) | ||
|
||
actual = utils.extract_body(body_part) | ||
expected = 'This is an email\n\nThis is a second part' | ||
|
||
self.assertEqual(actual, expected) | ||
|
||
def test_text_plain_with_attachment_text(self): | ||
mail = EmailMessage() | ||
set_basic_headers(mail) | ||
mail.set_content('This is an email') | ||
mail.add_attachment('this shouldnt be displayed') | ||
body_part = utils.get_body_part(mail) | ||
|
||
actual = utils.extract_body_part(body_part) | ||
expected = 'This is an email\n' | ||
|
||
self.assertEqual(actual, expected) | ||
|
||
|
@@ -705,7 +711,8 @@ def test_simple_utf8_file(self): | |
mail = email.message_from_binary_file( | ||
open('tests/static/mail/utf8.eml', 'rb'), | ||
_class=email.message.EmailMessage) | ||
actual = utils.extract_body(mail) | ||
body_part = utils.get_body_part(mail) | ||
actual = utils.extract_body_part(body_part) | ||
expected = "Liebe Grüße!\n" | ||
|
||
self.assertEqual(actual, expected) | ||
|
@@ -716,8 +723,11 @@ def test_simple_utf8_file(self): | |
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) | ||
mail = EmailMessage() | ||
set_basic_headers(mail) | ||
mail.set_content('This is an email') | ||
body_part = utils.get_body_part(mail) | ||
actual = utils.extract_body_part(body_part) | ||
|
||
self.assertEqual(actual, expected) | ||
|
||
|