aboutsummaryrefslogtreecommitdiff
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
parentPrint filename for failed files (diff)
downloadbackend-3fe02ff3df0f83234e0d4b05ce1d268e2cadc235.tar.gz
backend-3fe02ff3df0f83234e0d4b05ce1d268e2cadc235.tar.bz2
backend-3fe02ff3df0f83234e0d4b05ce1d268e2cadc235.zip
Show more filenames when rendering fails
-rwxr-xr-xag4
-rw-r--r--lib/storage.rb14
-rw-r--r--lib/utils.rb10
3 files changed, 16 insertions, 12 deletions
diff --git a/ag b/ag
index 4b857e3..be04609 100755
--- a/ag
+++ b/ag
@@ -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