From 0763c8e1c35f667031fc51db9f8f80c3ccce67ce Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 23 Feb 2017 09:46:42 +0530 Subject: [PATCH] Function ordering --- src/calibre/utils/smtp.py | 46 +++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/calibre/utils/smtp.py b/src/calibre/utils/smtp.py index e9626aea7f..93419e956d 100644 --- a/src/calibre/utils/smtp.py +++ b/src/calibre/utils/smtp.py @@ -13,6 +13,29 @@ import sys, traceback, os, socket, encodings.idna as idna from calibre import isbytestring, force_unicode +def safe_localhost(): + # RFC 2821 says we should use the fqdn in the EHLO/HELO verb, and + # if that can't be calculated, that we should use a domain literal + # instead (essentially an encoded IP address like [A.B.C.D]). + fqdn = socket.getfqdn() + if '.' in fqdn: + # Some mail servers have problems with non-ascii local hostnames, see + # https://bugs.launchpad.net/bugs/1256549 + try: + local_hostname = idna.ToASCII(force_unicode(fqdn)) + except: + local_hostname = 'localhost.localdomain' + else: + # We can't find an fqdn hostname, so use a domain literal + addr = '127.0.0.1' + try: + addr = socket.gethostbyname(socket.gethostname()) + except socket.gaierror: + pass + local_hostname = '[%s]' % addr + return local_hostname + + def get_msgid_domain(from_): from email.utils import parseaddr try: @@ -79,29 +102,6 @@ def get_mx(host, verbose=0): return [str(x.exchange) for x in answers if hasattr(x, 'exchange')] -def safe_localhost(): - # RFC 2821 says we should use the fqdn in the EHLO/HELO verb, and - # if that can't be calculated, that we should use a domain literal - # instead (essentially an encoded IP address like [A.B.C.D]). - fqdn = socket.getfqdn() - if '.' in fqdn: - # Some mail servers have problems with non-ascii local hostnames, see - # https://bugs.launchpad.net/bugs/1256549 - try: - local_hostname = idna.ToASCII(force_unicode(fqdn)) - except: - local_hostname = 'localhost.localdomain' - else: - # We can't find an fqdn hostname, so use a domain literal - addr = '127.0.0.1' - try: - addr = socket.gethostbyname(socket.gethostname()) - except socket.gaierror: - pass - local_hostname = '[%s]' % addr - return local_hostname - - def sendmail_direct(from_, to, msg, timeout, localhost, verbose, debug_output=None): import calibre.utils.smtplib as smtplib