diff options
author | Louise Crow <louise.crow@gmail.com> | 2015-05-28 12:38:43 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2015-05-28 12:38:43 +0100 |
commit | b9ebcb7c223a2377d582589840ea8bb72cb5f654 (patch) | |
tree | c6f540849c4f086c5032c6dfbf7622a028d107c4 /app/models | |
parent | 07b8c95e66d8709b4bfbc52443ea227ff43097db (diff) | |
parent | 8a831333d28bc4bb33631c8a31934c2313ddc912 (diff) |
Merge branch 'hotfix/0.21.0.33' into rails-3-develop
Diffstat (limited to 'app/models')
-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 2a52921f0..58ae29a3b 100644 --- a/app/models/raw_email.rb +++ b/app/models/raw_email.rb @@ -40,11 +40,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! |