convert isolated <CR> or <LF> -> <CR><LF>
authorAndrew Engelbrecht <sudoman@ninthfloor.org>
Mon, 30 Nov 2015 21:45:37 +0000 (16:45 -0500)
committerAndrew Engelbrecht <sudoman@ninthfloor.org>
Mon, 7 Dec 2015 18:32:42 +0000 (13:32 -0500)
this is for the sake of proper signature verification.

sometimes mail servers strip <CR><LF>s from the ends of lines. however
these characters are required by RFC 3156 for proper signature
verification.

edward
tests/gpg-flatten-5.eml

diff --git a/edward b/edward
index 2480fcd513a7a26b744a04df4d90a9d53e80a56f..1622e42ec66e3813cb28bc507a088013da274a8c 100755 (executable)
--- a/edward
+++ b/edward
@@ -454,7 +454,9 @@ def get_subpart_data (part):
 
     payload_string          = part.as_string()
     if payload_string != None:
-        obj.payload_bytes   = payload_string.encode(charset)
+        # convert each isolated carriage return or line feed to carriage return + line feed
+        payload_string_crlf = re.sub(r'\n', '\r\n', re.sub(r'\r', '\n', re.sub(r'\r\n', '\n', payload_string)))
+        obj.payload_bytes   = payload_string_crlf.encode(charset)
 
     obj.filename            = part.get_filename()
     obj.content_type        = part.get_content_type()
index 3478335992d470b3a6e1e2c11efa86eaf2f43edd..8eddb45eece6c56c4186aeadd8258eb43e0bb094 100644 (file)
@@ -41,11 +41,11 @@ Content-Disposition: attachment; filename="signature.asc"
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
-iJwEAAECAAYFAlXBO+cACgkQsT5tL2pPbujZbgQAhF23ts0wohA6lxbVfcq/mdzl
-GrRO7pYC5BNDtRRjeGDCOisdfY5qK0skuwVSSMJAKok+Sgv/FKsofWT08XPBz4vV
-KAtJoAb6i6r8g38lHGM1Fl8POK3tAEC0srf45xBJY14yuJoGMC0rG+Hj+IxtFfay
-Fphd1bTfkcXjEZN8/nA=
-=HfPl
+iJwEAAECAAYFAlZcv6cACgkQsT5tL2pPbuiVHAP/fl0fViiYtc5UHAOzywlTRKP0
+DXCp4mgwkeqawaC4+N7CN1I4dezoWBoKcOBJRuF6rrkeet7vsj8FeJAvzBTui6PI
+XxGPU4wuaaQ0R9DlePqKPzScrDEBXvxvJdk9AUilkiU3/jaCsgpalAaLrwK4PCIL
+iXisvPWXi2u7tSPpJWU=
+=GWbS
 -----END PGP SIGNATURE-----
 
 --69pEqCNMs7DnfdpwkAdpUCaf0lwnKu6Vr--