commit cf223e73293e3822e943576024f447ca0ff871de
parent beade458306f7ed3a11280280c4dbc49e8b076bb
Author: Matthieu Rakotojaona <matthieu.rakotojaona@gmail.com>
Date: Fri, 1 Nov 2013 13:32:46 +0100
Support more frequent representation of a PGP signed message
Diffstat:
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
@@ -571,10 +571,18 @@ private
## (and possible signed) inline GPG messages
def inline_gpg_to_chunks body, encoding_to, encoding_from
lines = body.split("\n")
+
+ # First case: Message is enclodsed between
+ #
+ # -----BEGIN PGP SIGNED MESSAGE-----
+ # and
+ # -----END PGP SIGNED MESSAGE-----
+ #
+ # In some cases, END PGP SIGNED MESSAGE doesn't appear
gpg = lines.between(GPG_SIGNED_START, GPG_SIGNED_END)
# between does not check if GPG_END actually exists
# Reference: http://permalink.gmane.org/gmane.mail.sup.devel/641
- if !gpg.empty? && !lines.index(GPG_END).nil?
+ if !gpg.empty?
msg = RMail::Message.new
msg.body = gpg.join("\n")
@@ -586,14 +594,21 @@ private
before = startidx != 0 ? lines[0 .. startidx-1] : []
after = endidx ? lines[endidx+1 .. lines.size] : []
+ # sig contains BEGIN PGP SIGNED MESSAGE and END PGP SIGNATURE, so
+ # we ditch them. sig may also contain the hash used by PGP (with a
+ # newline), so we also skip them
+ sig_start = sig[1].match(/^Hash:/) ? 3 : 1
+ sig_end = sig.size-2
payload = RMail::Message.new
- payload.body = sig[1, sig.size-2].join("\n")
+ payload.body = sig[sig_start, sig_end].join("\n")
return [text_to_chunks(before, false),
CryptoManager.verify(nil, msg, false),
message_to_chunks(payload),
text_to_chunks(after, false)].flatten.compact
end
+ # Second case: Message is encrypted
+
gpg = lines.between(GPG_START, GPG_END)
# between does not check if GPG_END actually exists
if !gpg.empty? && !lines.index(GPG_END).nil?