aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/raw_email.rb19
-rw-r--r--app/views/admin_raw_email/show.html.erb5
2 files changed, 21 insertions, 3 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!
diff --git a/app/views/admin_raw_email/show.html.erb b/app/views/admin_raw_email/show.html.erb
index f88b00ef0..1de719544 100644
--- a/app/views/admin_raw_email/show.html.erb
+++ b/app/views/admin_raw_email/show.html.erb
@@ -59,5 +59,8 @@
<p><%= link_to "Download", admin_raw_email_path(@raw_email, :format => 'txt') %></p>
-<pre><%=h(@raw_email.data).gsub(/\n/, '<br>').html_safe %></pre>
+<h2>Preview</h2>
+
+For an exact rendering of this email, use the "Download" link.
+<pre><%=h(@raw_email.data_as_text).gsub(/\n/, '<br>').html_safe %></pre>