diff mbox

Add script to contrib to format email body and patch for submission

Message ID 20130330145555.EE0D0421050@build1-lucid-cs
State New
Headers show

Commit Message

Tom de Vries March 30, 2013, 2:55 p.m. UTC
Ian,

this patch adds a script to contrib that formats an email body and a patch for
submission to gcc-patches.

This email was generated using the script, in the following way:
...
#!/bin/bash

cat compose-body-patch.header \
    <(./contrib/compose-body-patch.py \
	<(cat compose-body-patch.body
	  echo
	  cat compose-body-patch.log) \
        compose-body-patch.patch) \
    > message.txt
...

OK for trunk?

Thanks,
- Tom

2013-03-30  Tom de Vries  <tom@codesourcery.com>

	* compose-body-patch.py: New script.
diff mbox

Patch

Index: contrib/compose-body-patch.py
===================================================================
--- /dev/null (new file)
+++ contrib/compose-body-patch.py (revision 0)
@@ -0,0 +1,68 @@ 
+#!/usr/bin/python
+#
+# Copyright (C) 2013 Free Software Foundation, Inc.
+#
+# This script is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+
+# This script combines an email body and one or more patches into a MIME
+# multipart email, adhering to the style required by
+# http://gcc.gnu.org/contribute.html#patches
+#
+# The email can be sent by adding some more header fields and running sendmail.
+# F.i.:
+#   rm -f header.txt
+#   for f in From To Subject; do
+#       read -p "$f: " " line
+#       echo "$f: $line" >> header.txt
+#   done
+#   compose-body-patch.py improvement.txt improvement.patch > email.txt
+#   cat header.txt email.txt | unix2dos | sendmail -t -oi
+# 
+# The unix2dos for email.txt may be necessary because there's a bug in some
+# versions of python that causes the result of msg.as_string() below not to have
+# the CRLF EOL format required by MIME
+# ( discussed at http://stackoverflow.com/questions/3086860
+#   how-do-i-generate-a-multipart-mime-message-with-correct-crlf-in-python ).
+# But since all parts are text-based, we can work around that bug using
+# unix2dos.
+# Note that if email.txt has the right CRLF EOL format, the unix2dos for
+# header.txt is still necessary because sending emails with mixed EOL style may
+# not work.
+#
+# FWIW, if both header.txt and email.txt are in unix EOL format, this may also
+# work:
+#   cat header.txt email.txt | sendmail -t -oi
+# but YMMV.
+
+from email.mime.text import MIMEText
+from email.mime.multipart import MIMEMultipart
+import sys
+import os
+
+if len(sys.argv) < 3:
+    print "Usage: %s <body> <patch>+" % os.path.basename(sys.argv[0])
+    sys.exit (1)
+
+msg = MIMEMultipart('multipart')
+
+for x in range(1, len(sys.argv)):
+
+    filename = sys.argv[x]
+
+    fp = open(filename, 'r')
+    txt = fp.read()
+    fp.close()
+
+    if x == 1:
+        part = MIMEText(txt, 'plain')
+    else:
+        part = MIMEText(txt, 'x-patch')
+        part.set_param("name", filename)
+        part.add_header('Content-Disposition', 'inline; filename="%s"' % filename)
+
+    msg.attach(part)
+
+print msg.as_string()

Property changes on: contrib/compose-body-patch.py
___________________________________________________________________
Added: svn:executable
   + *