diff --git a/flask_mailman/utils.py b/flask_mailman/utils.py index d8ea9d8..a5f5b92 100644 --- a/flask_mailman/utils.py +++ b/flask_mailman/utils.py @@ -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 diff --git a/tests/test_mail.py b/tests/test_mail.py index 7200add..5ef0c64 100644 --- a/tests/test_mail.py +++ b/tests/test_mail.py @@ -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