mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 07:14:41 +08:00
force_encoding according to the charset in mail, this solve encoding problem when not using ‘utf-8’ charset.
This commit is contained in:
@ -57,21 +57,27 @@ module Email
|
||||
if @message.multipart?
|
||||
@message.parts.each do |p|
|
||||
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
|
||||
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
|
||||
|
||||
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?
|
||||
@body = scrub_html(html)
|
||||
return @body
|
||||
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
|
||||
@body = nil if @body =~ /Content\-Type\:/ ||
|
||||
|
Reference in New Issue
Block a user