CVSROOT syncmail,1.3,1.4

Toshio ãããã (toshio) fedora-extras-commits at redhat.com
Thu Jan 24 05:22:46 UTC 2008


Author: toshio

Update of /cvs/fedora/CVSROOT
In directory cvs-int.fedora.redhat.com:/var/tmp/CVSROOT

Modified Files:
	syncmail 
Log Message:
* Update syncmail to work with utf-8 senders.



Index: syncmail
===================================================================
RCS file: /cvs/fedora/CVSROOT/syncmail,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- syncmail	8 Dec 2005 21:34:52 -0000	1.3
+++ syncmail	24 Jan 2008 05:22:44 -0000	1.4
@@ -60,14 +60,14 @@
 Where options is:
 
     --cvsroot=<path>
-    	Use <path> as the environment variable CVSROOT.  Otherwise this
-    	variable must exist in the environment.
+            Use <path> as the environment variable CVSROOT.  Otherwise this
+            variable must exist in the environment.
 
     --require-keyword=STRING
         Only send mail if STRING is found in the commit message.
 
     --nodiff
-    	Don't bother generating the full diff, just report if the files changed
+            Don't bother generating the full diff, just report if the files changed
         or not.
 
     --quiet
@@ -97,6 +97,11 @@
 import time
 import getopt
 import re
+import popen2
+import signal
+import email.MIMEMultipart, email.Message, email.Utils, email.Header
+import smtplib
+
 
 # Diff trimming stuff
 DIFF_HEAD_LINES = 200
@@ -156,10 +161,10 @@
         del lines[DIFF_HEAD_LINES:-DIFF_TAIL_LINES]
         lines.insert(DIFF_HEAD_LINES,
                      '[...%d lines suppressed...]\n' % removedlines)
-	# we do want people to be able to view the whole change easily,
-	# even if it is long
-	if diffcmd:
-	    lines.insert(0, 'View full diff with command:\n%s\n' % diffcmd)
+        # we do want people to be able to view the whole change easily,
+        # even if it is long
+        if diffcmd:
+            lines.insert(0, 'View full diff with command:\n%s\n' % diffcmd)
     return string.join(lines, '')
 
 def create_diffstat(filespec, cvs_dir):
@@ -173,27 +178,23 @@
         return lines
     if string.find(file, ".patch", -6) != -1 or \
        string.find(file, ".diff", -5) != -1:
-	# run diffstat on the patch
-	if oldrev == 'NONE':
-	    # not in CVS yet
-	    diffcmd = '/usr/bin/diffstat %s 2>/dev/null' % file
-	else:
-	    diffcmd = '/usr/bin/cvs -f co -p -r %s %s/%s 2>/dev/null | /usr/bin/diffstat 2>/dev/null' % (
-	             newrev, cvs_dir, file)
+        # run diffstat on the patch
+        if oldrev == 'NONE':
+            # not in CVS yet
+            diffcmd = '/usr/bin/diffstat %s 2>/dev/null' % file
+        else:
+            diffcmd = '/usr/bin/cvs -f co -p -r %s %s/%s 2>/dev/null | /usr/bin/diffstat 2>/dev/null' % (
+                     newrev, cvs_dir, file)
         fp = os.popen(diffcmd)
         lines = fp.readlines()
         fp.close()
-	lines.insert(0, '%s:\n' % file)
+        lines.insert(0, '%s:\n' % file)
     return string.join(lines, '')
 
-# send mail using sendmail
+# send mail using smtp, with utf8 encoded sender names
 def blast_mail(subject, people):
     global optDiffStat
 
-    # the redirection sequence in this command is actually intentional
-    # (and not a mistake instead of ">/dev/null 2>&1")
-    sendmail = "/usr/sbin/sendmail -oi %s 2>&1 >/dev/null" % people
-
     cvs_dir = string.split(subject)[0]
     cvs_module = string.split(cvs_dir, "/")[0]
     
@@ -211,38 +212,49 @@
     # lock for too long.  Urg!
     if not os.fork(): # in the child
         # Need to wait on CVS to release the lock so we can do the diff
-        time.sleep(2)
-        fp = os.popen(sendmail, 'w')
-        fp.write("Content-Type: TEXT/PLAIN; charset=US-ASCII\n")
-        fp.write("Subject: %s\n" % (subject,))
-        fp.write("To: %s\n" % (people,))
+        msg = email.Message.Message()
+
+        msg.add_header('Subject', subject)
         if os.environ.has_key("CVSROOT"):
-            fp.write("X-CVSROOT: %s\n" % (os.environ["CVSROOT"],))
+            msg.add_header("X-CVSROOT", os.environ["CVSROOT"])
         username = pwd.getpwuid(os.getuid())[0]
         hostname = os.uname()[1]
-        fp.write("X-CVS-Module: %s\n" % (cvs_module,))
-        fp.write("X-CVS-Directory: %s\n" % (cvs_dir,))
-        fp.write("X-CVS-User: %s\n" % (username,))
-        fp.write("X-CVS-Server: %s\n" % (hostname,))
-        fp.write("Precedence: first-class\n")
-        fp.write("\n")
-        fp.write("Author: %s\n\n" % (username,))
+        # Get commiter's real-name, and utf8 encode it
+        sender_name = pwd.getpwuid(os.getuid())[4]
+        header_charset = 'utf-8'
+        sender_name = str(email.Header.Header(unicode(sender_name,'utf-8'), header_charset))
+        sender_email = username + "@fedoraproject.org"
+        sender = email.Utils.formataddr((sender_name, sender_email))
+        msg.add_header('From', sender)
+        msg.add_header('To', ", ".join(people.split()) )
+
+        msg.add_header("X-CVS-Module", cvs_module)
+        msg.add_header("X-CVS-Directory", cvs_dir)
+        msg.add_header("X-CVS-User", username)
+        msg.add_header("X-CVS-Server", hostname)
+        msg.add_header("Precedence", "first-class")
+
+        payload ="Author: %s\n\n" % (username,)
         # now insert the CVS blurb
-        fp.write(commit_message)
-        fp.write('\n')
+        payload += commit_message
+        payload += '\n'
         # append the diffs if available and sensible
-	graphics = re.compile(r".*\.(jp(e)?g|gif|png|tif(f)?),", re.IGNORECASE)
+        graphics = re.compile(r".*\.(jp(e)?g|gif|png|tif(f)?),", re.IGNORECASE)
         for file in diff_files:
             if optQuiet:
-                fp.write("ChangeSet: %s\n" % (file,))
+                payload += ("ChangeSet: %s\n" % (file,))
                 continue
-	    if not graphics.match(file):
-		if optDiffStat:
-		    fp.write(create_diffstat(file, cvs_dir))
-		    fp.write('\n')
-		fp.write(calculate_diff(file))
-		fp.write('\n')
-        fp.close()
+            if not graphics.match(file):
+                if optDiffStat:
+                    payload += (create_diffstat(file, cvs_dir))
+                    payload += '\n'
+                payload += calculate_diff(file)
+                payload += '\n'
+        msg.set_payload(payload)
+        smtp = smtplib.SMTP("localhost")
+        #smtp.set_debuglevel(1)
+        smtp.sendmail(sender, people.split(), msg.as_string())
+        smtp.quit()
         # doesn't matter what code we return, it isn't waited on
         os._exit(0)
 
@@ -255,11 +267,13 @@
     global DIFF_TAIL_LINES
     global DIFF_TRUNCATE_IF_LARGER
     global optRequireKeyword
-    
+
+    signal.signal(signal.SIGINT, signal.SIG_IGN)
+
     try:
         opts, args = getopt.getopt(sys.argv[1:], 'h', [
-	    'cvsroot=', 'quiet', 'nodiff', 'nodiffstat', 'help',
-	    'headlines=', 'taillines=', 'truncate=', 'require-keyword='])
+            'cvsroot=', 'quiet', 'nodiff', 'nodiffstat', 'help',
+            'headlines=', 'taillines=', 'truncate=', 'require-keyword='])
     except getopt.error, msg:
         usage(1, msg)
 
@@ -279,12 +293,12 @@
             optDiffStat = 0
         elif opt == '--nodiffstat':
             optDiffStat = 0
-	elif opt == '--headlines':
-	    DIFF_HEAD_LINES = arg
-	elif opt == '--taillines':
-	    DIFF_TAIL_LINES = arg
-	elif opt == '--truncate':
-	    DIFF_TRUNCATE_IF_LARGER = arg
+        elif opt == '--headlines':
+            DIFF_HEAD_LINES = arg
+        elif opt == '--taillines':
+            DIFF_TAIL_LINES = arg
+        elif opt == '--truncate':
+            DIFF_TRUNCATE_IF_LARGER = arg
         elif opt == '--require-keyword':
             optRequireKeyword.append(arg)
 
@@ -308,7 +322,6 @@
     blast_mail(subject, people)
 
 
-
 if __name__ == '__main__':
     print 'Running syncmail...'
     main()




More information about the fedora-extras-commits mailing list