mirror of
https://github.com/discourse/discourse.git
synced 2025-03-02 01:09:26 +00:00
Merge pull request #1835 from HerbJiang/master
Fix reply by email encoding error when using non-ASCII & non-UTF8 charset
This commit is contained in:
commit
9b3eb0d201
@ -57,21 +57,27 @@ module Email
|
|||||||
if @message.multipart?
|
if @message.multipart?
|
||||||
@message.parts.each do |p|
|
@message.parts.each do |p|
|
||||||
if p.content_type =~ /text\/plain/
|
if p.content_type =~ /text\/plain/
|
||||||
@body = p.body.to_s
|
@body = p.charset ? p.body.decoded.force_encoding(p.charset).encode("UTF-8").to_s : p.body.to_s
|
||||||
return @body
|
return @body
|
||||||
elsif p.content_type =~ /text\/html/
|
elsif p.content_type =~ /text\/html/
|
||||||
html = p.body.to_s
|
html = p.charset ? p.body.decoded.force_encoding(p.charset).encode("UTF-8").to_s : p.body.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
html = @message.body.to_s if @message.content_type =~ /text\/html/
|
if @message.content_type =~ /text\/html/
|
||||||
|
if defined? @message.charset
|
||||||
|
html = @message.body.decoded.force_encoding(@message.charset).encode("UTF-8").to_s
|
||||||
|
else
|
||||||
|
html = @message.body.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
if html.present?
|
if html.present?
|
||||||
@body = scrub_html(html)
|
@body = scrub_html(html)
|
||||||
return @body
|
return @body
|
||||||
end
|
end
|
||||||
|
|
||||||
@body = @message.body.to_s.strip
|
@body = @message.charset ? @message.body.decoded.force_encoding(@message.charset).encode("UTF-8").to_s.strip : @message.body.to_s
|
||||||
|
|
||||||
# Certain trigger phrases that means we didn't parse correctly
|
# Certain trigger phrases that means we didn't parse correctly
|
||||||
@body = nil if @body =~ /Content\-Type\:/ ||
|
@body = nil if @body =~ /Content\-Type\:/ ||
|
||||||
|
@ -73,6 +73,17 @@ stripped from my reply?")
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "It supports a non UTF-8 reply" do
|
||||||
|
let(:big5) { File.read("#{Rails.root}/spec/fixtures/emails/big5.eml") }
|
||||||
|
let(:receiver) { Email::Receiver.new(big5) }
|
||||||
|
|
||||||
|
it "processes correctly" do
|
||||||
|
I18n.expects(:t).with('user_notifications.previous_discussion').returns('媽!我上電視了!')
|
||||||
|
receiver.process
|
||||||
|
expect(receiver.body).to eq("媽!我上電視了!")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "via" do
|
describe "via" do
|
||||||
let(:wrote) { File.read("#{Rails.root}/spec/fixtures/emails/via_line.eml") }
|
let(:wrote) { File.read("#{Rails.root}/spec/fixtures/emails/via_line.eml") }
|
||||||
let(:receiver) { Email::Receiver.new(wrote) }
|
let(:receiver) { Email::Receiver.new(wrote) }
|
||||||
|
BIN
spec/fixtures/emails/big5.eml
vendored
Normal file
BIN
spec/fixtures/emails/big5.eml
vendored
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user