From 6b973b1d59b5c384a4ca5a5c0c2c53ad43159ad0 Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Mon, 13 May 2013 17:50:25 +0100 Subject: Add a helper function for dumping text to disk This function is useful for investigating problems with handling of emails, attachments and the related character encoding issues. It can safely be removed later, but is currently useful to have for debugging purposes. --- lib/normalize_string.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/normalize_string.rb') diff --git a/lib/normalize_string.rb b/lib/normalize_string.rb index e708a8d96..f02b18ee0 100644 --- a/lib/normalize_string.rb +++ b/lib/normalize_string.rb @@ -73,3 +73,14 @@ def convert_string_to_utf8_or_binary(s, suggested_character_encoding=nil) end result end + +def log_text_details(message, text) + if RUBY_VERSION.to_f >= 1.9 + STDERR.puts "#{message}, we have text: #{text}, of class #{text.class} and encoding #{text.encoding}" + else + STDERR.puts "#{message}, we have text: #{text}, of class #{text.class}" + end + filename = "/var/tmp/#{Digest::MD5.hexdigest(text)}.txt" + File.open(filename, "wb") { |f| f.write text } + STDERR.puts "#{message}, the filename is: #{filename}" +end -- cgit v1.2.3