summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorpacien <pacien.trangirard@pacien.net>2019-11-15 17:00:07 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2019-11-23 08:36:14 +0000
commit45829f7956716638fe77989a50eb87d3ea34cace (patch)
tree31a2f974db95daa8fac629baa9ca5a19baf58294 /tests
parentf57505160af4304b5f99a83beb2316a12dcc90aa (diff)
envelope: correctly handle folded headers
Diffstat (limited to 'tests')
-rw-r--r--tests/db/test_envelope.py35
1 files changed, 21 insertions, 14 deletions
diff --git a/tests/db/test_envelope.py b/tests/db/test_envelope.py
index be318b0d..b7612f37 100644
--- a/tests/db/test_envelope.py
+++ b/tests/db/test_envelope.py
@@ -28,20 +28,6 @@ SETTINGS = {
}
-def email_to_dict(mail):
- """Consumes an email, and returns a dict of headers and 'Body'."""
- split = mail.splitlines()
- final = {}
- for line in split:
- if line.strip():
- try:
- k, v = line.split(':')
- final[k.strip()] = v.strip()
- except ValueError:
- final['Body'] = line.strip()
- return final
-
-
class TestEnvelope(unittest.TestCase):
def assertEmailEqual(self, first, second):
@@ -100,3 +86,24 @@ class TestEnvelope(unittest.TestCase):
e.attach(f.name)
self._test_mail(e)
+
+ @mock.patch('alot.db.envelope.settings', SETTINGS)
+ def test_parse_template(self):
+ """Tests multi-line header and body parsing"""
+ raw = (
+ 'From: foo@example.com\n'
+ 'To: bar@example.com,\n'
+ ' baz@example.com\n'
+ 'Subject: Test email\n'
+ '\n'
+ 'Some body content: which is not a header.\n'
+ )
+ envlp = envelope.Envelope()
+ envlp.parse_template(raw)
+ self.assertDictEqual(envlp.headers, {
+ 'From': ['foo@example.com'],
+ 'To': ['bar@example.com, baz@example.com'],
+ 'Subject': ['Test email']
+ })
+ self.assertEqual(envlp.body,
+ 'Some body content: which is not a header.')