Skip to content

Commit

Permalink
Merge branch 'develop' into wdtk
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Aug 14, 2020
2 parents 11747bc + 1dcd79e commit 95bd95d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/mail_handler/backends/mail_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def backend
end

def mail_from_raw_email(data)
data = data.force_encoding(Encoding::BINARY) if data.is_a? String
Mail.new(data)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
From: EMAIL_FROM
To: FOI Person <EMAIL_TO>
Subject: Acknowledgement of request
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Information Governance�Unit
50 changes: 46 additions & 4 deletions spec/lib/mail_handler/backends/mail_backend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,52 @@

describe :mail_from_raw_email do

it 'returns a new mail instance of the email' do
raw_mail = load_file_fixture('raw_emails/1.email')
expected = Mail.read_from_string(raw_mail)
expect(mail_from_raw_email(raw_mail)).to eq(expected)
subject { mail_from_raw_email(raw_email) }

context 'when passed a binary string' do
# Read fixture file using 'rb' mode so we end up with a ASCII-8BIT string
let(:raw_email) { load_file_fixture('raw_emails/1.email', 'rb') }

it 'does not raise error' do
expect { subject }.to_not raise_error
end

it 'returns a new mail instance of the email' do
is_expected.to eq Mail.read_from_string(raw_email)
end
end

context 'when passed an UTF-8 string' do
let(:raw_email) do
# Read fixture file using 'r' mode so we end up with a UTF-8 string
load_file_fixture('iso8859_1_with_extended_character_set.email', 'r')
end

it 'does not raise error' do
expect { subject }.to_not raise_error
end

it 'returns a new mail with binary body' do
expect(subject.body.to_s).to eq(
"Information Governance\xA0Unit".force_encoding(Encoding::BINARY)
)
end
end

context 'when passed a mail' do
let(:raw_email) do
Mail.new(
load_file_fixture('incoming-request-attach-attachments.email')
).body
end

it 'does not raise error' do
expect { subject }.to_not raise_error
end

it 'returns a new mail instance of the email' do
is_expected.to eq Mail.read_from_string(raw_email)
end
end

end
Expand Down

0 comments on commit 95bd95d

Please sign in to comment.