aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Legler <alex@a3li.li>2015-02-21 23:37:18 +0100
committerAlex Legler <alex@a3li.li>2015-02-21 23:37:18 +0100
commit3fe02ff3df0f83234e0d4b05ce1d268e2cadc235 (patch)
tree94a7c9143431e51d65826fbe12a17b3afea7116f /lib
parentPrint filename for failed files (diff)
downloadbackend-3fe02ff3df0f83234e0d4b05ce1d268e2cadc235.tar.gz
backend-3fe02ff3df0f83234e0d4b05ce1d268e2cadc235.tar.bz2
backend-3fe02ff3df0f83234e0d4b05ce1d268e2cadc235.zip
Show more filenames when rendering fails
Diffstat (limited to 'lib')
-rw-r--r--lib/storage.rb14
-rw-r--r--lib/utils.rb10
2 files changed, 14 insertions, 10 deletions
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