Use the IDNA encoding for non-ascii hostnames

This commit is contained in:
Kovid Goyal 2013-12-02 13:22:43 +05:30
parent b91fb7b502
commit 26e978bc2f

View File

@ -9,9 +9,8 @@ This module implements a simple commandline SMTP client that supports:
* Background delivery with failures being saved in a maildir mailbox * Background delivery with failures being saved in a maildir mailbox
''' '''
import sys, traceback, os, socket import sys, traceback, os, socket, encodings.idna as idna
from calibre import isbytestring from calibre import isbytestring, force_unicode
from calibre.utils.filenames import ascii_text
def create_mail(from_, to, subject, text=None, attachment_data=None, def create_mail(from_, to, subject, text=None, attachment_data=None,
attachment_type=None, attachment_name=None): attachment_type=None, attachment_name=None):
@ -71,7 +70,7 @@ def safe_localhost():
# Some mail servers have problems with non-ascii local hostnames, see # Some mail servers have problems with non-ascii local hostnames, see
# https://bugs.launchpad.net/bugs/1256549 # https://bugs.launchpad.net/bugs/1256549
try: try:
local_hostname = ascii_text(fqdn) local_hostname = idna.ToASCII(force_unicode(fqdn))
except: except:
local_hostname = 'localhost.localdomain' local_hostname = 'localhost.localdomain'
else: else: