Skip to content

Commit

Permalink
fix: pre-encodes FQDN str with punycode to avoid #62
Browse files Browse the repository at this point in the history
  • Loading branch information
tkzt committed Nov 28, 2023
1 parent 12534b9 commit 1f902be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flask_mailman/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __str__(self):

def get_fqdn(self):
if not hasattr(self, '_fqdn'):
self._fqdn = socket.getfqdn()
self._fqdn = punycode(socket.getfqdn())
return self._fqdn


Expand Down
7 changes: 7 additions & 0 deletions tests/test_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,13 @@ def test_none_body(self):
self.assertEqual(msg.body, "")
self.assertEqual(msg.message().get_payload(), "")

@mock.patch("socket.getfqdn", return_value="漢字")
def test_non_ascii_dns_non_unicode_email(self, mocked_getfqdn):
delattr(DNS_NAME, "_fqdn")
email = EmailMessage("subject", "content", "from@example.com", ["to@example.com"])
email.encoding = "iso-8859-1"
self.assertIn("@xn--p8s937b>", email.message()["Message-ID"])

def test_encoding(self):
"""
Regression for #12791 - Encode body correctly with other encodings
Expand Down

0 comments on commit 1f902be

Please sign in to comment.