aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api_controller_spec.rb3
-rw-r--r--spec/controllers/general_controller_spec.rb16
-rw-r--r--spec/controllers/public_body_controller_spec.rb1
-rw-r--r--spec/fixtures/files/lotus-notes-quoting.email112
-rw-r--r--spec/fixtures/files/no-part-charset-bad-utf8.email38
-rw-r--r--spec/fixtures/files/space-boundary.email37
-rw-r--r--spec/models/incoming_message_spec.rb38
7 files changed, 237 insertions, 8 deletions
diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb
index ded9a040a..8d8a39950 100644
--- a/spec/controllers/api_controller_spec.rb
+++ b/spec/controllers/api_controller_spec.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
def normalise_whitespace(s)
@@ -167,7 +168,7 @@ describe ApiController, "when using the API" do
OutgoingMessage.count.should == n_outgoing_messages
end
- it "should not allow other people’s requests to be updated" do
+ it "should not allow other people's requests to be updated" do
request_id = _create_request
n_incoming_messages = IncomingMessage.count
n_outgoing_messages = OutgoingMessage.count
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index de8dd8422..cebcaf6ab 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -17,6 +17,22 @@ describe GeneralController, "when trying to show the blog" do
end
end
+describe GeneralController, 'when getting the blog feed' do
+
+ it 'should add a lang param correctly to a url with no querystring' do
+ Configuration.stub!(:blog_feed).and_return("http://blog.example.com")
+ get :blog
+ assigns[:feed_url].should == "http://blog.example.com?lang=en"
+ end
+
+ it 'should add a lang param correctly to a url with an existing querystring' do
+ Configuration.stub!(:blog_feed).and_return("http://blog.example.com?alt=rss")
+ get :blog
+ assigns[:feed_url].should == "http://blog.example.com?alt=rss&lang=en"
+ end
+
+end
+
describe GeneralController, "when searching" do
integrate_views
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 9eca43aee..d12818a1c 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe PublicBodyController, "when showing a body" do
diff --git a/spec/fixtures/files/lotus-notes-quoting.email b/spec/fixtures/files/lotus-notes-quoting.email
new file mode 100644
index 000000000..863a2dfef
--- /dev/null
+++ b/spec/fixtures/files/lotus-notes-quoting.email
@@ -0,0 +1,112 @@
+From foi@example.com Thu Mar 06 17:28:24 2008
+To: FOI Person <EMAIL_TO>
+Subject: Re: Freedom of Information request
+MIME-Version: 1.0
+X-Mailer: Lotus Notes Release 6.5.6 March 06, 2007
+From: foi <foi@example.com>
+Date: Thu, 6 Mar 2008 17:31:51 +0000
+Content-Type: multipart/alternative; boundary="=_alternative 005FFC2E80257404_="
+
+This is a multipart message in MIME format.
+--=_alternative 005FFC2E80257404_=
+Content-Type: text/plain; charset="ISO-8859-1"
+Content-Transfer-Encoding: quoted-printable
+
+Dear Requester,
+
+Some text.
+
+Yours sincerely
+
+
+FOI Team
+
+
+
+Bob Smith <request-xx-xxxxx@whatdotheyknow.com>=20
+Sent by: Bob Smith <request-xx-xxxxx@whatdotheyknow.com>
+06/03/08 10:00
+Please respond to
+Bob Smith <request-xx-xxxxx@whatdotheyknow.com>
+
+
+To
+FOI requests <foi@example.com>
+cc
+
+Subject
+Freedom of Information request
+
+
+
+
+
+
+ Original text
+
+
+
+
+--=_alternative 005FFC2E80257404_=
+Content-Type: text/html; charset="ISO-8859-1"
+Content-Transfer-Encoding: quoted-printable
+
+
+<div>
+<br><font size=3D2 face=3D"Arial">Dear Requester,</font>
+<br>
+<br><font size=3D2 face=3D"Arial">Some text. </font>
+<br>
+<br><font size=3D2 face=3D"Arial">Yours sincerely</font>
+<br>
+<br>
+<div>
+<br><font size=3D2 face=3D"Arial">FOI Team</font>
+<p>
+<br>
+<br>
+<table width=3D100%>
+<tr valign=3Dtop>
+<td width=3D40%><font size=3D1 face=3D"sans-serif"><b>Bob Smith &lt;re=
+quest-xx-xxxxx@whatdotheyknow.com&gt;</b>
+</font>
+<br><font size=3D1 face=3D"sans-serif">Sent by: Bob Smith &lt;request-=
+bounce-xx-xxxxx@whatdotheyknow.com&gt;</font>
+<p><font size=3D1 face=3D"sans-serif">06/03/08 10:00</font>
+<table border>
+<tr valign=3Dtop>
+<td bgcolor=3Dwhite>
+<div align=3Dcenter><font size=3D1 face=3D"sans-serif">Please respond to<br>
+Bob Smith &lt;request-xx-xxxxx@whatdotheyknow.com&gt;</font></div><=
+/table>
+<br>
+<td width=3D59%>
+<table width=3D100%>
+<tr valign=3Dtop>
+<td>
+<div align=3Dright><font size=3D1 face=3D"sans-serif">To</font></div>
+<td><font size=3D1 face=3D"sans-serif">FOI requests
+&lt;foi@example.com&gt;</font>
+<tr valign=3Dtop>
+<td>
+<div align=3Dright><font size=3D1 face=3D"sans-serif">cc</font></div>
+<td>
+<tr valign=3Dtop>
+<td>
+<div align=3Dright><font size=3D1 face=3D"sans-serif">Subject</font></div>
+<td><font size=3D1 face=3D"sans-serif">Freedom of Information request</font></table>
+<br>
+<table>
+<tr valign=3Dtop>
+<td>
+<td></table>
+<br></table>
+<br>
+<br>
+<br><tt><font size=3D2>&nbsp; &nbsp; &nbsp;Original text<br>
+<br>
+<br>
+</font></tt>
+<br></div></div></div>
+--=_alternative 005FFC2E80257404_=--
+
diff --git a/spec/fixtures/files/no-part-charset-bad-utf8.email b/spec/fixtures/files/no-part-charset-bad-utf8.email
new file mode 100644
index 000000000..7e67d0063
--- /dev/null
+++ b/spec/fixtures/files/no-part-charset-bad-utf8.email
@@ -0,0 +1,38 @@
+From xxxx@yahoo.cn Mon Oct 08 14:01:34 2012
+Return-path: <xxxx@yahoo.cn>
+Envelope-to: foi@atlas.ukcod.org.uk
+Delivery-date: Mon, 08 Oct 2012 14:01:34 +0100
+Received: (qmail 63864 invoked from network); 8 Oct 2012 13:01:12 -0000
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.cn; s=s1024; t=1349701272; bh=T/mtlIYvhB/L5RO+CvTazeAdGf1n1zsGXBoA8EKGT9M=; h=Message-ID:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:X-mailer:From:Subject:To:Content-Transfer-Encoding:Content-Type:Date; b=LYI/PXvA7DA746bmyprChUg7N8YDvN9XE/bhfTt5MW7siOmxHHzn1w+s5X33PvLI0x0UfJLo+MCkTnGPKnG5BYY38US8PkocJYyphrvF/eaUl3ALf8UvxHBOJX1iIi89Xp2NnfbS8lz9kZAWifb9GOnOA5/kLDcL5/WJXliit2k=
+Message-ID: <xxxx@xxxx.yahoo.com>
+X-Yahoo-Newman-Property: ymail-5
+X-YMail-OSG: nPs5jgsVM1myUoKjeEPTxxalz4BM6BZMEUYu.E8NPMPQyo_
+ Yej8T2WCTurn767NOwhuDIqNxC2QGZINqfjmKcdyW7a1P_Zxqr9GsjgxODci
+ ihwr7qYAGDDbcsrB.PX4epnJZHl3yAwoGW.1ReEZnXQANFcNep7.zNEbZ_2k
+ RU1IhI9aHYvxPxt5RWugwOoFRh9P8Ym35A88IMazNtVaBiBEXF6Vk8Aqr9XP
+ 3Vh9xOT9Pn6X8qOUjNXkdb3xB4S5AAIRSE9mqhL1KzHBwdVQs25IoM_2FV2b
+ gPsQGgL4_mwBH0WcEMhdj7Kn6Nfb44L.50E_V3DH.8P7KzDK8zNVXSbAqohX
+ Qi6MzUK2frr8IyZyYzHb.ekff7kAcJgUoHvhnyPar8tRYxhQT3_xsUTzsx8N
+ oWckVPh_i3OT7U4ObgekqgtteMoYqPH2eF1SZXamGBAs-
+X-Yahoo-SMTP: YUQHwRWswBDjbw_M.D6EP4KpT9khlJErDRBQi4ySZQ--
+X-mailer: MIME::Lite 3.027 (F2.74; T1.31; A2.07; B3.13; Q3.13)
+From: =?GB2312?B?zsJKaWFu?= Bing <xxxx@yahoo.cn>
+Subject: =?GB2312?B?yM7A1svJ?=
+To: FOI Person <EMAIL_TO>
+Content-Transfer-Encoding: base64
+Content-Type: text/plain
+Date: Tue, 9 Oct 2012 20:53:06 +0800
+
+DQogICAgICAgICAgufO5q8u+uLrU8MjLKL6twO0vssbO8SnE+rrDo7oNCiAgICAgICAgICAgILG+
+uavLvtTaMTk5N8Tqs8nBorn6vNK5pMnM16Ky4S7KtcGm0Nu68aGj09C2wMGiy7DO8Q0KICAgICAg
+ICAgINeo0rXIy9SxO9TayKu5+rj3s8fK0MnowaK31rmry76jqNXjva2hosnPuqOhornj1t2hor2t
+y9W1yA0KICAgICAgICAgILXYt72jqdLyvfjP7r3PtuDP1s3qs8myu8HLw7/Uws/6ytu27rbIoaPD
+v9TC09DSu7K/t9YNCiAgICAgICAgICDU9ta1tpCjqDYtNyXX89PSKbrNxtXGsaOoMC41JS0yJSDX
+89PSo6nTxbvdtPq/qrvyus/X96OsDQogICAgICAgICAgtePK/b3Ptc2ho7T6wO23ts6nyOfPwqO6
+DQogICAgICAgICAg1PbWtcuwOjEuMTcl16jTw9T21rWjuzI6xtXNqNT21rWjuzM6uqO52MBVv+6V
++CANCiAgICAgICAgICAgNC65+suwzajTw7v6tPI7IDUutdjLsM2o08O7+rTyDQogICAgICAgICAg
+ICAgPT09Pdaj1tiz0MW1PT09PSANCiAgICAgICAgICDGsb7dvvnOqraQhNW+1sHss/a78tPJxvPS
+tdaxvdO/qrP2o6zR6dakuvO4tr/uoaMNCiAgICAgICAgICAgICAgIMGqIMLnIDq7xr6twO0gICAg
+ICAgICAgICAgyMjP3zoxMzgtMjQzNi0wNTE1DQogICAgICAgICAgICDStc7xUVE6OTc4My05Njg5
+OCAgIEUtbWFpbDp3d3dheDg4QDEyNi5jb20NCg==
+
diff --git a/spec/fixtures/files/space-boundary.email b/spec/fixtures/files/space-boundary.email
new file mode 100644
index 000000000..37d65dbb5
--- /dev/null
+++ b/spec/fixtures/files/space-boundary.email
@@ -0,0 +1,37 @@
+From responder@example.com Wed Sep 03 10:44:18 2008
+Return-path: <responder@example.com>
+Envelope-to: foi@sandwich.ukcod.org.uk
+Delivery-date: Wed, 03 Sep 2008 10:44:18 +0100
+X-MimeOLE: Produced By Microsoft Exchange V6.5
+Content-class: urn:content-classes:message
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary=
+ "----_=_NextPart_001_01C90DA9.9B158D0D"
+Subject: A subject
+Date: Wed, 3 Sep 2008 10:44:05 +0100
+Message-ID: <D403C5D38B9BD6468928738951034DDE85A457@aglnex02.attorneygeneral.gsi.gov.uk>
+X-MS-Has-Attach: yes
+X-MS-TNEF-Correlator:
+Thread-Topic: Freedom of Information request - An information request about
+ stuff
+Thread-Index: AckNqOAr459KZB17Q1OIy1jxNVd9xAAAAnVAAAAWJ+A=
+From: "A responder" <responder@example.com>
+To: FOI Person <EMAIL_TO>
+
+This is a multi-part message in MIME format.
+
+------_=_NextPart_001_01C90DA9.9B158D0D
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: quoted-printable
+
+=20Apologies.=20Herewith.
+
+------_=_NextPart_001_01C90DA9.9B158D0D
+Content-Type: application/octet-stream; name="Mr Gradwick.pdf"
+Content-Transfer-Encoding: base64
+Content-Description: Mr Gradwick.pdf
+Content-Disposition: attachment; filename="Mr Gradwick.pdf"
+
+xxx
+
+------_=_NextPart_001_01C90DA9.9B158D0D--
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index 03a3c8dc3..69a5da0e9 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -12,6 +12,14 @@ describe IncomingMessage, " when dealing with incoming mail" do
ActionMailer::Base.deliveries.clear
end
+ it 'should correctly parse multipart mails with a linebreak in the boundary marker' do
+ ir = info_requests(:fancy_dog_request)
+ receive_incoming_mail('space-boundary.email', ir.incoming_email)
+ message = ir.incoming_messages[1]
+ message.mail.parts.size.should == 2
+ message.mail.multipart?.should == true
+ end
+
it "should return the mail Date header date for sent at" do
@im.parse_raw_email!(true)
@im.reload
@@ -56,6 +64,14 @@ describe IncomingMessage, " when dealing with incoming mail" do
message.subject.should == "Câmara Responde: Banco de ideias"
end
+ it 'should not error on display of a message which has no charset set on the body part and
+ is not good utf-8' do
+ ir = info_requests(:fancy_dog_request)
+ receive_incoming_mail('no-part-charset-bad-utf8.email', ir.incoming_email)
+ message = ir.incoming_messages[1]
+ message.parse_raw_email!
+ message.get_main_body_text_internal.should include("The above text was badly encoded")
+ end
it "should fold multiline sections" do
{
@@ -77,6 +93,7 @@ describe IncomingMessage, "when parsing HTML mail" do
plain_text = IncomingMessage._get_attachment_text_internal_one_file('text/html', html)
plain_text.should match(/është/)
end
+
end
describe IncomingMessage, "when getting the attachment text" do
@@ -115,16 +132,23 @@ end
describe IncomingMessage, " folding quoted parts of emails" do
- it "cope with [ in user names properly" do
- @user = mock_model(User)
- @user.stub!(:name).and_return("Sir [ Bobble")
- @info_request = mock_model(InfoRequest)
- @info_request.stub!(:user).and_return(@user)
- @info_request.stub!(:user_name).and_return(@user.name)
+ it 'should fold an example lotus notes quoted part converted from HTML correctly' do
+ ir = info_requests(:fancy_dog_request)
+ receive_incoming_mail('lotus-notes-quoting.email', ir.incoming_email)
+ message = ir.incoming_messages[1]
+ message.get_main_body_text_folded.should match(/FOLDED_QUOTED_SECTION/)
+ end
+ it 'should fold a plain text lotus notes quoted part correctly' do
+ text = "FOI Team\n\n\nInfo Requester <xxx@whatdotheyknow.com>=20\nSent by: Info Requester <request-bounce-xxxxx@whatdotheyknow.com>\n06/03/08 10:00\nPlease respond to\nInfo Requester <request-xxxx@whatdotheyknow.com>"
@incoming_message = IncomingMessage.new()
- @incoming_message.info_request = @info_request
+ @incoming_message.stub_chain(:info_request, :user_name).and_return("Info Requester")
+ @incoming_message.remove_lotus_quoting(text).should match(/FOLDED_QUOTED_SECTION/)
+ end
+ it "cope with [ in user names properly" do
+ @incoming_message = IncomingMessage.new()
+ @incoming_message.stub_chain(:info_request, :user_name).and_return("Sir [ Bobble")
# this gives a warning if [ is in the name
text = @incoming_message.remove_lotus_quoting("Sir [ Bobble \nSent by: \n")
text.should == "\n\nFOLDED_QUOTED_SECTION"