From: <bw...@lo...> - 2002-04-03 19:26:06
|
Update of /cvsroot/cvs-syncmail/syncmail In directory usw-pr-cvs1:/tmp/cvs-serv1072 Modified Files: syncmail Log Message: More Python 2.x eradication Index: syncmail =================================================================== RCS file: /cvsroot/cvs-syncmail/syncmail/syncmail,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- syncmail 3 Apr 2002 19:15:54 -0000 1.5 +++ syncmail 3 Apr 2002 19:25:58 -0000 1.6 @@ -71,9 +71,9 @@ import getopt import smtplib import pwd +import socket from cStringIO import StringIO -from socket import gethostname # Which SMTP server to do we connect to? Empty string means localhost. MAILHOST = '' @@ -156,6 +156,26 @@ +def getdomain(): + try: + fqdn = socket.getfqdn() + except AttributeError: + # Python 1.5.2 :( + hostname = socket.gethostname() + byaddr = socket.gethostbyaddr(socket.gethostbyname(hostname)) + aliases = byaddr[1] + aliases.insert(0, aliases[0]) + aliases.insert(0, hostname) + for fqdn in aliases: + if '.' in fqdn: + break + else: + fqdn = 'localhost.localdomain' + parts = string.split(fqdn, DOT) + return string.join(parts[1:], DOT) + + + def blast_mail(subject, people, filestodiff, contextlines): # cannot wait for child process or that will cause parent to retain cvs # lock for too long. Urg! @@ -167,7 +187,7 @@ conn = smtplib.SMTP() conn.connect(MAILHOST, MAILPORT) user = pwd.getpwuid(os.getuid())[0] - domain = string.join(string.split(gethostname(), DOT)[1:], DOT) + domain = getdomain() author = '%s@%s' % (user, domain) s = StringIO() sys.stdout = s |