diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-12-04 09:53:16 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-12-04 09:53:16 +0000 |
commit | 9dfe9de140242c176eef8af65d78ced3f2992cc1 (patch) | |
tree | a823ea107091fa496796b00f738fb92f2745844e /spec/lib/mail_handler/mail_handler_spec.rb | |
parent | 30dd01f931ae3dea9a56812387bfea2544818e31 (diff) |
Move method for getting the to, cc and envelope-to addresses of a mail to the mail handler.
Diffstat (limited to 'spec/lib/mail_handler/mail_handler_spec.rb')
-rw-r--r-- | spec/lib/mail_handler/mail_handler_spec.rb | 29 |
1 files changed, 29 insertions, 0 deletions
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 <EMAIL_TO>', + 'To: FOI Person <request-5555-xxxxxxxx@whatdotheyknow.com>') + mail = MailHandler.mail_from_raw_email(mail_data) + MailHandler.get_all_addresses(mail).should == ["request-5555-xxxxxxxx@whatdotheyknow.com"] + end +end |