From 2e01ec048c8f594a5bbacb39cf1ceb3808d54650 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 30 May 2016 10:33:27 +0200 Subject: [PATCH] Improved error handling of unprocessable emails, store unprocessable email for bug reporting unter tmp/unprocessable_mail/. --- app/models/channel/email_parser.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 54660a694..4f82ac9d2 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -344,6 +344,25 @@ retrns =end def process(channel, msg) + + _process(channel, msg) + rescue => e + + # store unprocessable email for bug reporting + path = "#{Rails.root}/tmp/unprocessable_mail/" + FileUtils.mkpath path + md5 = Digest::MD5.hexdigest(msg) + filename = "#{path}/#{md5}.eml" + Rails.logger.error "ERROR: Can't process email, store it for bug reporting under #{filename}" + Rails.logger.error 'ERROR: ' + e.inspect + File.open(filename, 'wb') { |file| + file.write msg + } + raise e.inspect + + end + + def _process(channel, msg) mail = parse(msg) # run postmaster pre filter