Index: lib/redmine/codeset_util.rb =================================================================== --- lib/redmine/codeset_util.rb (revision 20033) +++ lib/redmine/codeset_util.rb (working copy) @@ -23,9 +23,14 @@ end enc = encoding.blank? ? "UTF-8" : encoding if enc.casecmp("UTF-8") != 0 - str.force_encoding(enc) - str = str.encode("UTF-8", :invalid => :replace, + begin + str.force_encoding(enc) + str = str.encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => '?') + rescue Encoding::ConverterNotFoundError + Rails.logger.warn ">>> ConverterNotFoundError (#{enc} to UTF-8)" + str = replace_invalid_utf8(str) + end else str = replace_invalid_utf8(str) end Index: test/fixtures/mail_handler/body_windows-1258.eml =================================================================== --- test/fixtures/mail_handler/body_windows-1258.eml (nonexistent) +++ test/fixtures/mail_handler/body_windows-1258.eml (working copy) @@ -0,0 +1,14 @@ +From: John Smith +To: "redmine@somenet.foo" +Subject: This is a Vietnamiese test +Content-Type: multipart/alternative; + boundary="_c20d9cfa-d16a-43a3-a7e5-71da7877ab23_" + +--_c20d9cfa-d16a-43a3-a7e5-71da7877ab23_ +Content-Type: text/plain; charset="windows-1258" +Content-Transfer-Encoding: quoted-printable + +không hợp lệ + +--_c20d9cfa-d16a-43a3-a7e5-71da7877ab23_-- + Index: test/unit/lib/redmine/codeset_util_test.rb =================================================================== --- test/unit/lib/redmine/codeset_util_test.rb (revision 20033) +++ test/unit/lib/redmine/codeset_util_test.rb (working copy) @@ -101,4 +101,12 @@ assert_equal "UTF-8", s2.encoding.to_s assert_equal 'こんにち?', s2 end + + test "#to_utf8 should support not supported code page" do + s1 = (+'không hợp lệ').force_encoding('Windows-1258') + s2 = Redmine::CodesetUtil.to_utf8(s1, 'Windows-1258') + assert s2.valid_encoding? + assert_equal 'UTF-8', s2.encoding.to_s + assert_equal 'không hợp lệ', s2 + end end Index: test/unit/mail_handler_test.rb =================================================================== --- test/unit/mail_handler_test.rb (revision 20033) +++ test/unit/mail_handler_test.rb (working copy) @@ -747,6 +747,15 @@ assert_equal '고맙습니다.', issue.description end + def test_add_issue_with_vietnamiese_body + issue = submit_email( + 'body_windows-1258.eml', + issue: { project: 'ecookbook' } + ) + assert_kind_of Issue, issue + assert issue.description.include?('không hợp lệ') + end + def test_add_issue_with_no_subject_header with_settings :default_language => 'en' do issue = submit_email(