Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
* [sup-talk] [RFC] Fix parsing of encrypted messages that contain further multipart elements
@ 2009-07-23 17:12 Adeodato Simó
  2009-07-23 17:19 ` [sup-talk] [PATCH] " Adeodato Simó
  0 siblings, 1 reply; 3+ messages in thread
From: Adeodato Simó @ 2009-07-23 17:12 UTC (permalink / raw)


---
Hello,

this is just a RFC, because I can't think of any elegant way to address
the issue, given the shortcomings of the RMail API. Please read the
lengthy comment in the patch, and let me know if anybody has any ideas
about this issue.

P.S.: I've created a "sup-dato" repository in Gitorious, in case that's
helpful. Should I be creating merge requests?

 lib/sup/crypto.rb |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 8ec277b..6ef0c0e 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -132,8 +132,25 @@ class CryptoManager
           end
         end
 
+      # This is gross. The decrypted payload could very well be a multipart
+      # element itself, as opposed to a simple payload; for example, a
+      # multipart/signed element, like Mutt does when encrypting and signing a
+      # message (instead of clearsigning it). Supposedly, decrypted_payload
+      # being a multipart element ought to work out nicely because in
+      # Message::multipart_encrypted_to_chunks() the decrypted message is run
+      # though message_to_chunks() again to get any children. However, it does
+      # not work as intended because this inner payload need not carry a
+      # MIME-Version header, yet they are fed to RMail as a top-level message,
+      # for which the MIME-Version header is required, which causes for the
+      # part not to be detected as multipart. If we detect this is happening,
+      # force the payload to be interpreted as MIME.
+      msg = RMail::Parser.read(decrypted_payload)
+      if msg.header.content_type =~ %r{^multipart/} and not msg.multipart?
+        decrypted_payload = "MIME-Version: 1.0\n" + decrypted_payload
+        msg = RMail::Parser.read(decrypted_payload)
+      end
       notice = Chunk::CryptoNotice.new :valid, "This message has been decrypted for display"
-      [RMail::Parser.read(decrypted_payload), sig, notice]
+      [msg, sig, notice]
     else
       notice = Chunk::CryptoNotice.new :invalid, "This message could not be decrypted", output.split("\n")
       [nil, nil, notice]
-- 
1.6.3.3



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [sup-talk] [PATCH] Fix parsing of encrypted messages that contain further multipart elements
  2009-07-23 17:12 [sup-talk] [RFC] Fix parsing of encrypted messages that contain further multipart elements Adeodato Simó
@ 2009-07-23 17:19 ` Adeodato Simó
  2009-09-12 17:08   ` William Morgan
  0 siblings, 1 reply; 3+ messages in thread
From: Adeodato Simó @ 2009-07-23 17:19 UTC (permalink / raw)


---
Amended patch follows, with a better wording that I had seemingly not
committed. Sorry for the noise.

 lib/sup/crypto.rb |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 8ec277b..acbc1d8 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -132,8 +132,26 @@ class CryptoManager
           end
         end
 
+      # 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
+      # and signing a message (instead of just clearsigning the body).
+      # Supposedly, decrypted_payload being a multipart element ought to work
+      # out nicely because Message::multipart_encrypted_to_chunks() runs the
+      # decrypted message through message_to_chunks() again to get any
+      # children. However, it does not work as intended because these inner
+      # payloads need not carry a MIME-Version header, yet they are fed to
+      # RMail as a top-level message, for which the MIME-Version header is
+      # required. This causes for the part not to be detected as multipart,
+      # hence being shown as an attachment. If we detect this is happening,
+      # we force the decrypted payload to be interpreted as MIME.
+      msg = RMail::Parser.read(decrypted_payload)
+      if msg.header.content_type =~ %r{^multipart/} and not msg.multipart?
+        decrypted_payload = "MIME-Version: 1.0\n" + decrypted_payload
+        msg = RMail::Parser.read(decrypted_payload)
+      end
       notice = Chunk::CryptoNotice.new :valid, "This message has been decrypted for display"
-      [RMail::Parser.read(decrypted_payload), sig, notice]
+      [msg, sig, notice]
     else
       notice = Chunk::CryptoNotice.new :invalid, "This message could not be decrypted", output.split("\n")
       [nil, nil, notice]
-- 
1.6.3.3



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [sup-talk] [PATCH] Fix parsing of encrypted messages that contain further multipart elements
  2009-07-23 17:19 ` [sup-talk] [PATCH] " Adeodato Simó
@ 2009-09-12 17:08   ` William Morgan
  0 siblings, 0 replies; 3+ messages in thread
From: William Morgan @ 2009-09-12 17:08 UTC (permalink / raw)


Reformatted excerpts from Adeodato Sim?'s message of 2009-07-23:
> Amended patch follows, with a better wording that I had seemingly not
> committed. Sorry for the noise.

Not sure why I missed this. Branch crypto-mime-fix, merged into next.
Thanks!
-- 
William <wmorgan-sup at masanjin.net>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-09-12 17:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-23 17:12 [sup-talk] [RFC] Fix parsing of encrypted messages that contain further multipart elements Adeodato Simó
2009-07-23 17:19 ` [sup-talk] [PATCH] " Adeodato Simó
2009-09-12 17:08   ` William Morgan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox