diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2010-08-06 17:18:21 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2010-12-02 21:48:39 +0100 |
commit | 88f24642bd789ac41a86fe34ffe469cf9f0521a3 (patch) | |
tree | 0d3ca69c76c018c64a18acde50445db75d982d83 /lib | |
parent | Send emails as delayed job (diff) | |
download | recruiting-webapp-88f24642bd789ac41a86fe34ffe469cf9f0521a3.tar.gz recruiting-webapp-88f24642bd789ac41a86fe34ffe469cf9f0521a3.tar.bz2 recruiting-webapp-88f24642bd789ac41a86fe34ffe469cf9f0521a3.zip |
Email answers allow checking signatures
Use Mail gem for receiving emails. Changed fixture email question to require a
valid signature. Tests for signatures validation.
Diffstat (limited to 'lib')
-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 |