diff options
author | 2010-08-06 17:18:21 +0200 | |
---|---|---|
committer | 2010-12-02 21:48:39 +0100 | |
commit | 88f24642bd789ac41a86fe34ffe469cf9f0521a3 (patch) | |
tree | 0d3ca69c76c018c64a18acde50445db75d982d83 | |
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.
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 11 | ||||
-rw-r--r-- | app/models/email_answer.rb | 1 | ||||
-rw-r--r-- | app/models/receiver.rb | 8 | ||||
-rw-r--r-- | app/models/user_mailer.rb | 6 | ||||
-rw-r--r-- | db/fixtures/questions-email.yml | 9 | ||||
-rw-r--r-- | features/step_definitions/email_answer_steps.rb | 6 | ||||
-rw-r--r-- | lib/message.rb | 29 | ||||
-rw-r--r-- | spec/files/invaild-signed-thun-01.eml | 59 | ||||
-rw-r--r-- | spec/files/invalid-signed-mac-01.eml | 71 | ||||
-rw-r--r-- | spec/files/invalid-signed-mutt-01.eml | 57 | ||||
-rw-r--r-- | spec/files/invalid-signed-mutt-02.eml | 55 | ||||
-rw-r--r-- | spec/files/unsigned-gmail-01.eml | 12 | ||||
-rw-r--r-- | spec/files/unsigned-thunderbird-w-atachment-01.eml | 1 | ||||
-rw-r--r-- | spec/files/unsigned-thunderbird-w-atachment-02.eml | 24 | ||||
-rw-r--r-- | spec/files/valid-signed-mac-01.eml | 71 | ||||
-rw-r--r-- | spec/files/valid-signed-mutt-01.eml | 57 | ||||
-rw-r--r-- | spec/files/valid-signed-mutt-02.eml | 55 | ||||
-rw-r--r-- | spec/files/valid-signed-thun-01.eml | 59 | ||||
-rw-r--r-- | spec/helpers/message_spec.rb | 28 | ||||
-rw-r--r-- | spec/models/receiver_spec.rb | 11 | ||||
-rw-r--r-- | spec/models/user_mailer_spec.rb | 6 |
22 files changed, 619 insertions, 19 deletions
@@ -1,6 +1,8 @@ source :gemcutter gem 'rails', '2.3.5' +gem 'mail' +gem 'gpgme' gem 'hobo' gem 'hobo_openid', '>=0.4.2' gem 'bluecloth' diff --git a/Gemfile.lock b/Gemfile.lock index 0892b21..9a76a46 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,6 +32,7 @@ GEM gherkin (2.2.9) json (~> 1.4.6) term-ansicolor (~> 1.0.5) + gpgme (1.0.8) hobo (1.0.1) hobofields (= 1.0.1) hobosupport (= 1.0.1) @@ -47,8 +48,14 @@ GEM hobosupport (1.0.1) json (1.4.6) linecache (0.43) + mail (2.2.1) + activesupport (>= 2.3.4) + mime-types + treetop (>= 1.4.5) + mime-types (1.16) mysql (2.8.1) nokogiri (1.4.3.1) + polyglot (0.3.1) rack (1.0.1) rack-test (0.5.6) rack (>= 1.0) @@ -71,6 +78,8 @@ GEM shoulda (2.11.3) sqlite3-ruby (1.3.2) term-ansicolor (1.0.5) + treetop (1.4.8) + polyglot (>= 0.3.1) webrat (0.7.2) nokogiri (>= 1.2.0) rack (>= 1.0) @@ -87,8 +96,10 @@ DEPENDENCIES delayed_job email_spec (= 0.6.2) factory_girl + gpgme hobo hobo_openid (>= 0.4.2) + mail mysql nokogiri rails (= 2.3.5) diff --git a/app/models/email_answer.rb b/app/models/email_answer.rb index ffec1ac..fe21fb1 100644 --- a/app/models/email_answer.rb +++ b/app/models/email_answer.rb @@ -14,6 +14,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # Model storing answers for questions with email content. # No user is allowed to do anything except viewing. +require 'message.rb' class EmailAnswer < Answer fields do correct :boolean diff --git a/app/models/receiver.rb b/app/models/receiver.rb new file mode 100644 index 0000000..2235984 --- /dev/null +++ b/app/models/receiver.rb @@ -0,0 +1,8 @@ +require 'message.rb' +class Receiver + def self.receive(text) + # For now email answers for questions are only emails app receives + # so try use any received email as answer. + EmailAnswer.answer_from_email(Mail::Message.new(text)) + end +end diff --git a/app/models/user_mailer.rb b/app/models/user_mailer.rb index 1263e58..b405c8e 100644 --- a/app/models/user_mailer.rb +++ b/app/models/user_mailer.rb @@ -70,10 +70,4 @@ class UserMailer < ActionMailer::Base @body = { :email => email, :app_name => @app_name, :fields => fields } end - - def receive(email) - # For now email answers for questions are only emails app receives - # so try use any received email as answer. - EmailAnswer.answer_from_email(email) - end end diff --git a/db/fixtures/questions-email.yml b/db/fixtures/questions-email.yml index 6ad2d95..6a4a64b 100644 --- a/db/fixtures/questions-email.yml +++ b/db/fixtures/questions-email.yml @@ -3,12 +3,13 @@ email_q1: documentation: question_category: ebuild content: "Email a major eclass change announcement. Replace all - @gentoo.org addresses with @localhost addresses. + @gentoo.org addresses with @localhost addresses. Remember to sign the email. The from field should match email you set in the application. \n\nTo configure postfix use for example recruiting: \n\n gentoo-dev-announce: | \"curl -F 'email=<-' http://localhost:3000/users/receive_email\" \n gentoo-dev: /dev/null \n\nin /etc/mail/aliases." - req_text: 'To : gentoo-dev-announce@localhost - To : gentoo-dev@localhost - Reply-to : gentoo-dev@localhost' + req_text: "To : gentoo-dev-announce@localhost\n + To : gentoo-dev@localhost\n + Reply-to : gentoo-dev@localhost\n + Signatures : signature" diff --git a/features/step_definitions/email_answer_steps.rb b/features/step_definitions/email_answer_steps.rb index 24a2555..05f26ab 100644 --- a/features/step_definitions/email_answer_steps.rb +++ b/features/step_definitions/email_answer_steps.rb @@ -39,7 +39,7 @@ When /^I send wrong email announcement$/ do mail.from = @user.email_address mail.to = ['gentoo-dev-announce@localhost'] - UserMailer.receive(mail.to_s) + Receiver.receive(mail.to_s) end When /^I send proper email announcement$/ do @@ -51,7 +51,7 @@ When /^I send proper email announcement$/ do mail.to = ['gentoo-dev-announce@localhost', 'gentoo-dev@localhost'] mail.reply_to = 'gentoo-dev@localhost' - UserMailer.receive(mail.to_s) + Receiver.receive(mail.to_s) end When /^someone sends forged answer$/ do @@ -65,7 +65,7 @@ When /^someone sends forged answer$/ do Given 'user "forger"' mail.subject = "#{@question.id}-#{@user.token}" - UserMailer.receive(mail.to_s) + Receiver.receive(mail.to_s) end Then /^I should see subject for email "([^"]+)" should send to answer "([^"]+)"$/ do |user, question| 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 diff --git a/spec/files/invaild-signed-thun-01.eml b/spec/files/invaild-signed-thun-01.eml new file mode 100644 index 0000000..9eabdb2 --- /dev/null +++ b/spec/files/invaild-signed-thun-01.eml @@ -0,0 +1,59 @@ + +Return-Path: <jbartosik@gmail.com> +Received: from [192.168.1.4] (aatc109.neoplus.adsl.tpnet.pl [83.5.240.109]) + by mx.google.com with ESMTPS id s34sm4924693bkk.1.2010.09.13.11.27.44 + (version=SSLv3 cipher=RC4-MD5); + Mon, 13 Sep 2010 11:27:45 -0700 (PDT) +Message-ID: <4C8E6DE6.8030700@gmail.com> +Date: Mon, 13 Sep 2010 20:31:02 +0200 +From: Joachim Bartosik <jbartosik@gmail.com> +User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100912 Lightning/1.0b3pre Thunderbird/3.1.3 +MIME-Version: 1.0 +To: =?UTF-8?B?UGV0dGVyaSBSw6R0eQ==?= <betelgeuse@gentoo.org> +CC: Alex Legler <a3li@gentoo.org> +Subject: Gentoo Recruiters Application +X-Enigmail-Version: 1.1.2 +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; + boundary="------------enig47B3F63504D3ABAB3C58C63F" + +This is an OpenPGP/MIME signed message (RFC 2440 and 3156) +--------------enig47B3F63504D3ABAB3C58C63F +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: quoted-printable + +I'm finally resuming my work on Gentoo Recruiters Application so I +thought I'd remind you that there are two brunches waiting for push to +official repository: +* AGPL +* feedback_stat + +Regards, +Joachim + + +--------------enig47B3F63504D3ABAB3C58C63F +Content-Type: application/pgp-signature; name="signature.asc" +Content-Description: OpenPGP digital signature +Content-Disposition: attachment; filename="signature.asc" + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v2.0.16 (GNU/Linux) +Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ + +iQIcBAEBAgAGBQJMjm3mAAoJEI0yxgiYdAoguvsQAIiK/1b2kryD24OCWtDqBLl+ +BKZtC9TZzokM/1WjSp+XTDs1GeDob+94LDUyCoK89+gvg57lbuGvZ/AtzU89uvPJ +ckjPmgraxyVcJiUX20Qjc/DZv4rvVrjAjeKBknmBYq45G2AaZXFRFfdnKnTNZGIV +Op9InqRBeoXCf8eFxmgvI6nX7pIeTLVC8m1JHldLm4M5R+7ifqvU0vWyRPFbLPsk +CYFSGuMRexmaGrJ0u6e1R/QiynsjyXV9ygBe3R2B38tBvuK9lXYLiC/z+GVTsRtl +UiIvxWjbIP0HV4kNOKSgnYOgB4WhFps4rPKchGKypDljk0xf6yKz5IlXh0NhPyhJ +bqhYYMSJZ+ocpVjZ4aeof2eVrO+LQ1Y4IqJ0zYpUGlzpAKRzp4jKb5EvA7l2rEQJ +iEi+5sudaen8j578Aq+ffDkm+VA8e7+7rHrr45yiw+n1zcipYuwdo4kn21jZWaHN +bOtJB7ZyikrjDm5hT88DNqwbse6oj0p+s+iC9PXyGJB7N69RBjxWjCkVXlBVoHDM +eO8DCwvIFGMJ7nrChkECtkAQkrVjp0kBCkBXQaevWjoL/GvdT779GlfWbROqFDob +CRDEc6yiVmmuiYo3a0v6ASoVJuhvgKeJ7xxF2JQxC+fDz8qyFSTSmUVWkqdsxLNd +G60Q5pImq8vsYiHvEg6J +=AtMz +-----END PGP SIGNATURE----- + +--------------enig47B3F63504D3ABAB3C58C63F-- diff --git a/spec/files/invalid-signed-mac-01.eml b/spec/files/invalid-signed-mac-01.eml new file mode 100644 index 0000000..822f6ca --- /dev/null +++ b/spec/files/invalid-signed-mac-01.eml @@ -0,0 +1,71 @@ +Delivered-To: jbartosik@gmail.com
+Received: by 10.229.250.147 with SMTP id mo19cs11744qcb;
+ Wed, 6 Oct 2010 13:14:48 -0700 (PDT)
+Received: by 10.227.129.149 with SMTP id o21mr11043060wbs.176.1286396087327;
+ Wed, 06 Oct 2010 13:14:47 -0700 (PDT)
+Return-Path: <gentoo@floriancrouzat.net>
+Received: from relay4-v.mail.gandi.net (relay4-v.mail.gandi.net [217.70.178.78])
+ by mx.google.com with ESMTP id u71si1852350weq.44.2010.10.06.13.14.46;
+ Wed, 06 Oct 2010 13:14:47 -0700 (PDT)
+Received-SPF: neutral (google.com: 217.70.178.78 is neither permitted nor denied by best guess record for domain of gentoo@floriancrouzat.net) client-ip=217.70.178.78;
+Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.178.78 is neither permitted nor denied by best guess record for domain of gentoo@floriancrouzat.net) smtp.mail=gentoo@floriancrouzat.net
+X-Originating-IP: 217.70.178.42
+Received: from mfilter2-d.gandi.net (mfilter2-d.gandi.net [217.70.178.42])
+ by relay4-v.mail.gandi.net (Postfix) with ESMTP id C9843BA74
+ for <jbartosik@gmail.com>; Wed, 6 Oct 2010 22:14:46 +0200 (CEST)
+X-Virus-Scanned: Debian amavisd-new at mfilter2-d.gandi.net
+Received: from relay4-v.mail.gandi.net ([217.70.178.78])
+ by mfilter2-d.gandi.net (mfilter2-d.gandi.net [217.70.178.42]) (amavisd-new, port 10024)
+ with ESMTP id q+iis3HCV57D for <jbartosik@gmail.com>;
+ Wed, 6 Oct 2010 22:14:44 +0200 (CEST)
+X-Originating-IP: 88.173.156.163
+Received: from [192.168.1.2] (unknown [88.173.156.163])
+ (Authenticated sender: gentoo@floriancrouzat.net)
+ by relay4-v.mail.gandi.net (Postfix) with ESMTPSA id 2E297BA5F
+ for <jbartosik@gmail.com>; Wed, 6 Oct 2010 22:14:43 +0200 (CEST)
+From: Florian CROUZAT <gentoo@floriancrouzat.net>
+Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-18-998720552"
+Content-Transfer-Encoding: 7bit
+Subject: Regarding your blog post (gpg)
+Date: Wed, 6 Oct 2010 22:14:42 +0200
+Message-Id: <85C08C77-A10A-4FC5-9EC6-A3ED4A89A7B9@floriancrouzat.net>
+To: jbartosik@gmail.com
+Mime-Version: 1.0 (Apple Message framework v1081)
+X-Pgp-Agent: GPGMail 1.2.3
+X-Mailer: Apple Mail (2.1081)
+
+This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
+--Apple-Mail-18-998720552
+Content-Transfer-Encoding: 7bit
+Content-Type: text/plain; charset=us-ascii
+
+This is a signed mail from my mac using Mail.app and the GPGMail plugin.
+Hope it helps.
+
+Cheer.
+
+-----
+Florian.
+/ For security reasons, all text in this mail
+ is double-rot13 encrypted. /
+
+
+--Apple-Mail-18-998720552
+content-type: application/pgp-signature; x-mac-type=70674453;
+ name=PGP.sig
+content-description: This is a digitally signed message part
+content-disposition: inline; filename=PGP.sig
+content-transfer-encoding: 7bit
+
+-----BEGIN PGP SIGNATURE-----
+
+iQEcBAEBAgAGBQJMrNiyAAoJEI54KfPdrpQaoiAH/2SZ8FPr8Kt5KgTmslNDZDlI
+98xYlqTN4UeZlKBIsc9zl48lXX6o7RfXn38ociH5bPytZoBAUdjfdR+lsFawW8lW
+Xpx1Ieal+R1xPoxBgj6egU3n+bvnF2y4uuHn8QNOmJyzV98GdGZHlKnCig1sWuHs
+h5LqEyLe6Bhdj6ADgwQwl30rf+J7dSRk0mqu1ufsl2EjaTyxDDxa+dZ0rsBP2JGu
+CFLIbpgrYNhsmjtkF2CAoELJU5K6wqJ1j6Ajej21DaydFthmBtcXkBfBnwHlOckT
+1gHO/Phny6f2QO9Q8tnlIiqOmJTScrCG9yQq5gAeCJWrhCRsDVsLwkKecnlDoNg=
+=0fDv
+-----END PGP SIGNATURE-----
+
+--Apple-Mail-18-998720552--
diff --git a/spec/files/invalid-signed-mutt-01.eml b/spec/files/invalid-signed-mutt-01.eml new file mode 100644 index 0000000..97c6b63 --- /dev/null +++ b/spec/files/invalid-signed-mutt-01.eml @@ -0,0 +1,57 @@ +Delivered-To: jbartosik@gmail.com
+Received: by 10.142.255.19 with SMTP id c19cs17522wfi;
+ Tue, 5 Oct 2010 15:57:19 -0700 (PDT)
+Received: by 10.114.38.11 with SMTP id l11mr14535633wal.61.1286319439385;
+ Tue, 05 Oct 2010 15:57:19 -0700 (PDT)
+Return-Path: <dberkholz@gentoo.org>
+Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
+ by mx.google.com with ESMTP id u9si220057wak.97.2010.10.05.15.57.19;
+ Tue, 05 Oct 2010 15:57:19 -0700 (PDT)
+Received-SPF: pass (google.com: domain of dberkholz@gentoo.org designates 140.211.166.183 as permitted sender) client-ip=140.211.166.183;
+Authentication-Results: mx.google.com; spf=pass (google.com: domain of dberkholz@gentoo.org designates 140.211.166.183 as permitted sender) smtp.mail=dberkholz@gentoo.org
+Received: from gentoo.org (mayo-nat4.mayo.edu [129.176.197.23])
+ (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))
+ (No client certificate requested)
+ by smtp.gentoo.org (Postfix) with ESMTPSA id 286B01B4037
+ for <jbartosik@gmail.com>; Tue, 5 Oct 2010 22:57:19 +0000 (UTC)
+Date: Tue, 5 Oct 2010 17:57:37 -0500
+From: Donnie Berkholz <dberkholz@gentoo.org>
+To: jbartosik@gmail.com
+Subject: Test signed email
+Message-ID: <20101005225737.GD14137@comet.mayo.edu>
+MIME-Version: 1.0
+Content-Type: multipart/signed; micalg=pgp-sha1;
+ protocol="application/pgp-signature"; boundary="P+33d92oIH25kiaB"
+Content-Disposition: inline
+User-Agent: Mutt/1.5.20 (2009-06-14)
+
+
+--P+33d92oIH25kiaB
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: inline
+Content-Transfer-Encoding: quoted-printable
+
+Here yo go.
+
+
+--=20
+Thanks,
+Donnie
+
+Donnie Berkholz
+Sr. Developer, Gentoo Linux
+Blog: http://dberkholz.wordpress.com
+
+--P+33d92oIH25kiaB
+Content-Type: application/pgp-signature
+Content-Disposition: inline
+
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v2.0.16 (GNU/Linux)
+
+iEYEABECAAYFAkyrrWEACgkQXVaO67S1rtsbzgCg2ULZnOjukYezLAGlVkVOL60F
+azAAoLRfMcSuCHzOczVlZq1Cnrp+0WmB
+=homo
+-----END PGP SIGNATURE-----
+
+--P+33d92oIH25kiaB--
diff --git a/spec/files/invalid-signed-mutt-02.eml b/spec/files/invalid-signed-mutt-02.eml new file mode 100644 index 0000000..ff8cc73 --- /dev/null +++ b/spec/files/invalid-signed-mutt-02.eml @@ -0,0 +1,55 @@ +Delivered-To: jbartosik@gmail.com
+Received: by 10.229.250.147 with SMTP id mo19cs7485qcb;
+ Wed, 6 Oct 2010 20:12:13 -0700 (PDT)
+Received: by 10.100.198.4 with SMTP id v4mr271234anf.42.1286421132543;
+ Wed, 06 Oct 2010 20:12:12 -0700 (PDT)
+Return-Path: <jgeisler@cse.taylor.edu>
+Received: from smtp.cse.taylor.edu (smtp1.css.tayloru.edu [192.195.249.2])
+ by mx.google.com with ESMTP id i35si1444642anh.71.2010.10.06.20.12.12;
+ Wed, 06 Oct 2010 20:12:12 -0700 (PDT)
+Received-SPF: neutral (google.com: 192.195.249.2 is neither permitted nor denied by best guess record for domain of jgeisler@cse.taylor.edu) client-ip=192.195.249.2;
+Authentication-Results: mx.google.com; spf=neutral (google.com: 192.195.249.2 is neither permitted nor denied by best guess record for domain of jgeisler@cse.taylor.edu) smtp.mail=jgeisler@cse.taylor.edu
+Received: from jgeisler.cse.taylor.edu (ppp-70-225-142-226.dsl.ipltin.ameritech.net [70.225.142.226])
+ by smtp.cse.taylor.edu (Postfix) with ESMTP id AA99D4FA32B
+ for <jbartosik@gmail.com>; Wed, 6 Oct 2010 23:12:11 -0400 (EDT)
+Received: by jgeisler.cse.taylor.edu (Postfix, from userid 2421)
+ id 640DA6698D; Wed, 6 Oct 2010 23:11:32 -0400 (EDT)
+Date: Wed, 6 Oct 2010 23:11:32 -0400
+From: Jonathan Geisler <jgeisler@cse.taylor.edu>
+To: jbartosik@gmail.com
+Subject: signed message from Mutt
+Message-ID: <20101007031132.GL7080@cse.taylor.edu>
+MIME-Version: 1.0
+Content-Type: multipart/signed; micalg=pgp-sha256;
+ protocol="application/pgp-signature"; boundary="iKKZt69u2Wx/rspf"
+Content-Disposition: inline
+User-Agent: Mutt/1.5.20 (2009-06-14)
+X-Virus-Scanned: clamav-milter 0.96.3 at mary.cse.taylor.edu
+X-Virus-Status: Clean
+
+
+--iKKZt69u2Wx/rspf
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: inline
+
+Here is a signed message sent from a Matt client.
+
+ -- Jonathan Geisler --
+
+--iKKZt69u2Wx/rspf
+Content-Type: application/pgp-signature
+Content-Disposition: inline
+
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v2.0.16 (GNU/Linux)
+
+iQEcBAEBCAAGBQJMrTpkAAoJEOwSkIyhEMwrKs0H/2ZWR3ZW+j8QQr1pxI+lkbpp
+CkOjNzGUPWUNnx504jxteCMmPfIHpllZ9Jl35IEF3oqy8jW0b5bj02v3PfI2MOpV
+zBGqr1dhsCmFg4nJygkCwJ9srsk0IkxplltCDLMfAXPBauOAOB16s/QmUdQmZeY4
+kuvfMUFdODMpENF3UAicsoMkQSlV7YnQnL7i1mM+Gpj1Z6D+DLTtPsYZl/c/148T
+MyDVk7ez8zK0o/XQTWTETYg7Tu6VhjS3XDtc4YtwEEalgaf6nXLgLm23KkWy8lnC
+UAKOC4Il9nM5wA/4KsVds56f988Fu2yGDas0AFinh/ICY0Dgz0C4Pbur/bLS8gk=
+=uxnH
+-----END PGP SIGNATURE-----
+
+--iKKZt69u2Wx/rspf--
diff --git a/spec/files/unsigned-gmail-01.eml b/spec/files/unsigned-gmail-01.eml new file mode 100644 index 0000000..39590f8 --- /dev/null +++ b/spec/files/unsigned-gmail-01.eml @@ -0,0 +1,12 @@ + +MIME-Version: 1.0
+Received: by 10.229.250.147 with HTTP; Wed, 22 Sep 2010 02:02:30 -0700 (PDT)
+Date: Wed, 22 Sep 2010 11:02:30 +0200
+Delivered-To: jbartosik@gmail.com
+Message-ID: <AANLkTikUWvPR53mHSMiUHoDFEkrach+x11mg1Sw0qpih@mail.gmail.com>
+Subject: fake
+From: Joachim Bartosik <jbartosik@gmail.com>
+To: Joachim Bartosik <jbartosik@gmail.com>
+Content-Type: text/plain; charset=UTF-8
+
+fake
diff --git a/spec/files/unsigned-thunderbird-w-atachment-01.eml b/spec/files/unsigned-thunderbird-w-atachment-01.eml new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/spec/files/unsigned-thunderbird-w-atachment-01.eml @@ -0,0 +1 @@ +test diff --git a/spec/files/unsigned-thunderbird-w-atachment-02.eml b/spec/files/unsigned-thunderbird-w-atachment-02.eml new file mode 100644 index 0000000..a507b7c --- /dev/null +++ b/spec/files/unsigned-thunderbird-w-atachment-02.eml @@ -0,0 +1,24 @@ +Return-Path: <jbartosik@gmail.com>
+Received: from [192.168.1.3] (afgf33.neoplus.adsl.tpnet.pl [95.49.161.33])
+ by mx.google.com with ESMTPS id j14sm501525faa.23.2010.11.05.02.39.58
+ (version=SSLv3 cipher=RC4-MD5);
+ Fri, 05 Nov 2010 02:39:59 -0700 (PDT)
+Message-ID: <4CD3D1D6.3040408@gmail.com>
+Date: Fri, 05 Nov 2010 10:43:50 +0100
+From: Joachim Filip Bartosik <jbartosik@gmail.com>
+User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101102 Lightning/1.0b3pre Thunderbird/3.1.6
+MIME-Version: 1.0
+To: Joachim Bartosik <jbartosik+error501@gmail.com>
+Subject: test
+X-Enigmail-Version: 1.1.2
+Content-Type: multipart/mixed;
+ boundary="------------020708070202070004090004"
+
+This is a multi-part message in MIME format.
+--------------020708070202070004090004
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+with attachment
+
+--------------020708070202070004090004--
diff --git a/spec/files/valid-signed-mac-01.eml b/spec/files/valid-signed-mac-01.eml new file mode 100644 index 0000000..57f4d56 --- /dev/null +++ b/spec/files/valid-signed-mac-01.eml @@ -0,0 +1,71 @@ +Delivered-To: jbartosik@gmail.com
+Received: by 10.229.250.147 with SMTP id mo19cs11744qcb;
+ Wed, 6 Oct 2010 13:14:48 -0700 (PDT)
+Received: by 10.227.129.149 with SMTP id o21mr11043060wbs.176.1286396087327;
+ Wed, 06 Oct 2010 13:14:47 -0700 (PDT)
+Return-Path: <gentoo@floriancrouzat.net>
+Received: from relay4-v.mail.gandi.net (relay4-v.mail.gandi.net [217.70.178.78])
+ by mx.google.com with ESMTP id u71si1852350weq.44.2010.10.06.13.14.46;
+ Wed, 06 Oct 2010 13:14:47 -0700 (PDT)
+Received-SPF: neutral (google.com: 217.70.178.78 is neither permitted nor denied by best guess record for domain of gentoo@floriancrouzat.net) client-ip=217.70.178.78;
+Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.178.78 is neither permitted nor denied by best guess record for domain of gentoo@floriancrouzat.net) smtp.mail=gentoo@floriancrouzat.net
+X-Originating-IP: 217.70.178.42
+Received: from mfilter2-d.gandi.net (mfilter2-d.gandi.net [217.70.178.42])
+ by relay4-v.mail.gandi.net (Postfix) with ESMTP id C9843BA74
+ for <jbartosik@gmail.com>; Wed, 6 Oct 2010 22:14:46 +0200 (CEST)
+X-Virus-Scanned: Debian amavisd-new at mfilter2-d.gandi.net
+Received: from relay4-v.mail.gandi.net ([217.70.178.78])
+ by mfilter2-d.gandi.net (mfilter2-d.gandi.net [217.70.178.42]) (amavisd-new, port 10024)
+ with ESMTP id q+iis3HCV57D for <jbartosik@gmail.com>;
+ Wed, 6 Oct 2010 22:14:44 +0200 (CEST)
+X-Originating-IP: 88.173.156.163
+Received: from [192.168.1.2] (unknown [88.173.156.163])
+ (Authenticated sender: gentoo@floriancrouzat.net)
+ by relay4-v.mail.gandi.net (Postfix) with ESMTPSA id 2E297BA5F
+ for <jbartosik@gmail.com>; Wed, 6 Oct 2010 22:14:43 +0200 (CEST)
+From: Florian CROUZAT <gentoo@floriancrouzat.net>
+Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-18-998720552"
+Content-Transfer-Encoding: 7bit
+Subject: Regarding your blog post (gpg)
+Date: Wed, 6 Oct 2010 22:14:42 +0200
+Message-Id: <85C08C77-A10A-4FC5-9EC6-A3ED4A89A7B9@floriancrouzat.net>
+To: jbartosik@gmail.com
+Mime-Version: 1.0 (Apple Message framework v1081)
+X-Pgp-Agent: GPGMail 1.2.3
+X-Mailer: Apple Mail (2.1081)
+
+This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
+--Apple-Mail-18-998720552
+Content-Transfer-Encoding: 7bit
+Content-Type: text/plain; charset=us-ascii
+
+This is a signed mail from my mac using Mail.app and the GPGMail plugin.
+Hope it helps.
+
+Cheers.
+
+-----
+Florian.
+/ For security reasons, all text in this mail
+ is double-rot13 encrypted. /
+
+
+--Apple-Mail-18-998720552
+content-type: application/pgp-signature; x-mac-type=70674453;
+ name=PGP.sig
+content-description: This is a digitally signed message part
+content-disposition: inline; filename=PGP.sig
+content-transfer-encoding: 7bit
+
+-----BEGIN PGP SIGNATURE-----
+
+iQEcBAEBAgAGBQJMrNiyAAoJEI54KfPdrpQaoiAH/2SZ8FPr8Kt5KgTmslNDZDlI
+98xYlqTN4UeZlKBIsc9zl48lXX6o7RfXn38ociH5bPytZoBAUdjfdR+lsFawW8lW
+Xpx1Ieal+R1xPoxBgj6egU3n+bvnF2y4uuHn8QNOmJyzV98GdGZHlKnCig1sWuHs
+h5LqEyLe6Bhdj6ADgwQwl30rf+J7dSRk0mqu1ufsl2EjaTyxDDxa+dZ0rsBP2JGu
+CFLIbpgrYNhsmjtkF2CAoELJU5K6wqJ1j6Ajej21DaydFthmBtcXkBfBnwHlOckT
+1gHO/Phny6f2QO9Q8tnlIiqOmJTScrCG9yQq5gAeCJWrhCRsDVsLwkKecnlDoNg=
+=0fDv
+-----END PGP SIGNATURE-----
+
+--Apple-Mail-18-998720552--
diff --git a/spec/files/valid-signed-mutt-01.eml b/spec/files/valid-signed-mutt-01.eml new file mode 100644 index 0000000..6be6666 --- /dev/null +++ b/spec/files/valid-signed-mutt-01.eml @@ -0,0 +1,57 @@ +Delivered-To: jbartosik@gmail.com
+Received: by 10.142.255.19 with SMTP id c19cs17522wfi;
+ Tue, 5 Oct 2010 15:57:19 -0700 (PDT)
+Received: by 10.114.38.11 with SMTP id l11mr14535633wal.61.1286319439385;
+ Tue, 05 Oct 2010 15:57:19 -0700 (PDT)
+Return-Path: <dberkholz@gentoo.org>
+Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
+ by mx.google.com with ESMTP id u9si220057wak.97.2010.10.05.15.57.19;
+ Tue, 05 Oct 2010 15:57:19 -0700 (PDT)
+Received-SPF: pass (google.com: domain of dberkholz@gentoo.org designates 140.211.166.183 as permitted sender) client-ip=140.211.166.183;
+Authentication-Results: mx.google.com; spf=pass (google.com: domain of dberkholz@gentoo.org designates 140.211.166.183 as permitted sender) smtp.mail=dberkholz@gentoo.org
+Received: from gentoo.org (mayo-nat4.mayo.edu [129.176.197.23])
+ (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))
+ (No client certificate requested)
+ by smtp.gentoo.org (Postfix) with ESMTPSA id 286B01B4037
+ for <jbartosik@gmail.com>; Tue, 5 Oct 2010 22:57:19 +0000 (UTC)
+Date: Tue, 5 Oct 2010 17:57:37 -0500
+From: Donnie Berkholz <dberkholz@gentoo.org>
+To: jbartosik@gmail.com
+Subject: Test signed email
+Message-ID: <20101005225737.GD14137@comet.mayo.edu>
+MIME-Version: 1.0
+Content-Type: multipart/signed; micalg=pgp-sha1;
+ protocol="application/pgp-signature"; boundary="P+33d92oIH25kiaB"
+Content-Disposition: inline
+User-Agent: Mutt/1.5.20 (2009-06-14)
+
+
+--P+33d92oIH25kiaB
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: inline
+Content-Transfer-Encoding: quoted-printable
+
+Here ya go.
+
+
+--=20
+Thanks,
+Donnie
+
+Donnie Berkholz
+Sr. Developer, Gentoo Linux
+Blog: http://dberkholz.wordpress.com
+
+--P+33d92oIH25kiaB
+Content-Type: application/pgp-signature
+Content-Disposition: inline
+
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v2.0.16 (GNU/Linux)
+
+iEYEABECAAYFAkyrrWEACgkQXVaO67S1rtsbzgCg2ULZnOjukYezLAGlVkVOL60F
+azAAoLRfMcSuCHzOczVlZq1Cnrp+0WmB
+=homo
+-----END PGP SIGNATURE-----
+
+--P+33d92oIH25kiaB--
diff --git a/spec/files/valid-signed-mutt-02.eml b/spec/files/valid-signed-mutt-02.eml new file mode 100644 index 0000000..2525f53 --- /dev/null +++ b/spec/files/valid-signed-mutt-02.eml @@ -0,0 +1,55 @@ +Delivered-To: jbartosik@gmail.com
+Received: by 10.229.250.147 with SMTP id mo19cs7485qcb;
+ Wed, 6 Oct 2010 20:12:13 -0700 (PDT)
+Received: by 10.100.198.4 with SMTP id v4mr271234anf.42.1286421132543;
+ Wed, 06 Oct 2010 20:12:12 -0700 (PDT)
+Return-Path: <jgeisler@cse.taylor.edu>
+Received: from smtp.cse.taylor.edu (smtp1.css.tayloru.edu [192.195.249.2])
+ by mx.google.com with ESMTP id i35si1444642anh.71.2010.10.06.20.12.12;
+ Wed, 06 Oct 2010 20:12:12 -0700 (PDT)
+Received-SPF: neutral (google.com: 192.195.249.2 is neither permitted nor denied by best guess record for domain of jgeisler@cse.taylor.edu) client-ip=192.195.249.2;
+Authentication-Results: mx.google.com; spf=neutral (google.com: 192.195.249.2 is neither permitted nor denied by best guess record for domain of jgeisler@cse.taylor.edu) smtp.mail=jgeisler@cse.taylor.edu
+Received: from jgeisler.cse.taylor.edu (ppp-70-225-142-226.dsl.ipltin.ameritech.net [70.225.142.226])
+ by smtp.cse.taylor.edu (Postfix) with ESMTP id AA99D4FA32B
+ for <jbartosik@gmail.com>; Wed, 6 Oct 2010 23:12:11 -0400 (EDT)
+Received: by jgeisler.cse.taylor.edu (Postfix, from userid 2421)
+ id 640DA6698D; Wed, 6 Oct 2010 23:11:32 -0400 (EDT)
+Date: Wed, 6 Oct 2010 23:11:32 -0400
+From: Jonathan Geisler <jgeisler@cse.taylor.edu>
+To: jbartosik@gmail.com
+Subject: signed message from Mutt
+Message-ID: <20101007031132.GL7080@cse.taylor.edu>
+MIME-Version: 1.0
+Content-Type: multipart/signed; micalg=pgp-sha256;
+ protocol="application/pgp-signature"; boundary="iKKZt69u2Wx/rspf"
+Content-Disposition: inline
+User-Agent: Mutt/1.5.20 (2009-06-14)
+X-Virus-Scanned: clamav-milter 0.96.3 at mary.cse.taylor.edu
+X-Virus-Status: Clean
+
+
+--iKKZt69u2Wx/rspf
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: inline
+
+Here is a signed message sent from a Mutt client.
+
+ -- Jonathan Geisler --
+
+--iKKZt69u2Wx/rspf
+Content-Type: application/pgp-signature
+Content-Disposition: inline
+
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v2.0.16 (GNU/Linux)
+
+iQEcBAEBCAAGBQJMrTpkAAoJEOwSkIyhEMwrKs0H/2ZWR3ZW+j8QQr1pxI+lkbpp
+CkOjNzGUPWUNnx504jxteCMmPfIHpllZ9Jl35IEF3oqy8jW0b5bj02v3PfI2MOpV
+zBGqr1dhsCmFg4nJygkCwJ9srsk0IkxplltCDLMfAXPBauOAOB16s/QmUdQmZeY4
+kuvfMUFdODMpENF3UAicsoMkQSlV7YnQnL7i1mM+Gpj1Z6D+DLTtPsYZl/c/148T
+MyDVk7ez8zK0o/XQTWTETYg7Tu6VhjS3XDtc4YtwEEalgaf6nXLgLm23KkWy8lnC
+UAKOC4Il9nM5wA/4KsVds56f988Fu2yGDas0AFinh/ICY0Dgz0C4Pbur/bLS8gk=
+=uxnH
+-----END PGP SIGNATURE-----
+
+--iKKZt69u2Wx/rspf--
diff --git a/spec/files/valid-signed-thun-01.eml b/spec/files/valid-signed-thun-01.eml new file mode 100644 index 0000000..0b9a30c --- /dev/null +++ b/spec/files/valid-signed-thun-01.eml @@ -0,0 +1,59 @@ + +Return-Path: <jbartosik@gmail.com> +Received: from [192.168.1.4] (aatc109.neoplus.adsl.tpnet.pl [83.5.240.109]) + by mx.google.com with ESMTPS id s34sm4924693bkk.1.2010.09.13.11.27.44 + (version=SSLv3 cipher=RC4-MD5); + Mon, 13 Sep 2010 11:27:45 -0700 (PDT) +Message-ID: <4C8E6DE6.8030700@gmail.com> +Date: Mon, 13 Sep 2010 20:31:02 +0200 +From: Joachim Bartosik <jbartosik@gmail.com> +User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100912 Lightning/1.0b3pre Thunderbird/3.1.3 +MIME-Version: 1.0 +To: =?UTF-8?B?UGV0dGVyaSBSw6R0eQ==?= <betelgeuse@gentoo.org> +CC: Alex Legler <a3li@gentoo.org> +Subject: Gentoo Recruiters Application +X-Enigmail-Version: 1.1.2 +Content-Type: multipart/signed; micalg=pgp-sha1; + protocol="application/pgp-signature"; + boundary="------------enig47B3F63504D3ABAB3C58C63F" + +This is an OpenPGP/MIME signed message (RFC 2440 and 3156) +--------------enig47B3F63504D3ABAB3C58C63F +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: quoted-printable + +I'm finally resuming my work on Gentoo Recruiters Application so I +thought I'd remind you that there are two branches waiting for push to +official repository: +* AGPL +* feedback_stat + +Regards, +Joachim + + +--------------enig47B3F63504D3ABAB3C58C63F +Content-Type: application/pgp-signature; name="signature.asc" +Content-Description: OpenPGP digital signature +Content-Disposition: attachment; filename="signature.asc" + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v2.0.16 (GNU/Linux) +Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ + +iQIcBAEBAgAGBQJMjm3mAAoJEI0yxgiYdAoguvsQAIiK/1b2kryD24OCWtDqBLl+ +BKZtC9TZzokM/1WjSp+XTDs1GeDob+94LDUyCoK89+gvg57lbuGvZ/AtzU89uvPJ +ckjPmgraxyVcJiUX20Qjc/DZv4rvVrjAjeKBknmBYq45G2AaZXFRFfdnKnTNZGIV +Op9InqRBeoXCf8eFxmgvI6nX7pIeTLVC8m1JHldLm4M5R+7ifqvU0vWyRPFbLPsk +CYFSGuMRexmaGrJ0u6e1R/QiynsjyXV9ygBe3R2B38tBvuK9lXYLiC/z+GVTsRtl +UiIvxWjbIP0HV4kNOKSgnYOgB4WhFps4rPKchGKypDljk0xf6yKz5IlXh0NhPyhJ +bqhYYMSJZ+ocpVjZ4aeof2eVrO+LQ1Y4IqJ0zYpUGlzpAKRzp4jKb5EvA7l2rEQJ +iEi+5sudaen8j578Aq+ffDkm+VA8e7+7rHrr45yiw+n1zcipYuwdo4kn21jZWaHN +bOtJB7ZyikrjDm5hT88DNqwbse6oj0p+s+iC9PXyGJB7N69RBjxWjCkVXlBVoHDM +eO8DCwvIFGMJ7nrChkECtkAQkrVjp0kBCkBXQaevWjoL/GvdT779GlfWbROqFDob +CRDEc6yiVmmuiYo3a0v6ASoVJuhvgKeJ7xxF2JQxC+fDz8qyFSTSmUVWkqdsxLNd +G60Q5pImq8vsYiHvEg6J +=AtMz +-----END PGP SIGNATURE----- + +--------------enig47B3F63504D3ABAB3C58C63F-- diff --git a/spec/helpers/message_spec.rb b/spec/helpers/message_spec.rb new file mode 100644 index 0000000..430c03d --- /dev/null +++ b/spec/helpers/message_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper.rb' +require 'message.rb' +describe Mail::Message do + it "should recognize signatures" do + mails_dir = "#{RAILS_ROOT}/spec/files" + mail_files = ["valid-signed-thun-01.eml", "invaild-signed-thun-01.eml", + "valid-signed-mutt-01.eml", "valid-signed-mutt-02.eml", + "valid-signed-mac-01.eml", "invalid-signed-mutt-01.eml", + "invalid-signed-mutt-02.eml", "invalid-signed-mac-01.eml"] + for mail_file in mail_files + mail = Mail.read("#{mails_dir}/#{mail_file}") + mail.signatures.length.should == 1 + mail.signatures.first.match(/signature/).should_not be_nil + end + end + + it "should recognize unsigned messages" do + mails_dir = "#{RAILS_ROOT}/spec/files" + mail_files = ["unsigned-gmail-01.eml", + "unsigned-thunderbird-w-atachment-01.eml", + "unsigned-thunderbird-w-atachment-02.eml"] + + for mail_file in mail_files + mail = Mail.read("#{mails_dir}/#{mail_file}") + mail.signatures.should == [] + end + end +end diff --git a/spec/models/receiver_spec.rb b/spec/models/receiver_spec.rb new file mode 100644 index 0000000..7c94b09 --- /dev/null +++ b/spec/models/receiver_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper.rb' +describe Receiver do + include EmailSpec::Helpers + include EmailSpec::Matchers + + it "should pass received emails to EmailAnswer#answer_from_email" do + mail = "Some text" + EmailAnswer.should_receive(:answer_from_email) + Receiver.receive(mail.to_s) + end +end diff --git a/spec/models/user_mailer_spec.rb b/spec/models/user_mailer_spec.rb index 9c205cd..4e7c613 100644 --- a/spec/models/user_mailer_spec.rb +++ b/spec/models/user_mailer_spec.rb @@ -66,10 +66,4 @@ describe UserMailer do # don't test rest of the message notification.should have_text(/If you are answering question check if your message has proper subject./) end - - it "should pass received emails to EmailAnswer#answer_from_email" do - mail = TMail::Mail.new - EmailAnswer.should_receive(:answer_from_email) - UserMailer.receive(mail.to_s) - end end |