Quellcode durchsuchen

fix: capitalized email headers

Mikael Koli vor 3 Jahren
Ursprung
Commit
6a2a589d89

+ 9 - 9
docs/tutorials/testing.rst

@@ -40,9 +40,9 @@ in tests:
         text="Hi, this is an email.",
     )
 
-    assert str(msg) == """from: me@example.com
-    subject: Some news
-    to: you@example.com
+    assert str(msg) == """From: me@example.com
+    Subject: Some news
+    To: you@example.com
     Message-ID: <167294165062.31860.1664530310632362057@example.com>
     Content-Type: text/plain; charset="utf-8"
     Content-Transfer-Encoding: 7bit
@@ -109,9 +109,9 @@ Then to use this mock:
     )
 
     msgs = MockServer.messages
-    assert msgs == ["""from: me@example.com
-    subject: Some news
-    to: you@example.com
+    assert msgs == ["""From: me@example.com
+    Subject: Some news
+    To: you@example.com
     Message-ID: <167294165062.31860.1664530310632362057@example.com>
     Content-Type: text/plain; charset="utf-8"
     Content-Transfer-Encoding: 7bit
@@ -157,9 +157,9 @@ Then to use this class:
     )
 
     msgs = email.messages
-    assert msgs == ["""from: me@example.com
-    subject: Some news
-    to: you@example.com
+    assert msgs == ["""From: me@example.com
+    Subject: Some news
+    To: you@example.com
     Message-ID: <167294165062.31860.1664530310632362057@example.com>
     Content-Type: text/plain; charset="utf-8"
     Content-Transfer-Encoding: 7bit

+ 5 - 5
redmail/email/sender.py

@@ -400,16 +400,16 @@ class EmailSender:
 
     def _create_body(self, subject, sender, receivers=None, cc=None, bcc=None) -> EmailMessage:
         msg = EmailMessage()
-        msg["from"] = sender
-        msg["subject"] = subject
+        msg["From"] = sender
+        msg["Subject"] = subject
         
         # To whoom the email goes
         if receivers:
-            msg["to"] = receivers
+            msg["To"] = receivers
         if cc:
-            msg['cc'] = cc
+            msg['Cc'] = cc
         if bcc:
-            msg['bcc'] = bcc
+            msg['Bcc'] = bcc
 
         # Message-IDs could be produced by the first mail server
         # or the program sending the email (as we are doing now).

+ 22 - 22
redmail/test/email/test_body.py

@@ -25,9 +25,9 @@ def test_text_message():
     )
     msg = remove_email_message_id(str(msg))
     assert str(msg) == dedent("""
-    from: me@example.com
-    subject: Some news
-    to: you@example.com
+    From: me@example.com
+    Subject: Some news
+    To: you@example.com
     Message-ID: <<message_id>>
     Content-Type: text/plain; charset="utf-8"
     Content-Transfer-Encoding: 7bit
@@ -48,9 +48,9 @@ def test_html_message():
     )
     msg = remove_email_message_id(str(msg))
     assert remove_email_content_id(str(msg)) == dedent("""
-    from: me@example.com
-    subject: Some news
-    to: you@example.com
+    From: me@example.com
+    Subject: Some news
+    To: you@example.com
     Message-ID: <<message_id>>
     Content-Type: multipart/mixed; boundary="===============<ID>=="
 
@@ -83,9 +83,9 @@ def test_text_and_html_message():
     )
     msg = remove_email_message_id(str(msg))
     assert remove_email_content_id(str(msg)) == dedent("""
-    from: me@example.com
-    subject: Some news
-    to: you@example.com
+    From: me@example.com
+    Subject: Some news
+    To: you@example.com
     Message-ID: <<message_id>>
     MIME-Version: 1.0
     Content-Type: multipart/mixed; boundary="===============<ID>=="
@@ -191,9 +191,9 @@ def test_without_jinja(use_jinja_obj, use_jinja):
     )
     encoding = '7bit' if IS_PY37 else 'quoted-printable' 
     expected = dedent("""
-    from: me@example.com
-    subject: Some news
-    to: you@example.com
+    From: me@example.com
+    Subject: Some news
+    To: you@example.com
     Message-ID: <<message_id>>
     MIME-Version: 1.0
     Content-Type: multipart/mixed; boundary="===============<ID>=="
@@ -266,9 +266,9 @@ def test_set_defaults():
         for key, val in msg.items()
     }
     assert {
-        'from': 'me@gmail.com', 
-        'to': 'you@gmail.com, they@gmail.com', 
-        'subject': 'Some email', 
+        'From': 'me@gmail.com', 
+        'To': 'you@gmail.com, they@gmail.com', 
+        'Subject': 'Some email', 
         'Content-Type': 'text/plain; charset="utf-8"', 
         'Content-Transfer-Encoding': '7bit', 
         'MIME-Version': '1.0',
@@ -280,10 +280,10 @@ def test_cc_bcc():
     msg = email.get_message(sender="me@example.com", subject="Some email", cc=['you@example.com'], bcc=['he@example.com', 'she@example.com'])
     msg = remove_email_message_id(str(msg))
     assert remove_email_content_id(msg) == dedent("""
-    from: me@example.com
-    subject: Some email
-    cc: you@example.com
-    bcc: he@example.com, she@example.com
+    From: me@example.com
+    Subject: Some email
+    Cc: you@example.com
+    Bcc: he@example.com, she@example.com
     Message-ID: <<message_id>>
 
     """)[1:]
@@ -315,9 +315,9 @@ def test_no_table_templates():
         if key not in ('Message-ID',)
     }
     assert headers == {
-        'from': 'me@gmail.com', 
-        'subject': 'Some news', 
-        'to': 'you@gmail.com', 
+        'From': 'me@gmail.com', 
+        'Subject': 'Some news', 
+        'To': 'you@gmail.com', 
         'MIME-Version': '1.0', 
         'Content-Type': 'multipart/mixed',
     }

+ 4 - 4
redmail/test/email/test_cookbook.py

@@ -43,10 +43,10 @@ def test_distributions():
     msg = remove_email_message_id(str(msg))
     msg = remove_email_content_id(str(msg))
     assert msg == dedent("""
-    from: me@example.com
-    subject: Some email
-    to: me@example.com, you@example.com
-    cc: he@example.com, she@example.com
+    From: me@example.com
+    Subject: Some email
+    To: me@example.com, you@example.com
+    Cc: he@example.com, she@example.com
     Message-ID: <<message_id>>
     
     """)[1:]

+ 9 - 9
redmail/test/email/test_inline_media.py

@@ -68,9 +68,9 @@ def test_with_image_file(get_image_obj, dummy_png):
         if key not in ('Message-ID',)
     }
     assert {
-        'from': 'me@gmail.com', 
-        'subject': 'Some news', 
-        'to': 'you@gmail.com', 
+        'From': 'me@gmail.com', 
+        'Subject': 'Some news', 
+        'To': 'you@gmail.com', 
         #'MIME-Version': '1.0', 
         'Content-Type': 'multipart/mixed'
     } == headers
@@ -120,9 +120,9 @@ def test_with_image_dict_jpeg():
         if key not in ('Message-ID',)
     }
     assert {
-        'from': 'me@gmail.com', 
-        'subject': 'Some news', 
-        'to': 'you@gmail.com', 
+        'From': 'me@gmail.com', 
+        'Subject': 'Some news', 
+        'To': 'you@gmail.com', 
         #'MIME-Version': '1.0', 
         'Content-Type': 'multipart/mixed'
     } == headers
@@ -162,9 +162,9 @@ def test_with_image_obj(get_image_obj):
         if key not in ('Message-ID',)
     }
     assert {
-        'from': 'me@gmail.com', 
-        'subject': 'Some news', 
-        'to': 'you@gmail.com', 
+        'From': 'me@gmail.com', 
+        'Subject': 'Some news', 
+        'To': 'you@gmail.com', 
         #'MIME-Version': '1.0', 
         'Content-Type': 'multipart/mixed'
     } == headers

+ 3 - 3
redmail/test/email/test_template.py

@@ -69,9 +69,9 @@ def test_jinja_env(tmpdir):
     content = remove_email_message_id(content)
     content = remove_email_content_id(content)
     assert content == dedent("""
-    from: me@example.com
-    subject: Some news
-    to: you@example.com
+    From: me@example.com
+    Subject: Some news
+    To: you@example.com
     Message-ID: <<message_id>>
     MIME-Version: 1.0
     Content-Type: multipart/mixed; boundary="===============<ID>=="

+ 18 - 18
redmail/test/log/test_handler.py

@@ -27,9 +27,9 @@ def test_default_body():
                 "receivers": ["he@example.com", "she@example.com"],
             }, 
             {
-                "from": "me@example.com",
-                "to": "he@example.com, she@example.com",
-                "subject": "A log record",
+                "From": "me@example.com",
+                "To": "he@example.com, she@example.com",
+                "Subject": "A log record",
                 'Content-Transfer-Encoding': '7bit',
                 'Content-Type': 'text/plain; charset="utf-8"',
                 'MIME-Version': '1.0',
@@ -49,9 +49,9 @@ def test_default_body():
                 "fmt": '%(name)s: %(levelname)s: %(message)s'
             }, 
             {
-                "from": "me@example.com",
-                "to": "he@example.com, she@example.com",
-                "subject": "A log record",
+                "From": "me@example.com",
+                "To": "he@example.com, she@example.com",
+                "Subject": "A log record",
                 'Content-Transfer-Encoding': '7bit',
                 'Content-Type': 'text/plain; charset="utf-8"',
                 'MIME-Version': '1.0',
@@ -71,9 +71,9 @@ def test_default_body():
                 "fmt": '%(name)s: %(levelname)s: %(message)s'
             }, 
             {
-                "from": "me@example.com",
-                "to": "he@example.com, she@example.com",
-                "subject": "A log record",
+                "From": "me@example.com",
+                "To": "he@example.com, she@example.com",
+                "Subject": "A log record",
                 'Content-Transfer-Encoding': '7bit',
                 'Content-Type': 'text/plain; charset="utf-8"',
                 'MIME-Version': '1.0',
@@ -91,9 +91,9 @@ def test_default_body():
                 "receivers": ["he@example.com", "she@example.com"],
             }, 
             {
-                "from": "me@example.com",
-                "to": "he@example.com, she@example.com",
-                "subject": "Log: _test - INFO",
+                "From": "me@example.com",
+                "To": "he@example.com, she@example.com",
+                "Subject": "Log: _test - INFO",
                 'Content-Transfer-Encoding': '7bit',
                 'Content-Type': 'text/plain; charset="utf-8"',
                 'MIME-Version': '1.0',
@@ -113,9 +113,9 @@ def test_default_body():
                 "html": "<h1>{{ record.levelname }}</h1><p>{{ msg }}</p>"
             }, 
             {
-                "from": "me@example.com",
-                "to": "he@example.com, she@example.com",
-                "subject": "A log record",
+                "From": "me@example.com",
+                "To": "he@example.com, she@example.com",
+                "Subject": "A log record",
                 'Content-Type': 'multipart/mixed',
             },
             {
@@ -137,9 +137,9 @@ def test_default_body():
                 "html": "<h1>{{ record.levelname }}</h1><p>{{ record.message }}</p>"
             }, 
             {
-                "from": "me@example.com",
-                "to": "he@example.com, she@example.com",
-                "subject": "A log record",
+                "From": "me@example.com",
+                "To": "he@example.com, she@example.com",
+                "Subject": "A log record",
                 'Content-Type': 'multipart/mixed',
             },
             {

+ 24 - 24
redmail/test/log/test_handler_multi.py

@@ -35,9 +35,9 @@ def test_sender_with_login():
                 "receivers": ["he@example.com", "she@example.com"],
             }, 
             {
-                "from": "me@example.com",
-                "to": "he@example.com, she@example.com",
-                "subject": "A log record",
+                "From": "me@example.com",
+                "To": "he@example.com, she@example.com",
+                "Subject": "A log record",
                 'Content-Transfer-Encoding': '7bit',
                 'Content-Type': 'text/plain; charset="utf-8"',
                 'MIME-Version': '1.0',
@@ -57,9 +57,9 @@ def test_sender_with_login():
                 "fmt": '%(name)s - %(levelname)s - %(message)s'
             }, 
             {
-                "from": "me@example.com",
-                "to": "he@example.com, she@example.com",
-                "subject": "A log record",
+                "From": "me@example.com",
+                "To": "he@example.com, she@example.com",
+                "Subject": "A log record",
                 'Content-Transfer-Encoding': '7bit',
                 'Content-Type': 'text/plain; charset="utf-8"',
                 'MIME-Version': '1.0',
@@ -79,9 +79,9 @@ def test_sender_with_login():
                 "fmt": '%(name)s - %(levelname)s - %(message)s'
             }, 
             {
-                "from": "me@example.com",
-                "to": "he@example.com, she@example.com",
-                "subject": "A log record",
+                "From": "me@example.com",
+                "To": "he@example.com, she@example.com",
+                "Subject": "A log record",
                 'Content-Transfer-Encoding': '7bit',
                 'Content-Type': 'text/plain; charset="utf-8"',
                 'MIME-Version': '1.0',
@@ -99,9 +99,9 @@ def test_sender_with_login():
                 "receivers": ["he@example.com", "she@example.com"],
             }, 
             {
-                "from": "me@example.com",
-                "to": "he@example.com, she@example.com",
-                "subject": "Logs: INFO - INFO",
+                "From": "me@example.com",
+                "To": "he@example.com, she@example.com",
+                "Subject": "Logs: INFO - INFO",
                 'Content-Transfer-Encoding': '7bit',
                 'Content-Type': 'text/plain; charset="utf-8"',
                 'MIME-Version': '1.0',
@@ -121,9 +121,9 @@ def test_sender_with_login():
                 "html": "<h1>The records:</h1><p>{% for msg in msgs %}Log: {{ msg }}{% endfor %}</p>"
             }, 
             {
-                "from": "me@example.com",
-                "to": "he@example.com, she@example.com",
-                "subject": "A log record",
+                "From": "me@example.com",
+                "To": "he@example.com, she@example.com",
+                "Subject": "A log record",
                 'Content-Type': 'multipart/mixed',
             },
             {
@@ -145,9 +145,9 @@ def test_sender_with_login():
                 "html": "<h1>The records:</h1><p>{% for rec in records %}Log: {{ rec.levelname }} - {{ rec.message }}{% endfor %}</p>"
             }, 
             {
-                "from": "me@example.com",
-                "to": "he@example.com, she@example.com",
-                "subject": "A log record",
+                "From": "me@example.com",
+                "To": "he@example.com, she@example.com",
+                "Subject": "A log record",
                 'Content-Type': 'multipart/mixed',
             },
             {
@@ -218,9 +218,9 @@ def test_flush_multiple(logger):
     text = msg.get_payload()
 
     assert headers == {
-        "from": "None",
-        "to": "he@example.com, she@example.com",
-        "subject": "Logs: DEBUG - INFO",
+        "From": "None",
+        "To": "he@example.com, she@example.com",
+        "Subject": "Logs: DEBUG - INFO",
         'Content-Transfer-Encoding': '7bit',
         'Content-Type': 'text/plain; charset="utf-8"',
         'MIME-Version': '1.0',
@@ -254,9 +254,9 @@ def test_flush_none():
     text = msg.get_payload()
 
     assert headers == {
-        "from": "None",
-        "to": "he@example.com, she@example.com",
-        "subject": "Logs: NOTSET - NOTSET",
+        "From": "None",
+        "To": "he@example.com, she@example.com",
+        "Subject": "Logs: NOTSET - NOTSET",
         'Content-Transfer-Encoding': '7bit',
         'Content-Type': 'text/plain; charset="utf-8"',
         'MIME-Version': '1.0',