[python-postman] add patch for --sanitize flag.

Brett Lentz wakko666 at fedoraproject.org
Fri Nov 4 15:17:28 UTC 2011


commit cbb58d161f5ca1959cb001873939a6a5f9b23116
Author: Brett Lentz <blentz at redhat.com>
Date:   Fri Nov 4 11:11:01 2011 -0400

    add patch for --sanitize flag.

 postman_sanitize.patch |   67 ++++++++++++++++++++++++++++++++++++++++++++++++
 python-postman.spec    |    6 ++++
 2 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/postman_sanitize.patch b/postman_sanitize.patch
new file mode 100644
index 0000000..8d97123
--- /dev/null
+++ b/postman_sanitize.patch
@@ -0,0 +1,67 @@
+--- postman/__main__.py.orig 2011-11-04 09:56:12.343816745 -0400
++++ postman/__main__.py 2011-11-04 11:06:14.828066021 -0400
+@@ -1,21 +1,54 @@
+ import argparse
++import re
+ import sys
+ 
+ import boto
+ 
+ from postman import __version__
+ 
++legal_headers = [ 'Accept-Language', 'Bcc', 'Cc', 'Comments', 'Content-Type', 
++    'Content-Transfer-Encoding', 'Content-ID', 'Content-Description', 
++    'Content-Disposition', 'Content-Language', 'Date', 'DKIM-Signature',
++    'DomainKey-Signature From', 'In-Reply-To', 'Keywords', 'List-Archive',
++    'List-Help', 'List-Id', 'List-Owner', 'List-Post', 'List-Subscribe', 
++    'List-Unsubscribe', 'Message-Id', 'MIME-Version', 'Received', 'References',
++    'Reply-To', 'Return-Path', 'Sender', 'Subject', 'Thread-Index', 
++    'Thread-Topic', 'To', 'User-Agent' ]
+ 
+ def out(msg, args):
+     if args.verbose:
+         sys.stdout.write("%s\n" % msg)
+         sys.stdout.flush()
+ 
++def sanitize(args, msg):
++    ''' Transform any headers SES disallows in to X-Headers.
+ 
++    Sanitize method adapted from this Perl snippet:
++    http://www.evanhoffman.com/evan/2011/05/16/amazon-ses-illegal-header-errors/
++    '''
++    cleanmsg = ""
++    in_header = True
++
++    # Avoids indented lines.
++    hdr_re = re.compile("^([\w\d\-]+):")
++
++    for line in msg.splitlines(True):
++        # Two line breaks between header and message body.
++        if re.match("^[\n\r]", line):
++            # Do nothing once we've scanned the headers.
++            in_header = False
++        if in_header and hdr_re.match(line):
++            if hdr_re.match(line).group(1) not in legal_headers:
++                line = "X-%s" % line
++        cleanmsg += line
++    return cleanmsg
++                        
+ def cmd_send(args):
+     ses = boto.connect_ses()
+     out("Sending mail to: %s" % ", ".join(args.destinations), args)
+     msg = sys.stdin.read()
++    if args.sanitize:
++        msg = sanitize(args, msg)
+     r = ses.send_raw_email(msg, args.f, args.destinations)
+     if r.get("SendRawEmailResponse", {}).get("SendRawEmailResult", {}).get("MessageId"):
+         out("OK", args)
+@@ -90,6 +123,8 @@
+     parser_send = command_parsers.add_parser("send")
+     parser_send.add_argument("-f",
+         help="the address to send the message from, must be validated")
++    parser_send.add_argument("--sanitize", action="store_true", 
++        help="Sanitize headers. Convert illegal headers to X-Headers.")
+     parser_send.add_argument("destinations", metavar="TO", type=str, nargs="+",
+         help="a list of email addresses to deliver message to")
+     
+
diff --git a/python-postman.spec b/python-postman.spec
index 119f529..047ee52 100644
--- a/python-postman.spec
+++ b/python-postman.spec
@@ -14,6 +14,7 @@ License:        MIT
 URL:            http://pypi.python.org/pypi/%{pkgname}
 Source0:        http://pypi.python.org/packages/source/p/%{pkgname}/%{pkgname}-%{version}.tar.gz
 Patch0:         postman_fixdeps.patch
+Patch1:         postman_sanitize.patch
 
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildArch:      noarch
@@ -46,6 +47,8 @@ http://aws.amazon.com/articles/2405502737055650
 %patch0
 %endif
 
+%patch1
+
 find -name '*.py' | xargs sed -i '1s|^#!python|#!%{__python}|'
 
 %build
@@ -73,6 +76,9 @@ rm -rf %{buildroot}
 %{_mandir}/man5/*
 
 %changelog
+* Wed Oct 26 2011 Brett Lentz <blentz at redhat.com> - 0.5.2-4
+- Add --sanitize flag to allow working around SES illegal headers issues.
+
 * Wed Oct 26 2011 Brett Lentz <blentz at redhat.com> - 0.5.2-3
 - fix some niggling rpmlint errors
 


More information about the scm-commits mailing list