Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] [PATCH] Implement inline GPG
@ 2010-02-18 11:40 Michael Stapelberg
  2010-02-26 21:24 ` Rich Lane
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Stapelberg @ 2010-02-18 11:40 UTC (permalink / raw)
  To: sup-devel

[-- Attachment #1: Type: text/plain, Size: 319 bytes --]

Hi,

as my previous patch was not merged, I have updated the patch to apply against
the current code. Furthermore, it now correctly handles character sets for the
GPG encrypted part.

The patch has been tested by me and another user and seems to work fine.

Please merge it for the next release.

Best regards,
Michael

[-- Attachment #2: 0001-Implement-inline-GPG.patch --]
[-- Type: application/octet-stream, Size: 7629 bytes --]

From 87e8a9b90c9566710a03b6673b5e77459350683c Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Wed, 17 Feb 2010 16:36:18 +0100
Subject: [PATCH] Implement inline GPG
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The SIG_PATTERN had to be changed because GPG, when clearsigning (which
is what happens when you send inline GPG messages), kind of escapes
lines beginning with dashes (so that the -----BEGIN PGP MESSAGE-----
lines don’t get messed up). Therefore, signatures, starting with "-- "
will be escaped as "- -- ". The manpage of GPG states that the process
of clearsigning is not reversible. Thus, there is no method in GPG to
get the original message.
---
 lib/sup/crypto.rb  |   62 ++++++++++++++++++++++++++++++++-------------------
 lib/sup/message.rb |   31 +++++++++++++++++++++++++-
 2 files changed, 69 insertions(+), 24 deletions(-)

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 91652c7..4f75936 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -86,18 +86,24 @@ class CryptoManager
     encrypt from, to, payload, true
   end
 
-  def verify payload, signature # both RubyMail::Message objects
+  def verify payload, signature, detached=true # both RubyMail::Message objects
     return unknown_status(cant_find_binary) unless @cmd
 
-    payload_fn = Tempfile.new "redwood.payload"
-    payload_fn.write format_payload(payload)
-    payload_fn.close
+    if detached
+      payload_fn = Tempfile.new "redwood.payload"
+      payload_fn.write format_payload(payload)
+      payload_fn.close
+    end
 
     signature_fn = Tempfile.new "redwood.signature"
     signature_fn.write signature.decode
     signature_fn.close
 
-    output = run_gpg "--verify #{signature_fn.path} #{payload_fn.path}"
+    if detached
+      output = run_gpg "--verify #{signature_fn.path} #{payload_fn.path}"
+    else
+      output = run_gpg "--verify #{signature_fn.path}"
+    end
     output_lines = output.split(/\n/)
 
     if output =~ /^gpg: (.* signature from .*$)/
@@ -112,7 +118,7 @@ class CryptoManager
   end
 
   ## returns decrypted_message, status, desc, lines
-  def decrypt payload # a RubyMail::Message object
+  def decrypt payload, armor=false # a RubyMail::Message object
     return unknown_status(cant_find_binary) unless @cmd
 
     payload_fn = Tempfile.new "redwood.payload"
@@ -142,24 +148,34 @@ class CryptoManager
       Chunk::CryptoNotice.new :invalid, $1, message.split("\n")
     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 output
-    if msg.header.content_type =~ %r{^multipart/} && !msg.multipart?
-      output = "MIME-Version: 1.0\n" + output
-      output.force_encoding Encoding::ASCII_8BIT if output.respond_to? :force_encoding
+    if armor
+      msg = RMail::Message.new
+      # Look for Charset, they are put before the base64 crypted part
+      charsets = payload.body.split("\n").grep(/^Charset:/)
+      if !charsets.empty? and charsets[0] =~ /^Charset: (.+)$/
+        output = Iconv.easy_decode($encoding, $1, output)
+      end
+      msg.body = output
+    else
+      # 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 output
+      if msg.header.content_type =~ %r{^multipart/} && !msg.multipart?
+        output = "MIME-Version: 1.0\n" + output
+        output.force_encoding Encoding::ASCII_8BIT if output.respond_to? :force_encoding
+        msg = RMail::Parser.read output
+      end
     end
     notice = Chunk::CryptoNotice.new :valid, "This message has been decrypted for display"
     [notice, sig, msg]
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index a85cc0d..69ada67 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -26,7 +26,7 @@ class Message
 
   QUOTE_PATTERN = /^\s{0,4}[>|\}]/
   BLOCK_QUOTE_PATTERN = /^-----\s*Original Message\s*----+$/
-  SIG_PATTERN = /(^-- ?$)|(^\s*----------+\s*$)|(^\s*_________+\s*$)|(^\s*--~--~-)|(^\s*--\+\+\*\*==)/
+  SIG_PATTERN = /(^(- )*-- ?$)|(^\s*----------+\s*$)|(^\s*_________+\s*$)|(^\s*--~--~-)|(^\s*--\+\+\*\*==)/
 
   MAX_SIG_DISTANCE = 15 # lines from the end
   DEFAULT_SUBJECT = ""
@@ -512,6 +512,35 @@ private
         ## this ensures that the body is normalized to avoid non-displayable
         ## characters
         body = Iconv.easy_decode($encoding, m.charset || $encoding, m.decode) if m.body
+        lines = body.split("\n")
+
+        ## Check for inline-PGP
+        if body =~ /-----BEGIN PGP SIGNED MESSAGE-----/
+          sign_start = lines.index("-----BEGIN PGP SIGNED MESSAGE-----")
+          sign_end = lines.index("-----END PGP SIGNED MESSAGE-----") || lines.count
+          msg = RMail::Message.new
+          msg.body = lines[sign_start, sign_end+1].join("\n")
+
+          sign_end = lines.index("-----BEGIN PGP SIGNATURE-----") || sign_end
+          payload = RMail::Message.new
+          payload.body = lines[sign_start+1, sign_end-1].join("\n")
+          return [CryptoManager.verify(nil, msg, false), message_to_chunks(payload)].flatten.compact
+        end
+
+        if body =~ /-----BEGIN PGP MESSAGE-----/
+          signstart = lines.index("-----BEGIN PGP MESSAGE-----")
+          signend = lines.index("-----END PGP MESSAGE-----") || lines.count
+          msg = RMail::Message.new
+          msg.body = lines[signstart, signend+1].join("\n")
+          notice, sig, decryptedm = CryptoManager.decrypt msg, true
+          if decryptedm # managed to decrypt
+            children = message_to_chunks(decryptedm, true)
+            return [notice, sig].compact + children
+          else
+            return [notice]
+          end
+        end
+
         text_to_chunks((body || "").normalize_whitespace.split("\n"), encrypted)
       end
     end
-- 
1.6.5


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

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

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

* Re: [sup-devel] [PATCH] Implement inline GPG
  2010-02-18 11:40 [sup-devel] [PATCH] Implement inline GPG Michael Stapelberg
@ 2010-02-26 21:24 ` Rich Lane
  2010-02-27 13:11   ` Michael Stapelberg
  0 siblings, 1 reply; 13+ messages in thread
From: Rich Lane @ 2010-02-26 21:24 UTC (permalink / raw)
  To: Michael Stapelberg; +Cc: sup-devel

Excerpts from Michael Stapelberg's message of 2010-02-18 06:40:45 -0500:
> Hi,
> 
> as my previous patch was not merged, I have updated the patch to apply against
> the current code. Furthermore, it now correctly handles character sets for the
> GPG encrypted part.
> 
> The patch has been tested by me and another user and seems to work fine.
> 
> Please merge it for the next release.
> 
> Best regards,
> Michael

Not a full review yet, just a bug that bit me:

message.rb:531 assumes the text will be on its own line, while the
regex on 530 does not. (check my edge branch for line numbers)
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


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

* Re: [sup-devel] [PATCH] Implement inline GPG
  2010-02-26 21:24 ` Rich Lane
@ 2010-02-27 13:11   ` Michael Stapelberg
  2010-02-27 18:05     ` Rich Lane
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Stapelberg @ 2010-02-27 13:11 UTC (permalink / raw)
  To: Rich Lane; +Cc: sup-devel

Hi Rich,

Excerpts from Rich Lane's message of Fr Feb 26 22:24:08 +0100 2010:
> message.rb:531 assumes the text will be on its own line, while the
> regex on 530 does not. (check my edge branch for line numbers)
Right. RFC 2440 is not really clear about that. In 6.2 it only says:

"An Armor Header Line consists of the appropriate header line text
 surrounded by five (5) dashes ('-', 0x2D) on either side of the
 header line text."

But I guess that no client would put any data before/after these lines,
so adding ^ and $ to the regex in 530 seems right.

Let me know if you need any help validating this patch.

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


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

* Re: [sup-devel] [PATCH] Implement inline GPG
  2010-02-27 13:11   ` Michael Stapelberg
@ 2010-02-27 18:05     ` Rich Lane
  2010-03-01 13:45       ` Michael Stapelberg
  0 siblings, 1 reply; 13+ messages in thread
From: Rich Lane @ 2010-02-27 18:05 UTC (permalink / raw)
  To: Michael Stapelberg; +Cc: sup-devel

Excerpts from Michael Stapelberg's message of 2010-02-27 08:11:28 -0500:
> But I guess that no client would put any data before/after these lines,
> so adding ^ and $ to the regex in 530 seems right.

The problem is sign_start will be nil if the text isn't on a line by
itself, causing a crash a few lines later. This happened to me when I
was running with this patch on my edge branch. I'd remove the
duplication by making the condition of the if the sign_start assignment.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


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

* Re: [sup-devel] [PATCH] Implement inline GPG
  2010-02-27 18:05     ` Rich Lane
@ 2010-03-01 13:45       ` Michael Stapelberg
  2010-03-01 14:36         ` Christian Dietrich
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Stapelberg @ 2010-03-01 13:45 UTC (permalink / raw)
  To: Rich Lane; +Cc: sup-devel

Hi Rich,

Excerpts from Rich Lane's message of Sa Feb 27 19:05:58 +0100 2010:
> The problem is sign_start will be nil if the text isn't on a line by
> itself, causing a crash a few lines later. This happened to me when I
How about using the following solution?

gpg_start = "-----BEGIN PGP SIGNED MESSAGE-----"
gpg_end = "-----END PGP SIGNED MESSAGE-----"
gpg = lines.select { |l| true if l =~ /#{gpg_start}/ .. l =~ /#{gpg_end}/ }
msg.body = gpg.join("\n")

Is there a way to avoid the ugly "true if"? When just leaving it out, ruby
complained saying "ArgumentError: bad value for range".

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


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

* Re: [sup-devel] [PATCH] Implement inline GPG
  2010-03-01 13:45       ` Michael Stapelberg
@ 2010-03-01 14:36         ` Christian Dietrich
  2010-03-01 16:49           ` Michael Stapelberg
  0 siblings, 1 reply; 13+ messages in thread
From: Christian Dietrich @ 2010-03-01 14:36 UTC (permalink / raw)
  To: sup-devel


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1: Type: text/plain; charset=UTF-8, Size: 1903 bytes --]

Excerpts from Michael Stapelberg's message of Mo Mär 01 14:45:54 +0100 2010:
> Hi Rich,
> 
> Excerpts from Rich Lane's message of Sa Feb 27 19:05:58 +0100 2010:
> > The problem is sign_start will be nil if the text isn't on a line by
> > itself, causing a crash a few lines later. This happened to me when I
> How about using the following solution?
> 
> gpg_start = "-----BEGIN PGP SIGNED MESSAGE-----"
> gpg_end = "-----END PGP SIGNED MESSAGE-----"
> gpg = lines.select { |l| true if l =~ /#{gpg_start}/ .. l =~ /#{gpg_end}/ }
> msg.body = gpg.join("\n")
> 
> Is there a way to avoid the ugly "true if"? When just leaving it out, ruby
> complained saying "ArgumentError: bad value for range".

Hi, there,
tried this, but broke on this specific message, cause the string was
included but there was no signature.

This works for me:

517         ## Check for inline-PGP
518         if body =~ /^-----BEGIN PGP SIGNED MESSAGE-----/
519             gpg_start = "^-----BEGIN PGP SIGNED MESSAGE-----"
520             gpg_signature = "^-----BEGIN PGP SIGNATURE-----"
521             gpg_end = "^-----END PGP SIGNED MESSAGE-----"
522             gpg = lines.select { |l| true if l =~ /#{gpg_start}/ .. l =~ /#{gpg_end}/ }
523             body = lines.select { |l| true if l =~ /#{gpg_start}/ .. l =~ /#{gpg_signature}/ }
524             msg = RMail::Message.new
525             msg.body = gpg.join("\n")
526 
527             payload = RMail::Message.new
528             payload.body = body[1..-2].join("\n")
529 
530             File.open("/tmp/msg", "w+") {|f| f.write(msg.body)}
531             File.open("/tmp/payload", "w+") {|f| f.write(payload.body)}
532             return [CryptoManager.verify(nil, msg, false), message_to_chunks(payload)].flatten.compact
533         end

greetz didi
-- 
No documentation is better than bad documentation
-- Das Ausdrucken dieser Mail wird urheberrechtlich verfolgt.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 143 bytes --]

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

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

* Re: [sup-devel] [PATCH] Implement inline GPG
  2010-03-01 14:36         ` Christian Dietrich
@ 2010-03-01 16:49           ` Michael Stapelberg
  2010-03-01 17:46             ` Christian Dietrich
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Stapelberg @ 2010-03-01 16:49 UTC (permalink / raw)
  To: sup-devel

Hi didi,

Excerpts from Christian Dietrich's message of Mo Mär 01 15:36:10 +0100 2010:
> tried this, but broke on this specific message, cause the string was
> included but there was no signature.
Can you forward this message so that I can have a look, please?

> 517         ## Check for inline-PGP
> 518         if body =~ /^-----BEGIN PGP SIGNED MESSAGE-----/
> 519             gpg_start = "^-----BEGIN PGP SIGNED MESSAGE-----"
> 520             gpg_signature = "^-----BEGIN PGP SIGNATURE-----"
> 521             gpg_end = "^-----END PGP SIGNED MESSAGE-----"
Why do you use ^ in the beginning but not $ in the end?

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

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

* Re: [sup-devel] [PATCH] Implement inline GPG
  2010-03-01 16:49           ` Michael Stapelberg
@ 2010-03-01 17:46             ` Christian Dietrich
  2010-03-09 16:43               ` [sup-devel] [PATCH] Implement inline GPG (updated) Michael Stapelberg
  0 siblings, 1 reply; 13+ messages in thread
From: Christian Dietrich @ 2010-03-01 17:46 UTC (permalink / raw)
  To: sup-devel


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1: Type: text/plain; charset=UTF-8, Size: 987 bytes --]

Excerpts from Michael Stapelberg's message of Mo Mär 01 17:49:30 +0100 2010:
> Hi didi,
> 
> Excerpts from Christian Dietrich's message of Mo Mär 01 15:36:10 +0100 2010:
> > tried this, but broke on this specific message, cause the string was
> > included but there was no signature.
> Can you forward this message so that I can have a look, please?

It was your message with the patch.

<1267450467-sup-4411@midna.zekjur.net>

> 
> > 517         ## Check for inline-PGP
> > 518         if body =~ /^-----BEGIN PGP SIGNED MESSAGE-----/
> > 519             gpg_start = "^-----BEGIN PGP SIGNED MESSAGE-----"
> > 520             gpg_signature = "^-----BEGIN PGP SIGNATURE-----"
> > 521             gpg_end = "^-----END PGP SIGNED MESSAGE-----"
> Why do you use ^ in the beginning but not $ in the end?

You never know what kind of crude mailers are out there.

greetz didi
-- 
No documentation is better than bad documentation
-- Das Ausdrucken dieser Mail wird urheberrechtlich verfolgt.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 143 bytes --]

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

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

* Re: [sup-devel] [PATCH] Implement inline GPG (updated)
  2010-03-01 17:46             ` Christian Dietrich
@ 2010-03-09 16:43               ` Michael Stapelberg
  2010-03-10 21:23                 ` Michael Stapelberg
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Stapelberg @ 2010-03-09 16:43 UTC (permalink / raw)
  To: sup-devel

[-- Attachment #1: Type: text/plain, Size: 275 bytes --]

Hi everybody,

Excerpts from Christian Dietrich's message of Mo Mär 01 18:46:52 +0100 2010:
> It was your message with the patch.
Alright, tested it and reworked my patch. The latest version is attached.

Hope it is good enough to get merged now ;-).

Best regards,
Michael

[-- Attachment #2: 0001-Implement-inline-GPG.patch --]
[-- Type: application/octet-stream, Size: 7614 bytes --]

From b77ace80b888896f281b3c39e8a9f4f315813a35 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Tue, 9 Mar 2010 17:40:48 +0100
Subject: [PATCH] Implement inline GPG
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The SIG_PATTERN had to be changed because GPG, when clearsigning (which
is what happens when you send inline GPG messages), kind of escapes
lines beginning with dashes (so that the -----BEGIN PGP MESSAGE-----
lines don’t get messed up). Therefore, signatures, starting with "-- "
will be escaped as "- -- ". The manpage of GPG states that the process
of clearsigning is not reversible. Thus, there is no method in GPG to
get the original message.
---
 lib/sup/crypto.rb  |   62 ++++++++++++++++++++++++++++++++-------------------
 lib/sup/message.rb |   34 +++++++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 24 deletions(-)

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 5ece6d9..abbcb98 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -97,18 +97,24 @@ EOS
     encrypt from, to, payload, true
   end
 
-  def verify payload, signature # both RubyMail::Message objects
+  def verify payload, signature, detached=true # both RubyMail::Message objects
     return unknown_status(cant_find_binary) unless @cmd
 
-    payload_fn = Tempfile.new "redwood.payload"
-    payload_fn.write format_payload(payload)
-    payload_fn.close
+    if detached
+      payload_fn = Tempfile.new "redwood.payload"
+      payload_fn.write format_payload(payload)
+      payload_fn.close
+    end
 
     signature_fn = Tempfile.new "redwood.signature"
     signature_fn.write signature.decode
     signature_fn.close
 
-    output = run_gpg "--verify #{signature_fn.path} #{payload_fn.path}"
+    if detached
+      output = run_gpg "--verify #{signature_fn.path} #{payload_fn.path}"
+    else
+      output = run_gpg "--verify #{signature_fn.path}"
+    end
     output_lines = output.split(/\n/)
 
     if output =~ /^gpg: (.* signature from .*$)/
@@ -123,7 +129,7 @@ EOS
   end
 
   ## returns decrypted_message, status, desc, lines
-  def decrypt payload # a RubyMail::Message object
+  def decrypt payload, armor=false # a RubyMail::Message object
     return unknown_status(cant_find_binary) unless @cmd
 
     payload_fn = Tempfile.new "redwood.payload"
@@ -153,24 +159,34 @@ EOS
       Chunk::CryptoNotice.new :invalid, $1, message.split("\n")
     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 output
-    if msg.header.content_type =~ %r{^multipart/} && !msg.multipart?
-      output = "MIME-Version: 1.0\n" + output
-      output.force_encoding Encoding::ASCII_8BIT if output.respond_to? :force_encoding
+    if armor
+      msg = RMail::Message.new
+      # Look for Charset, they are put before the base64 crypted part
+      charsets = payload.body.split("\n").grep(/^Charset:/)
+      if !charsets.empty? and charsets[0] =~ /^Charset: (.+)$/
+        output = Iconv.easy_decode($encoding, $1, output)
+      end
+      msg.body = output
+    else
+      # 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 output
+      if msg.header.content_type =~ %r{^multipart/} && !msg.multipart?
+        output = "MIME-Version: 1.0\n" + output
+        output.force_encoding Encoding::ASCII_8BIT if output.respond_to? :force_encoding
+        msg = RMail::Parser.read output
+      end
     end
     notice = Chunk::CryptoNotice.new :valid, "This message has been decrypted for display"
     [notice, sig, msg]
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index ebc73fc..ef87218 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -26,7 +26,7 @@ class Message
 
   QUOTE_PATTERN = /^\s{0,4}[>|\}]/
   BLOCK_QUOTE_PATTERN = /^-----\s*Original Message\s*----+$/
-  SIG_PATTERN = /(^-- ?$)|(^\s*----------+\s*$)|(^\s*_________+\s*$)|(^\s*--~--~-)|(^\s*--\+\+\*\*==)/
+  SIG_PATTERN = /(^(- )*-- ?$)|(^\s*----------+\s*$)|(^\s*_________+\s*$)|(^\s*--~--~-)|(^\s*--\+\+\*\*==)/
 
   MAX_SIG_DISTANCE = 15 # lines from the end
   DEFAULT_SUBJECT = ""
@@ -512,6 +512,38 @@ private
         ## this ensures that the body is normalized to avoid non-displayable
         ## characters
         body = Iconv.easy_decode($encoding, m.charset || $encoding, m.decode) if m.body
+        lines = body.split("\n")
+
+        ## Check for inline-PGP
+        msg_start = "^-----BEGIN PGP SIGNED MESSAGE-----$"
+        msg_end = "^-----END PGP SIGNED MESSAGE-----$"
+        gpg = lines.select { |l| true if l =~ /#{msg_start}/ .. l =~ /#{msg_end}/ }
+        if !gpg.empty?
+          msg = RMail::Message.new
+          msg.body = gpg.join("\n")
+
+          sig_start = "^-----BEGIN PGP SIGNATURE-----$"
+          sig = lines.select { |l| true if l =~ /#{msg_start}/ .. l =~ /#{sig_start}/ }
+          payload = RMail::Message.new
+          payload.body = sig[1, sig.count-2].join("\n")
+          return [CryptoManager.verify(nil, msg, false), message_to_chunks(payload)].flatten.compact
+        end
+
+        msg_start = "^-----BEGIN PGP MESSAGE-----$"
+        msg_end = "^-----END PGP MESSAGE-----$"
+        gpg = lines.select { |l| true if l =~ /#{msg_start}/ .. l =~ /#{msg_end}/ }
+        if !gpg.empty?
+          msg = RMail::Message.new
+          msg.body = gpg.join("\n")
+          notice, sig, decryptedm = CryptoManager.decrypt msg, true
+          if decryptedm # managed to decrypt
+            children = message_to_chunks(decryptedm, true)
+            return [notice, sig].compact + children
+          else
+            return [notice]
+          end
+        end
+
         text_to_chunks((body || "").normalize_whitespace.split("\n"), encrypted)
       end
     end
-- 
1.6.5


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

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

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

* Re: [sup-devel] [PATCH] Implement inline GPG (updated)
  2010-03-09 16:43               ` [sup-devel] [PATCH] Implement inline GPG (updated) Michael Stapelberg
@ 2010-03-10 21:23                 ` Michael Stapelberg
  2010-03-12  4:43                   ` Rich Lane
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Stapelberg @ 2010-03-10 21:23 UTC (permalink / raw)
  To: sup-devel

[-- Attachment #1: Type: text/plain, Size: 286 bytes --]

Hi,

Excerpts from Michael Stapelberg's message of Di Mär 09 17:43:03 +0100 2010:
> Alright, tested it and reworked my patch. The latest version is attached.
Updated it once again after testing with a user on sup-talk. See attachment
and please merge it now :).

Best regards,
Michael

[-- Attachment #2: 0001-Implement-inline-GPG.patch --]
[-- Type: application/octet-stream, Size: 7925 bytes --]

From 9c3de457828827b0ba9a3d98ca1870325eb6d21d Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Tue, 9 Mar 2010 17:40:48 +0100
Subject: [PATCH] Implement inline GPG
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The SIG_PATTERN had to be changed because GPG, when clearsigning (which
is what happens when you send inline GPG messages), kind of escapes
lines beginning with dashes (so that the -----BEGIN PGP MESSAGE-----
lines don’t get messed up). Therefore, signatures, starting with "-- "
will be escaped as "- -- ". The manpage of GPG states that the process
of clearsigning is not reversible. Thus, there is no method in GPG to
get the original message.
---
 lib/sup/crypto.rb  |   62 ++++++++++++++++++++++++++++++++-------------------
 lib/sup/message.rb |   42 ++++++++++++++++++++++++++++++++--
 2 files changed, 78 insertions(+), 26 deletions(-)

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 5ece6d9..abbcb98 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -97,18 +97,24 @@ EOS
     encrypt from, to, payload, true
   end
 
-  def verify payload, signature # both RubyMail::Message objects
+  def verify payload, signature, detached=true # both RubyMail::Message objects
     return unknown_status(cant_find_binary) unless @cmd
 
-    payload_fn = Tempfile.new "redwood.payload"
-    payload_fn.write format_payload(payload)
-    payload_fn.close
+    if detached
+      payload_fn = Tempfile.new "redwood.payload"
+      payload_fn.write format_payload(payload)
+      payload_fn.close
+    end
 
     signature_fn = Tempfile.new "redwood.signature"
     signature_fn.write signature.decode
     signature_fn.close
 
-    output = run_gpg "--verify #{signature_fn.path} #{payload_fn.path}"
+    if detached
+      output = run_gpg "--verify #{signature_fn.path} #{payload_fn.path}"
+    else
+      output = run_gpg "--verify #{signature_fn.path}"
+    end
     output_lines = output.split(/\n/)
 
     if output =~ /^gpg: (.* signature from .*$)/
@@ -123,7 +129,7 @@ EOS
   end
 
   ## returns decrypted_message, status, desc, lines
-  def decrypt payload # a RubyMail::Message object
+  def decrypt payload, armor=false # a RubyMail::Message object
     return unknown_status(cant_find_binary) unless @cmd
 
     payload_fn = Tempfile.new "redwood.payload"
@@ -153,24 +159,34 @@ EOS
       Chunk::CryptoNotice.new :invalid, $1, message.split("\n")
     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 output
-    if msg.header.content_type =~ %r{^multipart/} && !msg.multipart?
-      output = "MIME-Version: 1.0\n" + output
-      output.force_encoding Encoding::ASCII_8BIT if output.respond_to? :force_encoding
+    if armor
+      msg = RMail::Message.new
+      # Look for Charset, they are put before the base64 crypted part
+      charsets = payload.body.split("\n").grep(/^Charset:/)
+      if !charsets.empty? and charsets[0] =~ /^Charset: (.+)$/
+        output = Iconv.easy_decode($encoding, $1, output)
+      end
+      msg.body = output
+    else
+      # 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 output
+      if msg.header.content_type =~ %r{^multipart/} && !msg.multipart?
+        output = "MIME-Version: 1.0\n" + output
+        output.force_encoding Encoding::ASCII_8BIT if output.respond_to? :force_encoding
+        msg = RMail::Parser.read output
+      end
     end
     notice = Chunk::CryptoNotice.new :valid, "This message has been decrypted for display"
     [notice, sig, msg]
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index ebc73fc..7a19f27 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -26,7 +26,7 @@ class Message
 
   QUOTE_PATTERN = /^\s{0,4}[>|\}]/
   BLOCK_QUOTE_PATTERN = /^-----\s*Original Message\s*----+$/
-  SIG_PATTERN = /(^-- ?$)|(^\s*----------+\s*$)|(^\s*_________+\s*$)|(^\s*--~--~-)|(^\s*--\+\+\*\*==)/
+  SIG_PATTERN = /(^(- )*-- ?$)|(^\s*----------+\s*$)|(^\s*_________+\s*$)|(^\s*--~--~-)|(^\s*--\+\+\*\*==)/
 
   MAX_SIG_DISTANCE = 15 # lines from the end
   DEFAULT_SUBJECT = ""
@@ -511,8 +511,44 @@ private
         ## if there's no charset, use the current encoding as the charset.
         ## this ensures that the body is normalized to avoid non-displayable
         ## characters
-        body = Iconv.easy_decode($encoding, m.charset || $encoding, m.decode) if m.body
-        text_to_chunks((body || "").normalize_whitespace.split("\n"), encrypted)
+        if m.body
+          body = Iconv.easy_decode($encoding, m.charset || $encoding, m.decode)
+        else
+          body = ""
+        end
+        lines = body.split("\n")
+
+        ## Check for inline-PGP
+        msg_start = "^-----BEGIN PGP SIGNED MESSAGE-----$"
+        msg_end = "^-----END PGP SIGNED MESSAGE-----$"
+        gpg = lines.select { |l| true if l =~ /#{msg_start}/ .. l =~ /#{msg_end}/ }
+        if !gpg.empty?
+          msg = RMail::Message.new
+          msg.body = gpg.join("\n")
+
+          sig_start = "^-----BEGIN PGP SIGNATURE-----$"
+          sig = lines.select { |l| true if l =~ /#{msg_start}/ .. l =~ /#{sig_start}/ }
+          payload = RMail::Message.new
+          payload.body = sig[1, sig.count-2].join("\n")
+          return [CryptoManager.verify(nil, msg, false), message_to_chunks(payload)].flatten.compact
+        end
+
+        msg_start = "^-----BEGIN PGP MESSAGE-----$"
+        msg_end = "^-----END PGP MESSAGE-----$"
+        gpg = lines.select { |l| true if l =~ /#{msg_start}/ .. l =~ /#{msg_end}/ }
+        if !gpg.empty?
+          msg = RMail::Message.new
+          msg.body = gpg.join("\n")
+          notice, sig, decryptedm = CryptoManager.decrypt msg, true
+          if decryptedm # managed to decrypt
+            children = message_to_chunks(decryptedm, true)
+            return [notice, sig].compact + children
+          else
+            return [notice]
+          end
+        end
+
+        text_to_chunks(body.normalize_whitespace.split("\n"), encrypted)
       end
     end
   end
-- 
1.6.5


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

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

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

* Re: [sup-devel] [PATCH] Implement inline GPG (updated)
  2010-03-10 21:23                 ` Michael Stapelberg
@ 2010-03-12  4:43                   ` Rich Lane
  2010-03-12 11:02                     ` Michael Stapelberg
  0 siblings, 1 reply; 13+ messages in thread
From: Rich Lane @ 2010-03-12  4:43 UTC (permalink / raw)
  To: Michael Stapelberg; +Cc: sup-devel

lib/sup/message.rb:

Since the regexes only match whole lines, why not just do string
comparisons? I'd also like those strings to be constants but I won't
insist on that. 

The body assignment should be a ternary.

I really dislike the flip-flop operator but it looks like the best way
to do this. Please package those selects into a commented Enumerable
method.

Please factor your two cases in message_to_chunks into very well
documented methods. message_to_chunks is already too complicated.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


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

* Re: [sup-devel] [PATCH] Implement inline GPG (updated)
  2010-03-12  4:43                   ` Rich Lane
@ 2010-03-12 11:02                     ` Michael Stapelberg
  2010-03-15  5:19                       ` Rich Lane
  0 siblings, 1 reply; 13+ messages in thread
From: Michael Stapelberg @ 2010-03-12 11:02 UTC (permalink / raw)
  To: Rich Lane; +Cc: sup-devel

[-- Attachment #1: Type: text/plain, Size: 815 bytes --]

Hi Rich,

Excerpts from Rich Lane's message of Fr Mär 12 05:43:38 +0100 2010:
> Since the regexes only match whole lines, why not just do string
> comparisons? I'd also like those strings to be constants but I won't
> insist on that. 
Good point, I changed that.

> The body assignment should be a ternary.
I avoided that because the line gets incredibly long then (91 characters
vs. 79 characters inside the if. Are you sure you want that ternary?
If so, please just change it yourself.

> I really dislike the flip-flop operator but it looks like the best way
> to do this. Please package those selects into a commented Enumerable
> method.
Done.

> Please factor your two cases in message_to_chunks into very well
> documented methods. message_to_chunks is already too complicated.
Done.

Best regards,
Michael

[-- Attachment #2: 0001-Implement-inline-GPG.patch --]
[-- Type: application/octet-stream, Size: 8476 bytes --]

From 827d72529b46d0930bf3ee721284a8ec543ecbc5 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Tue, 9 Mar 2010 17:40:48 +0100
Subject: [PATCH] Implement inline GPG
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The SIG_PATTERN had to be changed because GPG, when clearsigning (which
is what happens when you send inline GPG messages), kind of escapes
lines beginning with dashes (so that the -----BEGIN PGP MESSAGE-----
lines don’t get messed up). Therefore, signatures, starting with "-- "
will be escaped as "- -- ". The manpage of GPG states that the process
of clearsigning is not reversible. Thus, there is no method in GPG to
get the original message.
---
 lib/sup/crypto.rb  |   62 ++++++++++++++++++++++++++++++++-------------------
 lib/sup/message.rb |   50 +++++++++++++++++++++++++++++++++++++++--
 lib/sup/util.rb    |    5 ++++
 3 files changed, 91 insertions(+), 26 deletions(-)

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 5ece6d9..abbcb98 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -97,18 +97,24 @@ EOS
     encrypt from, to, payload, true
   end
 
-  def verify payload, signature # both RubyMail::Message objects
+  def verify payload, signature, detached=true # both RubyMail::Message objects
     return unknown_status(cant_find_binary) unless @cmd
 
-    payload_fn = Tempfile.new "redwood.payload"
-    payload_fn.write format_payload(payload)
-    payload_fn.close
+    if detached
+      payload_fn = Tempfile.new "redwood.payload"
+      payload_fn.write format_payload(payload)
+      payload_fn.close
+    end
 
     signature_fn = Tempfile.new "redwood.signature"
     signature_fn.write signature.decode
     signature_fn.close
 
-    output = run_gpg "--verify #{signature_fn.path} #{payload_fn.path}"
+    if detached
+      output = run_gpg "--verify #{signature_fn.path} #{payload_fn.path}"
+    else
+      output = run_gpg "--verify #{signature_fn.path}"
+    end
     output_lines = output.split(/\n/)
 
     if output =~ /^gpg: (.* signature from .*$)/
@@ -123,7 +129,7 @@ EOS
   end
 
   ## returns decrypted_message, status, desc, lines
-  def decrypt payload # a RubyMail::Message object
+  def decrypt payload, armor=false # a RubyMail::Message object
     return unknown_status(cant_find_binary) unless @cmd
 
     payload_fn = Tempfile.new "redwood.payload"
@@ -153,24 +159,34 @@ EOS
       Chunk::CryptoNotice.new :invalid, $1, message.split("\n")
     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 output
-    if msg.header.content_type =~ %r{^multipart/} && !msg.multipart?
-      output = "MIME-Version: 1.0\n" + output
-      output.force_encoding Encoding::ASCII_8BIT if output.respond_to? :force_encoding
+    if armor
+      msg = RMail::Message.new
+      # Look for Charset, they are put before the base64 crypted part
+      charsets = payload.body.split("\n").grep(/^Charset:/)
+      if !charsets.empty? and charsets[0] =~ /^Charset: (.+)$/
+        output = Iconv.easy_decode($encoding, $1, output)
+      end
+      msg.body = output
+    else
+      # 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 output
+      if msg.header.content_type =~ %r{^multipart/} && !msg.multipart?
+        output = "MIME-Version: 1.0\n" + output
+        output.force_encoding Encoding::ASCII_8BIT if output.respond_to? :force_encoding
+        msg = RMail::Parser.read output
+      end
     end
     notice = Chunk::CryptoNotice.new :valid, "This message has been decrypted for display"
     [notice, sig, msg]
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index ebc73fc..30ccaf8 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -26,7 +26,13 @@ class Message
 
   QUOTE_PATTERN = /^\s{0,4}[>|\}]/
   BLOCK_QUOTE_PATTERN = /^-----\s*Original Message\s*----+$/
-  SIG_PATTERN = /(^-- ?$)|(^\s*----------+\s*$)|(^\s*_________+\s*$)|(^\s*--~--~-)|(^\s*--\+\+\*\*==)/
+  SIG_PATTERN = /(^(- )*-- ?$)|(^\s*----------+\s*$)|(^\s*_________+\s*$)|(^\s*--~--~-)|(^\s*--\+\+\*\*==)/
+
+  GPG_SIGNED_START = "-----BEGIN PGP SIGNED MESSAGE-----"
+  GPG_SIGNED_END = "-----END PGP SIGNED MESSAGE-----"
+  GPG_START = "-----BEGIN PGP MESSAGE-----"
+  GPG_END = "-----END PGP MESSAGE-----"
+  GPG_SIG_END = "-----BEGIN PGP SIGNATURE-----"
 
   MAX_SIG_DISTANCE = 15 # lines from the end
   DEFAULT_SUBJECT = ""
@@ -511,8 +517,46 @@ private
         ## if there's no charset, use the current encoding as the charset.
         ## this ensures that the body is normalized to avoid non-displayable
         ## characters
-        body = Iconv.easy_decode($encoding, m.charset || $encoding, m.decode) if m.body
-        text_to_chunks((body || "").normalize_whitespace.split("\n"), encrypted)
+        if m.body
+          body = Iconv.easy_decode($encoding, m.charset || $encoding, m.decode)
+        else
+          body = ""
+        end
+
+        ## Check for inline-PGP
+        chunks = inline_gpg_to_chunks body.split("\n")
+        return chunks if chunks
+
+        text_to_chunks(body.normalize_whitespace.split("\n"), encrypted)
+      end
+    end
+  end
+
+  ## looks for gpg signed (but not encrypted) inline  messages inside the
+  ## message body (there is no extra header for inline GPG) or for encrypted
+  ## (and possible signed) inline GPG messages
+  def inline_gpg_to_chunks lines
+    gpg = lines.between(GPG_SIGNED_START, GPG_SIGNED_END)
+    if !gpg.empty?
+      msg = RMail::Message.new
+      msg.body = gpg.join("\n")
+
+      sig = lines.between(GPG_SIGNED_START, GPG_SIG_END)
+      payload = RMail::Message.new
+      payload.body = sig[1, sig.count-2].join("\n")
+      return [CryptoManager.verify(nil, msg, false), message_to_chunks(payload)].flatten.compact
+    end
+
+    gpg = lines.between(GPG_START, GPG_END)
+    if !gpg.empty?
+      msg = RMail::Message.new
+      msg.body = gpg.join("\n")
+      notice, sig, decryptedm = CryptoManager.decrypt msg, true
+      if decryptedm # managed to decrypt
+        children = message_to_chunks(decryptedm, true)
+        return [notice, sig].compact + children
+      else
+        return [notice]
       end
     end
   end
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
index ab32d7c..fb9e0c3 100644
--- a/lib/sup/util.rb
+++ b/lib/sup/util.rb
@@ -459,6 +459,11 @@ module Enumerable
   def max_of
     map { |e| yield e }.max
   end
+
+  ## returns all the entries which are equal to startline up to endline
+  def between startline, endline
+    select { |l| true if l == startline .. l == endline }
+  end
 end
 
 class Array
-- 
1.6.5


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

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

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

* Re: [sup-devel] [PATCH] Implement inline GPG (updated)
  2010-03-12 11:02                     ` Michael Stapelberg
@ 2010-03-15  5:19                       ` Rich Lane
  0 siblings, 0 replies; 13+ messages in thread
From: Rich Lane @ 2010-03-15  5:19 UTC (permalink / raw)
  To: Michael Stapelberg; +Cc: sup-devel

Branch inline-gpg, merged to next.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


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

end of thread, other threads:[~2010-03-15  5:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-18 11:40 [sup-devel] [PATCH] Implement inline GPG Michael Stapelberg
2010-02-26 21:24 ` Rich Lane
2010-02-27 13:11   ` Michael Stapelberg
2010-02-27 18:05     ` Rich Lane
2010-03-01 13:45       ` Michael Stapelberg
2010-03-01 14:36         ` Christian Dietrich
2010-03-01 16:49           ` Michael Stapelberg
2010-03-01 17:46             ` Christian Dietrich
2010-03-09 16:43               ` [sup-devel] [PATCH] Implement inline GPG (updated) Michael Stapelberg
2010-03-10 21:23                 ` Michael Stapelberg
2010-03-12  4:43                   ` Rich Lane
2010-03-12 11:02                     ` Michael Stapelberg
2010-03-15  5:19                       ` Rich Lane

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