diff options
author | Louise Crow <louise.crow@gmail.com> | 2015-05-28 11:57:18 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2015-05-28 11:57:18 +0100 |
commit | c1947ec633e29abd65f1e3737707e2a7f79b5fc8 (patch) | |
tree | bcee9e60dba9b7834c910a11719404eb4d4d7e03 /app/models/raw_email.rb | |
parent | 005ca27e756ed7448c114de9ba0e9545352133ac (diff) | |
parent | c0a76dd0b1816f9a324e6187795c18abf36eeed5 (diff) |
Merge branch 'handle-unparsed-email-as-binary' into hotfix/0.21.0.33
Diffstat (limited to 'app/models/raw_email.rb')
-rw-r--r-- | app/models/raw_email.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb index 3b466cb81..907d3c7a0 100644 --- a/app/models/raw_email.rb +++ b/app/models/raw_email.rb @@ -39,11 +39,26 @@ class RawEmail < ActiveRecord::Base def data=(d) FileUtils.mkdir_p(directory) unless File.exists?(directory) - File.atomic_write(filepath) { |file| file.write(d) } + File.atomic_write(filepath) do |file| + file.binmode + file.write(d) + end end def data - File.open(filepath, "r").read + File.open(filepath, "rb").read + end + + def data_as_text + text = data + if text.respond_to?(:encoding) + text = text.encode("UTF-8", :invalid => :replace, + :undef => :replace, + :replace => "") + else + text = Iconv.conv('UTF-8//IGNORE', 'UTF-8', text) + end + text end def destroy_file_representation! |