From 3fe02ff3df0f83234e0d4b05ce1d268e2cadc235 Mon Sep 17 00:00:00 2001 From: Alex Legler Date: Sat, 21 Feb 2015 23:37:18 +0100 Subject: Show more filenames when rendering fails --- lib/storage.rb | 14 +++++++------- lib/utils.rb | 10 +++++++--- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/storage.rb b/lib/storage.rb index da9e8ad..fdf70b6 100644 --- a/lib/storage.rb +++ b/lib/storage.rb @@ -73,17 +73,17 @@ module Ag::Storage sleep 1 end - def get_content(message) - content = "Cannot parse MIME/contents." + def get_content(message, filename) + content = 'Cannot parse MIME/contents.' begin raw_content = Ag::Rendering::HTMLizer.HTMLize(message) - content = Ag::Utils.fix_encoding(raw_content || '').strip + content = Ag::Utils.fix_encoding(raw_content || '', true).strip if content == '' - $stderr.puts "#{message.message_id}: Content empty" + $stderr.puts "#{message.message_id}: Content empty?" end - rescue - $stderr.puts "#{message.message_id}: Invalid encoding" + rescue => e + $stderr.puts "Cannot render message #{message.message_id} (file: #{filename}): #{e}" end content @@ -111,7 +111,7 @@ module Ag::Storage result['hits']['hits'].first['_id'] end - def store(list, message) + def store(list, message, filename) content = get_content(message) identifier = message['X-Archives-Hash'].value diff --git a/lib/utils.rb b/lib/utils.rb index 109a6a5..3714614 100644 --- a/lib/utils.rb +++ b/lib/utils.rb @@ -3,12 +3,16 @@ require 'charlock_holmes' module Ag module Utils module_function - def fix_encoding(str) + def fix_encoding(str, fail_hard = false) detection = CharlockHolmes::EncodingDetector.detect(str) CharlockHolmes::Converter.convert(str, detection[:encoding], 'UTF-8') rescue => e - $stderr.puts e.message if $options.debug - 'Encoding could not be reliably detected. Message contents not available.' + if fail_hard + raise e + else + $stderr.puts e.message if $options.debug + 'Encoding could not be reliably detected. Contents not available.' + end end end end \ No newline at end of file -- cgit v1.2.3-65-gdbad