diff options
author | Mark Longair <mark@mysociety.org> | 2013-05-16 15:10:54 +0100 |
---|---|---|
committer | Mark Longair <mhl@pobox.com> | 2013-05-16 18:18:05 +0100 |
commit | ac2d5ed7f249fe5bef5601b4a60141fa79095558 (patch) | |
tree | 2dd93f2b93cb8e50b1f040faa473ab5272822a18 | |
parent | 97d5046613b474c49e97cd108b874ac0e0c3f4cf (diff) |
Avoid an FoiAttachment validation failure under Rails 3
Under Rails 3, the uudecoded FoiAttachment in this test
fails validation at the self.save! in
IncomingMessage.parse_raw_email, although the FoiAttachment
has been correctly created and saved to the database in
_uudecode_and_save_attachments. Forcing a reload=true on
self.foi_attachments fixes this.
Thanks to Louise Crow for finding the fix for this problem.
-rw-r--r-- | app/models/incoming_message.rb | 1 | ||||
-rw-r--r-- | spec/fixtures/files/inline-uuencode.email | 27 | ||||
-rw-r--r-- | spec/models/incoming_message_spec.rb | 11 |
3 files changed, 39 insertions, 0 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 7585768e8..64afe6e3e 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -131,6 +131,7 @@ class IncomingMessage < ActiveRecord::Base end self.valid_to_reply_to = self._calculate_valid_to_reply_to self.last_parsed = Time.now + self.foi_attachments reload=true self.save! end end diff --git a/spec/fixtures/files/inline-uuencode.email b/spec/fixtures/files/inline-uuencode.email new file mode 100644 index 000000000..3134ba3ad --- /dev/null +++ b/spec/fixtures/files/inline-uuencode.email @@ -0,0 +1,27 @@ +From foo@bar Mon Jun 01 17:14:44 2009 +Return-path: <foo@bar> +Envelope-to: foi@quux +Delivery-date: Mon, 01 Jun 2009 17:14:44 +0100 +From: <foo@bar> +To: <request-whatever@quux> +Subject: something or other +Date: Mon, 1 Jun 2009 17:14:37 +0100 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.181 +Message-ID: <baz@xyzzy> + +Thanks for your email - here's a truncated attachment +for you: + +********************************************************************** + +begin 666 ResponseT7363 9.doc +MT,\1X*&Q&N$`````````````````````/@`#`/[_"0`&```````````````" +M````) ``````````$ ``+@````$```#^____`````",```!L````________ +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +#```` +` +end + +The original of this email was scanned for viruses or something +like that. diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index b97ee3ca8..1d86c26ad 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -419,6 +419,17 @@ describe IncomingMessage, " when uudecoding bad messages" do im.get_attachments_for_display.size.should == 1 end + it "should still work when parsed from the raw email" do + raw_email = load_file_fixture 'inline-uuencode.email' + mail = MailHandler.mail_from_raw_email(raw_email) + im = incoming_messages :useless_incoming_message + im.stub!(:raw_email).and_return(raw_email) + im.stub!(:mail).and_return(mail) + im.parse_raw_email! + attachments = im.foi_attachments + attachments.size.should == 2 + end + it "should apply censor rules" do mail = get_fixture_mail('incoming-request-bad-uuencoding.email') |