diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-09-20 16:55:06 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-11-08 17:07:36 +0000 |
commit | a83b379fd2d676172855825d0592937b234371e2 (patch) | |
tree | 6a9c2abddd410f02488093d5c54f7c855b9a0560 | |
parent | 9dd0b8b27bc7072c7e6afe54ff3693f653b7c90c (diff) |
Don't read the saved mail in binary mode.
The first reason for doing this is that atomic_write doesn't write in binary mode, and I think we should be symmetrical in reading and writing.
The second reason is that I don't think a received email is really binary data in its raw form. I think it will be ascii with non ascii parts converted to ascii using content-transfer-encodings (http://en.wikipedia.org/wiki/MIME).
This matters in Ruby 1.9 because we have a default internal and external encoding (http://blog.grayproductions.net/articles/ruby_19s_three_default_encodings).
UTF-8 seems like a good initial default to set. If we retrieve this data from a file as binary data, we have a problem treating it as text, as we can't convert from binary to text in Ruby 1.9. Given that this is ascii data, I think we can safely treat it as UTF-8 (which should be a superset of ascii), until we convert it into a mail object, which should interpret the mime encodings correctly.
-rw-r--r-- | app/models/raw_email.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb index bae144931..de7978b82 100644 --- a/app/models/raw_email.rb +++ b/app/models/raw_email.rb @@ -22,7 +22,7 @@ class RawEmail < ActiveRecord::Base if request_id.empty? raise "Failed to find the id number of the associated request: has it been saved?" end - + if ENV["RAILS_ENV"] == "test" return File.join(Rails.root, 'files/raw_email_test') else @@ -49,7 +49,7 @@ class RawEmail < ActiveRecord::Base end def data - File.open(self.filepath, "rb").read + File.open(self.filepath, "r").read end def destroy_file_representation! |