diff options
author | Robin Houston <robin@lenny.robin> | 2011-09-19 12:47:40 +0100 |
---|---|---|
committer | Robin Houston <robin@lenny.robin> | 2011-09-19 12:47:40 +0100 |
commit | b7544ee519c05240127b65e2bf5adfc99e9bc3ec (patch) | |
tree | 88608d30660ae264c965320f51cc8d4dafd2194e /script/handle-mail-replies | |
parent | 02264a621c568e1673d57a7fee9341f703b580e2 (diff) | |
parent | 2442a5322ee560756f521983a0f7f0de4c4aa4e1 (diff) |
Merge branch 'wdtk' into develop
Diffstat (limited to 'script/handle-mail-replies')
-rwxr-xr-x | script/handle-mail-replies | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/script/handle-mail-replies b/script/handle-mail-replies index 93cdc8cfd..9b1fb5b29 100755 --- a/script/handle-mail-replies +++ b/script/handle-mail-replies @@ -17,12 +17,19 @@ load "config.rb" MySociety::Config.set_file(File.join($alaveteli_dir, 'config', 'general'), true) MySociety::Config.load_default +$:.push(File.join($alaveteli_dir, "vendor", "rails", "actionmailer", "lib", "action_mailer", "vendor", "tmail-1.2.7")) +require 'tmail' + def main(in_test_mode) Dir.chdir($alaveteli_dir) do - load_rails - raw_message = $stdin.read - message = TMail::Mail.parse(raw_message) + begin + message = TMail::Mail.parse(raw_message) + rescue + # Error parsing message. Just pass it on, to be on the safe side. + forward_on(raw_message) unless in_test_mode + return 0 + end pfas = permanently_failed_addresses(message) if !pfas.empty? @@ -93,16 +100,29 @@ end def is_oof?(message) # Check for out-of-office + if message.header_string("X-POST-MessageClass") == "9; Autoresponder" + return true + end + + subject = message.header_string("Subject").downcase if message.header_string("Return-Path") == "<>" - subject = message.header_string("Subject") - if subject.start_with? "Out of Office: " + if subject.start_with? "out of office: " return true end - if subject.start_with? "Automatic reply: " + if subject.start_with? "automatic reply: " return true end end + if subject.start_with? "out of office autoreply:" + return true + end + if subject == "out of office" + return true + end + if subject.end_with? "is out of the office" + return true + end return false end @@ -120,6 +140,7 @@ def load_rails end def record_bounce(email_address, bounce_message) + load_rails User.record_bounce_for_email(email_address, bounce_message) end |