1"""
2Email message and email sending related helper functions.
3"""
4
5from __future__ import annotations
6
7import socket
8
9from plain.utils.encoding import punycode
10
11
12# Cache the hostname, but do it lazily: socket.getfqdn() can take a couple of
13# seconds, which slows down the restart of the server.
14class CachedDnsName:
15 def __str__(self) -> str:
16 return self.get_fqdn()
17
18 def get_fqdn(self) -> str:
19 if not hasattr(self, "_fqdn"):
20 self._fqdn = punycode(socket.getfqdn())
21 return self._fqdn
22
23
24_DNS_NAME = CachedDnsName()