[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sup-devel] Fix for decrypting messages



I was finding some messages weren't getting decrypted properly - I
would be told the message was decrypted, but no text would appear. But
I could decrypt it manually. Trying the dev console I found the entire
message was being parsed into headers. Eventually I worked out that
the decrypted message had "\r\n" as line breaks, while the RMail
parser expects "\n\n" as the divider between the header and body, not
"\r\n\r\n". So the patch is basically one line to take the decrypted
output and replace \r\n with \n. This is done after the signature is
verified.

The mail client producing the emails was the Evolution mail client,
but I guess it may happen with others aswell.

Hamish Downer
From 1c8cbcf77666c9cbe918876889a73e6db08a45ae Mon Sep 17 00:00:00 2001
From: Hamish Downer <dmishd@gmail.com>
Date: Sun, 17 Oct 2010 19:48:36 +0100
Subject: [PATCH] Deal with "\r\n" inside encrypted messages

RMail expects "\n\n" to be the dividing line between the header and
body, but sometimes the decrypted message has "\r\n" as line ending
so the RMail parsing does not work. This commit fixes that.
---
 lib/sup/crypto.rb |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 386dbb8..3069483 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -170,6 +170,10 @@ EOS
       end
       msg.body = output
     else
+      # It appears that some clients use Windows new lines - CRLF - but RMail
+      # splits the body and header on "\n\n". So to allow the parse below to 
+      # succeed, we will convert the newlines to what RMail expects
+      output = output.gsub(/\r\n/, "\n")
       # This is gross. This decrypted payload could very well be a multipart
       # element itself, as opposed to a simple payload. For example, a
       # multipart/signed element, like those generated by Mutt when encrypting
-- 
1.7.1

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel