From ca7bb3d9f7f7e38ca670dee4352a6c81e2b9d19a Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 11:07:48 +0000 Subject: Move TMail monkey patch to MailHandler Tmail backend. --- spec/lib/mail_handler/mail_handler_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 spec/lib/mail_handler/mail_handler_spec.rb (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb new file mode 100644 index 000000000..fa29132bc --- /dev/null +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -0,0 +1,16 @@ +# coding: utf-8 +require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper') + +def get_fixture_mail(filename) + MailHandler.mail_from_raw_email(load_file_fixture(filename)) +end + +describe 'when creating a mail object from raw data' do + + it 'should correctly parse a multipart email with a linebreak in the boundary' do + mail = get_fixture_mail('space-boundary.email') + mail.parts.size.should == 2 + mail.multipart?.should == true + end + +end -- cgit v1.2.3 From 23e99ffb72361161ef8cff4d0d79efca83326c80 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 12:09:25 +0000 Subject: Factor out method for getting a mail object from a fixture file. --- spec/lib/mail_handler/mail_handler_spec.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index fa29132bc..fc29817f6 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -1,10 +1,6 @@ # coding: utf-8 require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper') -def get_fixture_mail(filename) - MailHandler.mail_from_raw_email(load_file_fixture(filename)) -end - describe 'when creating a mail object from raw data' do it 'should correctly parse a multipart email with a linebreak in the boundary' do -- cgit v1.2.3 From 4bdab94e9d4f0a64647e5f8534c1fea8b4ba2809 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 15 Nov 2012 14:04:55 +0000 Subject: Move TMail extensions to mail handler. --- spec/lib/mail_handler/mail_handler_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index fc29817f6..a3fba0698 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -9,4 +9,15 @@ describe 'when creating a mail object from raw data' do mail.multipart?.should == true end + it 'should parse multiple to addresses with unqoted display names' do + mail = get_fixture_mail('multiple-unquoted-display-names.email') + mail.to.should == ["request-66666-caa77777@whatdotheyknow.com", "foi@example.com"] + end + + it 'should convert an iso8859 email to utf8' do + mail = get_fixture_mail('iso8859_2_raw_email.email') + mail.subject.should have_text(/gjatë/u) + mail.body.is_utf8?.should == true + end + end -- cgit v1.2.3 From 826c5ed18300ae4f42dfbf5777d8c43243b8be11 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 3 Dec 2012 18:49:56 +0000 Subject: Use get_part_body in spec. --- spec/lib/mail_handler/mail_handler_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index a3fba0698..6213d3fdf 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -17,7 +17,7 @@ describe 'when creating a mail object from raw data' do it 'should convert an iso8859 email to utf8' do mail = get_fixture_mail('iso8859_2_raw_email.email') mail.subject.should have_text(/gjatë/u) - mail.body.is_utf8?.should == true + MailHandler.get_part_body(mail).is_utf8?.should == true end end -- cgit v1.2.3 From 9a8ae037e904a47817e5469f03146195d22016b9 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 3 Dec 2012 18:50:34 +0000 Subject: Add specs for the mail handler getting the from name and from address from an email. --- spec/lib/mail_handler/mail_handler_spec.rb | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index 6213d3fdf..805fd6800 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -21,3 +21,59 @@ describe 'when creating a mail object from raw data' do end end + +describe 'when asked for the from name' do + + it 'should return nil if there is a blank "From" field' do + mail_data = load_file_fixture('incoming-request-plain.email') + mail_data.gsub!('EMAIL_FROM', '') + mail = MailHandler.mail_from_raw_email(mail_data) + MailHandler.get_from_name(mail).should == nil + end + + it 'should correctly return an encoded name from the from field' do + mail = get_fixture_mail('quoted-subject-iso8859-1.email') + MailHandler.get_from_name(mail).should == 'Coordenação de Relacionamento, Pesquisa e Informação/CEDI' + end + + it 'should get a name from a "From" field with a name and address' do + mail = get_fixture_mail('incoming-request-oft-attachments.email') + MailHandler.get_from_name(mail).should == 'Public Authority' + end + + it 'should return nil from a "From" field that is just a name'do + mail = get_fixture_mail('track-response-webshield-bounce.email') + MailHandler.get_from_name(mail).should == nil + end + +end + +describe 'when asked for the from address' do + + it 'should return nil if there is a blank "From" field' do + mail_data = load_file_fixture('incoming-request-plain.email') + mail_data.gsub!('EMAIL_FROM', '') + mail = MailHandler.mail_from_raw_email(mail_data) + MailHandler.get_from_address(mail).should == nil + end + + it 'should correctly return an address from a mail that has an encoded name in the from field' do + mail = get_fixture_mail('quoted-subject-iso8859-1.email') + MailHandler.get_from_address(mail).should == 'geraldinequango@localhost' + end + + it 'should return nil if there is no address in the "From" field' do + mail = get_fixture_mail('track-response-webshield-bounce.email') + MailHandler.get_from_address(mail).should == nil + end + + it 'should return the "From" email address if there is one' do + mail = get_fixture_mail('track-response-abcmail-oof.email') + MailHandler.get_from_address(mail).should == 'Name.Removed@example.gov.uk' + end + + it 'should get an address from a "From" field with a name and address' do + mail = get_fixture_mail('incoming-request-oft-attachments.email') + MailHandler.get_from_address(mail).should == 'public@authority.gov.uk' + end +end -- cgit v1.2.3 From 9dfe9de140242c176eef8af65d78ced3f2992cc1 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 4 Dec 2012 09:53:16 +0000 Subject: Move method for getting the to, cc and envelope-to addresses of a mail to the mail handler. --- spec/lib/mail_handler/mail_handler_spec.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index 805fd6800..4603b695f 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -77,3 +77,32 @@ describe 'when asked for the from address' do MailHandler.get_from_address(mail).should == 'public@authority.gov.uk' end end + +describe 'when asked for all the addresses a mail has been sent to' do + + it 'should return an array containing the envelope-to address and the to address, and the cc address if there is one' do + mail_data = load_file_fixture('humberside-police-odd-mime-type.email') + mail_data.gsub!('Envelope-to: request-5335-xxxxxxxx@whatdotheyknow.com', + 'Envelope-to: request-5555-xxxxxxxx@whatdotheyknow.com') + mail_data.gsub!('Cc: request-5335-xxxxxxxx@whatdotheyknow.com', + 'Cc: request-3333-xxxxxxxx@whatdotheyknow.com') + mail = MailHandler.mail_from_raw_email(mail_data) + MailHandler.get_all_addresses(mail).should == ['request-5335-xxxxxxxx@whatdotheyknow.com', + 'request-3333-xxxxxxxx@whatdotheyknow.com', + 'request-5555-xxxxxxxx@whatdotheyknow.com'] + end + + it 'should only return unique values' do + # envelope-to and to fields are the same + mail = get_fixture_mail('humberside-police-odd-mime-type.email') + MailHandler.get_all_addresses(mail).should == ['request-5335-xxxxxxxx@whatdotheyknow.com'] + end + + it 'should handle the absence of an envelope-to or cc field' do + mail_data = load_file_fixture('autoresponse-header.email') + mail_data.gsub!('To: FOI Person ', + 'To: FOI Person ') + mail = MailHandler.mail_from_raw_email(mail_data) + MailHandler.get_all_addresses(mail).should == ["request-5555-xxxxxxxx@whatdotheyknow.com"] + end +end -- cgit v1.2.3 From 6052df14bab5fe82cd5ccf1979dbfc6d6ab3befa Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 4 Dec 2012 10:35:22 +0000 Subject: Add methods for finding out if there is an empty return path on a mail and getting the auto-submitted field. --- spec/lib/mail_handler/mail_handler_spec.rb | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index 4603b695f..e673c5bf0 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -106,3 +106,35 @@ describe 'when asked for all the addresses a mail has been sent to' do MailHandler.get_all_addresses(mail).should == ["request-5555-xxxxxxxx@whatdotheyknow.com"] end end + +describe 'when asked for auto_submitted' do + + it 'should return a string value for an email with an auto-submitted header' do + mail = get_fixture_mail('autoresponse-header.email') + MailHandler.get_auto_submitted(mail).should == 'auto-replied' + end + + it 'should return a nil value for an email with no auto-submitted header' do + mail = get_fixture_mail('incoming-request-plain.email') + MailHandler.get_auto_submitted(mail).should == nil + end + +end + +describe 'when asked if there is an empty return path' do + + it 'should return true if there is an empty return-path specified' do + mail = get_fixture_mail('empty-return-path.email') + MailHandler.empty_return_path?(mail).should == true + end + + it 'should return false if there is no return-path header' do + mail = get_fixture_mail('incoming-request-attach-attachments.email') + MailHandler.empty_return_path?(mail).should == false + end + + it 'should return false if there is a return path address' do + mail = get_fixture_mail('autoresponse-header.email') + MailHandler.empty_return_path?(mail).should == false + end +end -- cgit v1.2.3 From 2df3a091a9cf91c1a3c249de48392662a8603d86 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 4 Dec 2012 11:22:37 +0000 Subject: Add a method for setting the from address on a plain email fixture. --- spec/lib/mail_handler/mail_handler_spec.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index e673c5bf0..8f642d529 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -1,6 +1,12 @@ # coding: utf-8 require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper') +def create_message_from(from_field) + mail_data = load_file_fixture('incoming-request-plain.email') + mail_data.gsub!('EMAIL_FROM', from_field) + mail = MailHandler.mail_from_raw_email(mail_data) +end + describe 'when creating a mail object from raw data' do it 'should correctly parse a multipart email with a linebreak in the boundary' do @@ -25,9 +31,7 @@ end describe 'when asked for the from name' do it 'should return nil if there is a blank "From" field' do - mail_data = load_file_fixture('incoming-request-plain.email') - mail_data.gsub!('EMAIL_FROM', '') - mail = MailHandler.mail_from_raw_email(mail_data) + mail = create_message_from('') MailHandler.get_from_name(mail).should == nil end @@ -51,9 +55,7 @@ end describe 'when asked for the from address' do it 'should return nil if there is a blank "From" field' do - mail_data = load_file_fixture('incoming-request-plain.email') - mail_data.gsub!('EMAIL_FROM', '') - mail = MailHandler.mail_from_raw_email(mail_data) + mail = create_message_from('') MailHandler.get_from_address(mail).should == nil end -- cgit v1.2.3 From 6ea3501d7b0bff1194955d0de716bd3f1aba3ca6 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 4 Dec 2012 11:23:38 +0000 Subject: Add specs for getting name, email and formatted address - make them pass with the mail backend. --- spec/lib/mail_handler/mail_handler_spec.rb | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index 8f642d529..6043bf5bc 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -140,3 +140,53 @@ describe 'when asked if there is an empty return path' do MailHandler.empty_return_path?(mail).should == false end end + +describe 'when deriving a name, email and formatted address from a message from a line' do + + def should_render_from_address(from_line, expected_result) + mail = create_message_from(from_line) + name = MailHandler.get_from_name(mail) + email = MailHandler.get_from_address(mail) + address = MailHandler.address_from_name_and_email(name, email).to_s + [name, email, address].should == expected_result + end + + it 'should correctly reproduce a simple name and email that does not need quotes' do + should_render_from_address('"FOI Person" ', + ['FOI Person', + 'foiperson@localhost', + 'FOI Person ']) + end + + it 'should render an address with no name' do + should_render_from_address("foiperson@localhost", + [nil, + "foiperson@localhost", + "foiperson@localhost"]) + end + + it 'should quote a name with a square bracked in it' do + should_render_from_address('"FOI [ Person" ', + ['FOI [ Person', + 'foiperson@localhost', + '"FOI [ Person" ']) + end + + it 'should quote a name with an @ in it' do + should_render_from_address('"FOI @ Person" ', + ['FOI @ Person', + 'foiperson@localhost', + '"FOI @ Person" ']) + end + + + it 'should quote a name with quotes in it' do + should_render_from_address('"FOI \" Person" ', + ['FOI " Person', + 'foiperson@localhost', + '"FOI \" Person" ']) + end + + + +end -- cgit v1.2.3 From 49c8a6131acbdfe151fe1ab0a0e08616865a4e08 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 4 Dec 2012 12:00:11 +0000 Subject: Rewrite and move spec so that it tests the mail handler method. --- spec/lib/mail_handler/mail_handler_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index 6043bf5bc..dc147f32b 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -151,6 +151,13 @@ describe 'when deriving a name, email and formatted address from a message from [name, email, address].should == expected_result end + it 'should correctly render a name with quoted commas' do + should_render_from_address('"Clare College, Cambridge" ', + ['Clare College, Cambridge', + 'test@test.test', + '"Clare College, Cambridge" ']) + end + it 'should correctly reproduce a simple name and email that does not need quotes' do should_render_from_address('"FOI Person" ', ['FOI Person', -- cgit v1.2.3 From 096c5c5613f426f2e5a73618e6a4e41bc06b57e2 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 4 Dec 2012 14:13:49 +0000 Subject: Adding methods for getting the content type of a mail part, and getting header strings from a mail. --- spec/lib/mail_handler/mail_handler_spec.rb | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index dc147f32b..7eeba47e0 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -194,6 +194,60 @@ describe 'when deriving a name, email and formatted address from a message from '"FOI \" Person" ']) end +end + +describe 'when getting the content type of a mail part' do + + def expect_content_type(fixture_file, content_type) + mail = get_fixture_mail(fixture_file) + MailHandler.get_content_type(mail).should == content_type + end + + it 'should correctly return a type of "multipart/report"' do + expect_content_type('track-response-multipart-report.email', 'multipart/report') + end + it 'should correctly return a type of "text/plain"' do + expect_content_type('track-response-abcmail-oof.email', 'text/plain') + end + + it 'should correctly return a type of "multipart/mixed"' do + expect_content_type('track-response-messageclass-oof.email', 'multipart/mixed') + end + + it 'should correctly return the types in an example bounce report' do + mail = get_fixture_mail('track-response-ms-bounce.email') + report = mail.parts.detect{ |part| MailHandler.get_content_type(part) == 'multipart/report'} + MailHandler.get_content_type(report.parts[0]).should == 'text/plain' + MailHandler.get_content_type(report.parts[1]).should == 'message/delivery-status' + MailHandler.get_content_type(report.parts[2]).should == 'message/rfc822' + end end + +describe 'when getting header strings' do + + def expect_header_string(fixture_file, header, header_string) + mail = get_fixture_mail(fixture_file) + MailHandler.get_header_string(header, mail).should == header_string + end + + it 'should return the contents of a "Subject" header' do + expect_header_string('track-response-ms-bounce.email', + 'Subject', + 'Delivery Status Notification (Delay)') + end + + it 'should return the contents of an "X-Failed-Recipients" header' do + expect_header_string('autoresponse-header.email', + 'X-Failed-Recipients', + 'enquiries@cheese.com') + end + + it 'should return the contents of an example "" header' do + expect_header_string('track-response-messageclass-oof.email', + 'X-POST-MessageClass', + '9; Autoresponder') + end + +end \ No newline at end of file -- cgit v1.2.3 From 14bbd1d75840add4fd5f8c440b58ac465c306fb6 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 6 Dec 2012 10:23:37 +0000 Subject: Move methods for getting the text out of attachments to the mail handler module. --- spec/lib/mail_handler/mail_handler_spec.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index 7eeba47e0..efa89b6e0 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -250,4 +250,24 @@ describe 'when getting header strings' do '9; Autoresponder') end -end \ No newline at end of file +end + +describe "when parsing HTML mail" do + it "should display UTF-8 characters in the plain text version correctly" do + html = "foo është" + plain_text = MailHandler._get_attachment_text_internal_one_file('text/html', html) + plain_text.should match(/është/) + end + +end + +describe "when getting the attachment text" do + + it "should not raise an error if the expansion of a zip file raises an error" do + mock_entry = mock('ZipFile entry', :file? => true) + mock_entry.stub!(:get_input_stream).and_raise("invalid distance too far back") + Zip::ZipFile.stub!(:open).and_return([mock_entry]) + MailHandler._get_attachment_text_internal_one_file('application/zip', "some string") + end + +end -- cgit v1.2.3 From 1d4ef88e60bcecc5c413cf3b6e6cb76f4bb6eaa1 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 6 Dec 2012 10:43:07 +0000 Subject: Rename _get_attachment_text_internal_one_file to get_attachment_text_one_file as it is now an externally-accessed method of the mail handler module. --- spec/lib/mail_handler/mail_handler_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index efa89b6e0..3ccccc6bc 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -255,19 +255,18 @@ end describe "when parsing HTML mail" do it "should display UTF-8 characters in the plain text version correctly" do html = "foo është" - plain_text = MailHandler._get_attachment_text_internal_one_file('text/html', html) + plain_text = MailHandler.get_attachment_text_one_file('text/html', html) plain_text.should match(/është/) end end describe "when getting the attachment text" do - it "should not raise an error if the expansion of a zip file raises an error" do mock_entry = mock('ZipFile entry', :file? => true) mock_entry.stub!(:get_input_stream).and_raise("invalid distance too far back") Zip::ZipFile.stub!(:open).and_return([mock_entry]) - MailHandler._get_attachment_text_internal_one_file('application/zip', "some string") + MailHandler.get_attachment_text_one_file('application/zip', "some string") end end -- cgit v1.2.3 From 43a21cd57f6aafb94698b5324aaac0f3c106319f Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 6 Dec 2012 11:27:23 +0000 Subject: Stub the close method on the object we're passing to the zip file extraction function. --- spec/lib/mail_handler/mail_handler_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index 3ccccc6bc..99ab8096f 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -264,8 +264,10 @@ end describe "when getting the attachment text" do it "should not raise an error if the expansion of a zip file raises an error" do mock_entry = mock('ZipFile entry', :file? => true) + mock_entries = [mock_entry] + mock_entries.stub!(:close) mock_entry.stub!(:get_input_stream).and_raise("invalid distance too far back") - Zip::ZipFile.stub!(:open).and_return([mock_entry]) + Zip::ZipFile.stub!(:open).and_return(mock_entries) MailHandler.get_attachment_text_one_file('application/zip', "some string") end -- cgit v1.2.3 From f026dbc4c23ca25dd31dc6d3d132d6f1668728de Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 6 Dec 2012 13:46:05 +0000 Subject: Convert example URL to spec. --- spec/lib/mail_handler/mail_handler_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index 99ab8096f..1e10a7871 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -272,3 +272,12 @@ describe "when getting the attachment text" do end end + +describe 'when getting attachment attributes' do + + it 'should handle a mail which causes Tmail to generate a blank header value' do + mail = get_fixture_mail('many-attachments-date-header.email') + attributes = MailHandler.get_attachment_attributes(mail) + end + +end -- cgit v1.2.3 From 6f64f255e08c553e7edee02ad7eb6acd535124bf Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 6 Dec 2012 14:11:10 +0000 Subject: Add a spec for some basic consistency in content types, url part numbers, filenames, and within rfc822 subjects. --- spec/lib/mail_handler/mail_handler_spec.rb | 80 ++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index 1e10a7871..c01b173d5 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -280,4 +280,84 @@ describe 'when getting attachment attributes' do attributes = MailHandler.get_attachment_attributes(mail) end + it 'should produce a consistent set of url_part_numbers, content_types, within_rfc822_subjects + and filenames from an example mail with lots of attachments' do + mail = get_fixture_mail('many-attachments-date-header.email') + attributes = MailHandler.get_attachment_attributes(mail) + + expected_attributes = [ { :content_type=>"text/plain", + :url_part_number=>1, + :within_rfc822_subject=>nil, + :filename=>nil}, + { :content_type=>"text/plain", + :url_part_number=>2, + :within_rfc822_subject=>"Re: xxx", + :filename=>nil}, + { :content_type=>"text/html", + :url_part_number=>4, + :within_rfc822_subject=>"example", + :filename=>nil}, + { :content_type=>"image/gif", :url_part_number=>5, + :within_rfc822_subject=>"example", + :filename=>"image001.gif"}, + { :content_type=>"application/vnd.ms-excel", + :url_part_number=>6, + :within_rfc822_subject=>"example", + :filename=>"particpant list.xls"}, + { :content_type=>"text/plain", + :url_part_number=>7, + :within_rfc822_subject=>"RE: example", + :filename=>nil}, + { :content_type=>"text/html", + :url_part_number=>9, + :within_rfc822_subject=>"As promised - Masterclass info (example)", + :filename=>nil}, + { :content_type=>"image/gif", + :url_part_number=>10, + :within_rfc822_subject=>"As promised - Masterclass info (example)", + :filename=>"image001.gif"}, + { :content_type=>"application/vnd.ms-word", + :url_part_number=>11, + :within_rfc822_subject=>"As promised - Masterclass info (example)", + :filename=>"Participant List.doc"}, + { :content_type=>"application/vnd.ms-word", + :url_part_number=>12, + :within_rfc822_subject=>"As promised - Masterclass info (example)", + :filename=>"Information & Booking Form.doc"}, + { :content_type=>"text/plain", + :url_part_number=>13, + :within_rfc822_subject=>"Re: As promised - info (example)", + :filename=>nil}, + { :content_type=>"text/html", + :url_part_number=>15, + :within_rfc822_subject=>"Thank you from example", + :filename=>nil}, + { :content_type=>"image/gif", + :url_part_number=>16, + :within_rfc822_subject=>"Thank you from example", + :filename=>"image001.gif"}, + { :content_type=>"text/plain", + :url_part_number=>17, + :within_rfc822_subject=>"example - Meeting - Tuesday 2nd March", + :filename=>nil}, + { :content_type=>"text/plain", + :url_part_number=>18, + :within_rfc822_subject=>"example - Help needed", + :filename=>nil}, + { :content_type=>"application/pdf", + :url_part_number=>19, + :within_rfc822_subject=>"example - Help needed", + :filename=>"Information Pack.pdf"}, + { :content_type=>"text/plain", + :url_part_number=>20, + :within_rfc822_subject=>"Re: As promised - info (example)", + :filename=>nil} ] + + attributes.each_with_index do |attr, index| + attr.delete(:charset) + attr.delete(:body) + attr.delete(:hexdigest) + attr.should == expected_attributes[index] + end + end end -- cgit v1.2.3 From 24648c4b8f0bfbcbb3cf0d192b28906a9b7e111c Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 6 Dec 2012 17:11:15 +0000 Subject: Add specs for attachment attributes. --- spec/lib/mail_handler/mail_handler_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index c01b173d5..ae65210f2 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -275,6 +275,26 @@ end describe 'when getting attachment attributes' do + it 'should get two attachment parts from a multipart mail with text and html alternatives + and an image' do + mail = get_fixture_mail('quoted-subject-iso8859-1.email') + attributes = MailHandler.get_attachment_attributes(mail) + attributes.size.should == 2 + end + + it 'should expand a mail attached as text' do + mail = get_fixture_mail('rfc822-attachment.email') + attributes = MailHandler.get_attachment_attributes(mail) + attributes.size.should == 2 + rfc_attachment = attributes[1] + rfc_attachment[:within_rfc822_subject].should == 'Freedom of Information request' + headers = ['Date: Thu, 13 Mar 2008 16:57:33 +0000', + 'Subject: Freedom of Information request', + 'From: An FOI Officer ', + 'To: request-bounce-xx-xxxxx@whatdotheyno.com'] + rfc_attachment[:body].should == "#{headers.join("\n")}\n\nsome example text" + end + it 'should handle a mail which causes Tmail to generate a blank header value' do mail = get_fixture_mail('many-attachments-date-header.email') attributes = MailHandler.get_attachment_attributes(mail) -- cgit v1.2.3 From e898190fe61a4369ee83e94a24327ff437435b07 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 11 Dec 2012 14:07:54 +0000 Subject: Wrap specs on the extraction of RFC-822 headers in code that sets the ENV timezone. TMail renders headers using localtime, which is not ideal, but we're migrating away from it anyway, so I'm not sure it's worth delving into the internals of TMail to fix it. --- spec/lib/mail_handler/mail_handler_spec.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'spec/lib/mail_handler') diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index ae65210f2..48c32e2bc 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -283,16 +283,20 @@ describe 'when getting attachment attributes' do end it 'should expand a mail attached as text' do - mail = get_fixture_mail('rfc822-attachment.email') - attributes = MailHandler.get_attachment_attributes(mail) - attributes.size.should == 2 - rfc_attachment = attributes[1] - rfc_attachment[:within_rfc822_subject].should == 'Freedom of Information request' - headers = ['Date: Thu, 13 Mar 2008 16:57:33 +0000', - 'Subject: Freedom of Information request', - 'From: An FOI Officer ', - 'To: request-bounce-xx-xxxxx@whatdotheyno.com'] - rfc_attachment[:body].should == "#{headers.join("\n")}\n\nsome example text" + # Note that this spec will only pass using Tmail in the timezone set as datetime headers + # are rendered out in the local time - using the Mail gem this is not necessary + with_env_tz('London') do + mail = get_fixture_mail('rfc822-attachment.email') + attributes = MailHandler.get_attachment_attributes(mail) + attributes.size.should == 2 + rfc_attachment = attributes[1] + rfc_attachment[:within_rfc822_subject].should == 'Freedom of Information request' + headers = ['Date: Thu, 13 Mar 2008 16:57:33 +0000', + 'Subject: Freedom of Information request', + 'From: An FOI Officer ', + 'To: request-bounce-xx-xxxxx@whatdotheyno.com'] + rfc_attachment[:body].should == "#{headers.join("\n")}\n\nsome example text" + end end it 'should handle a mail which causes Tmail to generate a blank header value' do -- cgit v1.2.3