diff options
-rwxr-xr-x | ag | 4 | ||||
-rw-r--r-- | lib/storage.rb | 14 | ||||
-rw-r--r-- | lib/utils.rb | 10 |
3 files changed, 16 insertions, 12 deletions
@@ -109,7 +109,7 @@ def do_full mail = maildir_message.data begin - Ag::Storage.store($options.name, mail) + Ag::Storage.store($options.name, mail, maildir_message.filename) rescue => e $stderr.puts "Cannot save message #{mail.message_id}: #{e.message}" next @@ -124,7 +124,7 @@ def do_incremental mail = maildir_message.data begin - Ag::Storage.store($options.name, mail) + Ag::Storage.store($options.name, mail, maildir_message.filename) maildir_message.process unless $options.readonly rescue => e $stderr.puts "Cannot save message #{mail.message_id} (file #{maildir_message.filename}): #{e.message}" 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 |