From: Barry A. W. <bw...@us...> - 2004-03-12 22:57:38
|
Update of /cvsroot/cvs-syncmail/syncmail In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8401 Modified Files: syncmail Log Message: Jacob Moorman related a patch by Ari Gordon-Schlosberg to use the GECOS field in the From header. His patch didn't appear to be against the head of our CVS, and we were pretty close anyway. I took the opportunity to clean some things up though: - reorder the imports into Guido order :) - get rid of the funky splitting of the gecos field on commas, and use email.Utils.formataddr() to combine the realname and the address. This should properly quote any names with weird punctuation in them (like that of some co-project-admin I know) - get rid of the binding of sys.stdout since we can now use print>> (does that rock or what?) - bump to version 1.4 Index: syncmail =================================================================== RCS file: /cvsroot/cvs-syncmail/syncmail/syncmail,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- syncmail 23 Jan 2004 15:57:28 -0000 1.38 +++ syncmail 12 Mar 2004 22:48:58 -0000 1.39 @@ -88,18 +88,19 @@ email-addrs At least one email address. """ -__version__ = '1.3' +__version__ = '1.4' import os -import sys import re +import pwd +import sys import time import getopt -import smtplib -import pwd import socket +import smtplib from cStringIO import StringIO +from email.Utils import formataddr # Which SMTP server to do we connect to? MAILHOST = 'localhost' @@ -222,38 +223,33 @@ conn.connect(MAILHOST, MAILPORT) pwinfo = pwd.getpwuid(os.getuid()) user = pwinfo[0] - name = pwinfo[4].split(',')[0] + name = pwinfo[4] domain = fromhost or socket.getfqdn() address = '%s@%s' % (user, domain) s = StringIO() - sys.stdout = s datestamp = time.strftime('%a, %d %b %Y %H:%M:%S +0000', time.gmtime(time.time())) - try: - vars = {'address' : address, - 'name' : quotename(name), - 'people' : COMMASPACE.join(people), - 'subject' : subject, - 'version' : __version__, - 'date' : datestamp, - } - print '''\ -From: %(name)s <%(address)s> + vars = {'author' : formataddr((name, address)), + 'people' : COMMASPACE.join(people), + 'subject' : subject, + 'version' : __version__, + 'date' : datestamp, + } + print >> s, '''\ +From: %(author)s To: %(people)s''' % vars - if replyto: - print 'Reply-To: %s' % replyto - print '''\ + if replyto: + print >> s, 'Reply-To: %s' % replyto + print >>s, '''\ Subject: %(subject)s Date: %(date)s X-Mailer: Python syncmail %(version)s <http://sf.net/projects/cvs-syncmail> ''' % vars - s.write(sys.stdin.read()) - # append the diffs if available - print - for entry in entries: - print calculate_diff(entry, contextlines) - finally: - sys.stdout = sys.__stdout__ + s.write(sys.stdin.read()) + # append the diffs if available + print >> s + for entry in entries: + print >> s, calculate_diff(entry, contextlines) resp = conn.sendmail(address, people, s.getvalue()) conn.close() os._exit(0) |