diff options
author | Francis Irving <francis@mysociety.org> | 2009-12-02 23:05:26 +0000 |
---|---|---|
committer | Francis Irving <francis@mysociety.org> | 2009-12-02 23:05:26 +0000 |
commit | dfe62a251903f49bc7c1fee68efff1511b12e374 (patch) | |
tree | 86f12f3ccbf3e32a955ce3da50c3d590a39d9548 | |
parent | c4868ded72b339265c9b2c3114efb97dcfa1db77 (diff) |
Test for TMail fix for a particular message. Monkey patch doesn't quite
work yet.
-rw-r--r-- | lib/tmail_extensions.rb | 25 | ||||
-rw-r--r-- | spec/fixtures/humberside-police-odd-mime-type.email | 144 | ||||
-rw-r--r-- | spec/libs/tmail_extensions.rb | 20 |
3 files changed, 189 insertions, 0 deletions
diff --git a/lib/tmail_extensions.rb b/lib/tmail_extensions.rb index 6e214df0e..89f5a7df3 100644 --- a/lib/tmail_extensions.rb +++ b/lib/tmail_extensions.rb @@ -6,6 +6,9 @@ # # $Id: tmail_extensions.rb,v 1.7 2009-10-02 23:31:01 francis Exp $ +require 'tmail' +require 'tmail/interface' + # Monkeypatch! # These mainly used in app/models/incoming_message.rb @@ -35,6 +38,28 @@ module TMail val = self.header_string('envelope-to') return val ? [val,] : [] end + + # Bug fix to this function - is for message in humberside-police-odd-mime-type.email + # Which was originally: https://secure.mysociety.org/admin/foi/request/show_raw_email/11209 + # See test in spec/lib/tmail_extensions.rb + def set_content_type( str, sub = nil, param = nil ) + if sub + main, sub = str, sub + else + main, sub = str.split(%r</>, 2) + raise ArgumentError, "sub type missing: #{str.inspect}" unless sub + end + if h = @header['content-type'] + h.main_type = main + h.sub_type = sub + h.params.clear # if !h.params.nil? # XXX this if statement is the fix # XXX disabled until works with test + else + store 'Content-Type', "#{main}/#{sub}" + end + @header['content-type'].params.replace param if param + str + end + end class Address diff --git a/spec/fixtures/humberside-police-odd-mime-type.email b/spec/fixtures/humberside-police-odd-mime-type.email new file mode 100644 index 000000000..5514b29da --- /dev/null +++ b/spec/fixtures/humberside-police-odd-mime-type.email @@ -0,0 +1,144 @@ +From MAILER-DAEMON Thu Jan 01 15:56:20 2009 +Return-path: <> +Envelope-to: request-5335-xxxxxxxx@whatdotheyknow.com +Delivery-date: Thu, 01 Jan 2009 15:56:20 +0000 +Received: from earth.karoo.kcom.com ([212.50.160.55]:62894) + by sandwich.ukcod.org.uk with esmtp (Exim 4.63) + id 1LIPuG-0004AJ-B3 + for request-5335-xxxxxxxx@whatdotheyknow.com; Thu, 01 Jan 2009 15:56:20 +0000 +Received: from unknown (HELO smtp-in.karoo.kcom.com) ([10.102.8.11]) + by earth.karoo.kcom.com with ESMTP; 01 Jan 2009 15:44:42 +0000 +Received: from exim by smtp-in.karoo.kcom.comwith local (Exim 4.30) + id 1LIPu0-0004fg-G6 server-id smtp-in4 + for request-5335-xxxxxxxx@whatdotheyknow.com; Thu, 01 Jan 2009 15:56:04 +0000 +X-Failed-Recipients: clerk@humberside-pa.karoo.co.uk +Reply-To: Postmaster <postmaster@karoo.kcom.com> +Auto-Submitted: auto-generated +From: Mail Delivery System <Mailer-Daemon@karoo.co.uk> +To: request-5335-xxxxxxxx@whatdotheyknow.com +Subject: Mail delivery failed : returning message to sender +X-Mailer: Karoo Mailcore [version 2.0-IB] +MIME-Version: 1.0 +Content-Type: Multipart/Mixed; + boundary="------------Boundary-00=_8OOXGBH86T9O9BSG6K29" +Message-Id: <E1LIPu0-0004fg-G6@smtp-in.karoo.kcom.com> +Date: Thu, 01 Jan 2009 15:56:04 +0000 + + +--------------Boundary-00=_8OOXGBH86T9O9BSG6K29 +Content-Type: text/plain; + charset="iso-8859-1" +Content-Transfer-Encoding: 8bit +Subject: Mail delivery failed : returning message to sender + + +This message was created automatically by mail delivery software. + +A message that you sent could not be delivered to all of its recipients. +The following address(es) failed: + + clerk@humberside-pa.karoo.co.uk + Unrouteable address + + +A Copy of the E-mail Has been Attached +--------------Boundary-00=_8OOXGBH86T9O9BSG6K29 +Content-Type: message/rfc822; + charset="iso-8859-1"; + name="1LIPu0-0004fc-FM"; + subject=" + +Content-Transfer-Encoding: 8bit + +Return-path: <request-5335-xxxxxxxx@whatdotheyknow.com> +Received: from [212.50.160.60] (helo=venus.karoo.kcom.com) + by smtp-in.karoo.kcom.comwith esmtp (Exim 4.30) + id 1LIPu0-0004fc-FM server-id smtp-in4 + for clerk@humberside-pa.karoo.co.uk; Thu, 01 Jan 2009 15:56:04 +0000 +X-IronPort-Anti-Spam-Filtered: true +X-IronPort-Anti-Spam-Result: AnECAF9nXElSb+bUmWdsb2JhbACMZQGHFQEBAQEBCAsKBxG2eIVy +X-IronPort-AV: E=Sophos;i="4.36,313,1228089600"; + d="scan'208";a="465483300" +Received: from sandwich.ukcod.org.uk ([82.111.230.212]) + by venus.karoo.kcom.com with ESMTP; 01 Jan 2009 15:46:44 +0000 +Received: from foi by sandwich.ukcod.org.uk with local (Exim 4.63) + (envelope-from <request-5335-xxxxxxxx@whatdotheyknow.com>) + id 1LIPtz-0004AG-OC + for clerk@humberside-pa.karoo.co.uk; Thu, 01 Jan 2009 15:56:03 +0000 +From: John Jarman <request-5335-xxxxxxxx@whatdotheyknow.com> +To: FOI requests at Humberside Police Authority <clerk@humberside-pa.karoo.co.uk> +Subject: Freedom of Information request - Police Injury Award Pensions +Mime-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Message-Id: <E1LIPtz-0004AG-OC@sandwich.ukcod.org.uk> +Date: Thu, 01 Jan 2009 15:56:03 +0000 + + Dear Humberside Police Authority, + + I am making a request for all the information to which I am + entitled under the Freedom Of Information Act. In order to assist + you with this request, I am outlining my query as specifically as + possible. If however this request is too wide or too unclear, I + would be grateful if you could contact me by e-mail, as I + understand that under the act, you are required to advise and + assist requesters. + + I would like to know: + + 1) How many former officers of the Humberside Police force are + currently in receipt of an injury award pension, as provided for in + the Police Pensions Regulations 1987 and the Police (Injury + Benefit) Regulations 2006? + + 2) Do you operate a policy of reducing an injury award pension to + the lowest permissible band when the former officer reaches the age + of 65? + + 3) In the years 2004 to 2008 inclusive, how many former officers’ + injury award pensions were reduced to the lowest banding upon the + former officer reaching the age of 65? (A total figure only is + requested, but I have no objection if you break the figures down by + year) + + 4) In the years 1987 to 2003 inclusive, how many former officers’ + injury award pensions were reduced to the lowest banding upon the + former officer reaching the age of 65? (A total figure only is + requested, but I have no objection if you break the figures down by + year) + + 5) In the years 2004 to 2008 inclusive, how many formal complaints + have been made against officers of ACPO rank in the Humberside + Police force regarding matters in any way connected with the + administration of reviews of police injury awards? (A total figure + only is requested, but I have no objection if you break the figures + down by year) + + I understand that under the FOI Act, I should be entitled to a + response within 20 working days. I look forward to hearing from you + in the near future. + + Please note that your full reply to the above questions should be + sent by e-mail to the return address shown in the heading to this + message. This is because both the request and its response are + published for public scrutiny on the web site through which this + request has been made. + + Thank you for your assistance in this matter. + + Mr. John Jarman + + ------------------------------------------------------------------- + Disclaimer: This message and any reply that you make will be + published on the internet. Our privacy and copyright policies: + http://www.whatdotheyknow.com/help/about#officers + + Is clerk@humberside-pa.karoo.co.uk the wrong address for Freedom of + Information requests to Humberside Police Authority ? If so please + contact us using this form: + http://www.whatdotheyknow.com/help/contact + ------------------------------------------------------------------- + + +--------------Boundary-00=_8OOXGBH86T9O9BSG6K29-- + + diff --git a/spec/libs/tmail_extensions.rb b/spec/libs/tmail_extensions.rb new file mode 100644 index 000000000..7b9e1b495 --- /dev/null +++ b/spec/libs/tmail_extensions.rb @@ -0,0 +1,20 @@ +# This is a test of the monkey patches in lib/fcgi_fixes.rb + +require File.dirname(__FILE__) + '/../spec_helper' + +describe "when using TMail" do + + it "should load an email with funny MIME settings" do + # just send it to the holding pen + InfoRequest.holding_pen_request.incoming_messages.size.should == 0 + receive_incoming_mail("humberside-police-odd-mime-type.email", 'dummy') + InfoRequest.holding_pen_request.incoming_messages.size.should == 1 + + incoming_message = InfoRequest.holding_pen_request.incoming_messages[0] + + # This will raise an error if the bug in TMail hasn't been fixed + incoming_message.get_body_for_html_display() + end + +end + |