diff options
Diffstat (limited to 'lib/message.rb')
-rw-r--r-- | lib/message.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/message.rb b/lib/message.rb new file mode 100644 index 0000000..a860c59 --- /dev/null +++ b/lib/message.rb @@ -0,0 +1,29 @@ +# This must not be automagically included. +# If this is included automatically Mail gem will not load properly and +# things will break. +module Mail + class Message + def signatures + boundary = content_type._?.match(/boundary="?([^;"]*)"?;?/)._?.captures._?.first + return [] unless boundary + + boundary = Regexp.escape(boundary) + signed = body.decoded.match(/#{boundary}\n(.*?)\n\-*#{boundary}/m)._?.captures._?.first + return [] unless signed + + result = [] + for part in parts[1..-1] + begin + GPGME::verify(part.decoded, signed){ |signature| result.push signature.to_s} + rescue + # Some signatures break GPGME::Signature#to_s - report them + result = [] + GPGME::verify(part.decoded, signed) do |signature| + result.push "Breaking signature" + end + end + end + result + end + end +end |