diff options
Diffstat (limited to 'script/handle-mail-replies')
-rwxr-xr-x | script/handle-mail-replies | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/script/handle-mail-replies b/script/handle-mail-replies index 68cab9035..7590f5848 100755 --- a/script/handle-mail-replies +++ b/script/handle-mail-replies @@ -18,13 +18,7 @@ load "config.rb" MySociety::Config.set_file(File.join($alaveteli_dir, 'config', 'general'), true) MySociety::Config.load_default -require 'rubygems' -if File.exist? File.join($alaveteli_dir,'vendor','rails','Rakefile') - $:.push(File.join($alaveteli_dir, "vendor", "rails", "actionmailer", "lib", "action_mailer", "vendor", "tmail-1.2.7")) - require 'tmail' -else - require 'action_mailer' -end +require 'action_mailer' def main(in_test_mode) Dir.chdir($alaveteli_dir) do @@ -49,9 +43,22 @@ def main(in_test_mode) return 1 end - if is_oof? message - # Discard out-of-office messages - return 2 + # If we are still here, there are no permanent failures, + # so if the message is a multipart/report then it must be + # reporting a temporary failure. In this case we discard it + if message.content_type == "multipart/report" + return 1 + end + + # Another style of temporary failure message + subject = message.header_string("Subject") + if message.content_type == "multipart/mixed" && subject == "Delivery Status Notification (Delay)" + return 1 + end + + # Discard out-of-office messages + if is_oof?(message) + return 2 # Use a different return code, to distinguish OOFs from bounces end # Otherwise forward the message on @@ -100,6 +107,15 @@ def permanently_failed_addresses(message) end end + subject = message.header_string("Subject") + # Then look for the style we’ve seen in WebShield bounces + # (These do not have a return path of <> in the cases I have seen.) + if subject == "Returned Mail: Error During Delivery" + if message.body =~ /^\s*---- Failed Recipients ----\s*((?:<[^>]+>\n)+)/ + return $1.scan(/<([^>]+)>/).flatten + end + end + return [] end @@ -151,7 +167,7 @@ end def load_rails require File.join('config', 'boot') - require RAILS_ROOT + '/config/environment' + require Rails.root + '/config/environment' end def record_bounce(email_address, bounce_message) |