diff options
Diffstat (limited to 'app/models/exim_log.rb')
-rw-r--r-- | app/models/exim_log.rb | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/app/models/exim_log.rb b/app/models/exim_log.rb index f7e23ed1c..864d5bf89 100644 --- a/app/models/exim_log.rb +++ b/app/models/exim_log.rb @@ -1,10 +1,24 @@ +# == Schema Information +# Schema version: 71 +# +# Table name: exim_logs +# +# id :integer not null, primary key +# exim_log_done_id :integer +# info_request_id :integer +# order :integer not null +# line :text not null +# created_at :datetime not null +# updated_at :datetime not null +# + # models/exim_log.rb: # We load log file lines for requests in here, for display in the admin interface. # # Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: exim_log.rb,v 1.3 2009-01-27 18:01:41 francis Exp $ +# $Id: exim_log.rb,v 1.4 2009-02-09 09:51:53 francis Exp $ class EximLog < ActiveRecord::Base belongs_to :info_request @@ -58,6 +72,43 @@ class EximLog < ActiveRecord::Base done.save! end end + + # Check that the last day of requests has been sent in Exim and we got the + # lines. Writes any errors to STDERR. This check is really mainly to + # check the envelope from is the request address, as Ruby is quite + # flaky with regard to that, and it is important for anti-spam reasons. + def EximLog.check_recent_requests_have_been_sent + # Get all requests sent for a period of 24 hours, ending a day ago. + # (the gap is because we load exim log lines via cron at best an hour + # after they are made) + irs = InfoRequest.find(:all, :conditions => [ "created_at < ? and created_at > ?", Time.now() - 1.day, Time.now() - 2.days ] ) + + # Go through each request and check it + for ir in irs + # Look for line showing request was sent + found = false + for exim_log in ir.exim_logs + test_outgoing = " <= " + ir.incoming_email + " " + if exim_log.line.include?(test_outgoing) + # Check the from value is the same (it always will be, but may as well + # be sure we are parsing the exim line right) + envelope_from = " from <" + ir.incoming_email + "> " + if !exim_log.line.include?(envelope_from) + raise "unexpected parsing of exim line" + end + + STDERR.puts exim_log.line # debugging + found = true + end + end + if !found + # It's very important the envelope from is set for avoiding spam filter reasons - this + # effectively acts as a check for that. + STDERR.puts("failed to find request sending Exim line for request id " + ir.id.to_s + " " + ir.url_title + " (check envelope from is being set to request address in Ruby, and load-exim-logs crontab is working)") # *** don't comment out this STDERR line, it is the point of the function! + end + end + end + end |