aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-08-06 17:18:21 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-12-02 21:48:39 +0100
commit88f24642bd789ac41a86fe34ffe469cf9f0521a3 (patch)
tree0d3ca69c76c018c64a18acde50445db75d982d83 /lib
parentSend emails as delayed job (diff)
downloadrecruiting-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.rb29
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