Skip to content

Commit

Permalink
Handle unknown encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Mar 1, 2017
1 parent d654286 commit 4cd94bf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/chupa-text/decomposers/mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ def decompose(data)
end
parts.each_with_index do |part, i|
body = part.body.decoded
body.force_encoding(part.charset) if part.charset
if part.charset
begin
body.force_encoding(part.charset)
rescue ArgumentError
raise UnknownEncodingError.new(data, part.charset)
end
end

part_data = TextData.new(body, :source_data => data)
uri = data.uri.dup
Expand Down
9 changes: 9 additions & 0 deletions test/fixture/unknown-encoding.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Mime-Version: 1.0
Subject: Hello
From: Sender <[email protected]>
To: Recipient <[email protected]>
Date: Sun, 19 Feb 2017 00:27:55 +0900 (JST)
Content-Type: Text/Plain; charset=iso-2022-jp-3
Content-Transfer-Encoding: 8bit

World
13 changes: 13 additions & 0 deletions test/test-mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,18 @@ def decompose
super(fixture_path("nested-rfc822.eml"))
end
end

sub_test_case("unknown encoding") do
def test_body
assert_raise(ChupaText::UnknownEncodingError) do
decompose
end
end

private
def decompose
super(fixture_path("unknown-encoding.eml"))
end
end
end
end

0 comments on commit 4cd94bf

Please sign in to comment.