diff options
-rw-r--r-- | app/models/info_request.rb | 6 | ||||
-rw-r--r-- | app/models/mail_server_log.rb (renamed from app/models/exim_log.rb) | 65 | ||||
-rw-r--r-- | app/models/mail_server_log_done.rb (renamed from app/models/exim_log_done.rb) | 9 | ||||
-rw-r--r-- | app/views/admin_request/show.rhtml | 8 | ||||
-rw-r--r-- | db/migrate/20121010214348_rename_exim_log_tables.rb | 13 | ||||
-rwxr-xr-x | script/check-recent-requests-sent | 2 | ||||
-rwxr-xr-x | script/load-exim-logs | 4 | ||||
-rw-r--r-- | spec/lib/timezone_fixes_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/mail_server_log_spec.rb (renamed from spec/models/exim_log_spec.rb) | 74 |
9 files changed, 105 insertions, 94 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 85168e6d4..d8c84fa9e 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -47,7 +47,7 @@ class InfoRequest < ActiveRecord::Base has_many :track_things, :order => 'created_at desc' has_many :comments, :order => 'created_at' has_many :censor_rules, :order => 'created_at desc' - has_many :exim_logs, :order => 'exim_log_done_id' + has_many :mail_server_logs, :order => 'mail_server_log_done_id' has_tag_string @@ -884,8 +884,8 @@ public info_request_event.track_things_sent_emails.each { |a| a.destroy } info_request_event.destroy end - self.exim_logs.each do |exim_log| - exim_log.destroy + self.mail_server_logs.each do |mail_server_log| + mail_server_log.destroy end self.outgoing_messages.each { |a| a.destroy } self.incoming_messages.each { |a| a.destroy } diff --git a/app/models/exim_log.rb b/app/models/mail_server_log.rb index ace9d422b..e925a2759 100644 --- a/app/models/exim_log.rb +++ b/app/models/mail_server_log.rb @@ -1,18 +1,17 @@ # == Schema Information -# Schema version: 114 +# Schema version: 20121010214348 # -# Table name: exim_logs +# Table name: mail_server_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 +# id :integer not null, primary key +# mail_server_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. @@ -20,34 +19,34 @@ # # $Id: exim_log.rb,v 1.14 2009-09-17 21:10:05 francis Exp $ -class EximLog < ActiveRecord::Base +class MailServerLog < ActiveRecord::Base belongs_to :info_request - belongs_to :exim_log_done + belongs_to :mail_server_log_done # Load in exim log file from disk, or update if we already have it # Assumes files are named with date, rather than cyclically. # Doesn't do anything if file hasn't been modified since it was last loaded. # Note: If you do use rotated log files (rather than files named by date), at some # point old loaded log lines will get deleted in the database. - def EximLog.load_file(file_name) + def MailServerLog.load_file(file_name) is_gz = file_name.include?(".gz") file_name_db = is_gz ? file_name.gsub(".gz", "") : file_name modified = File.stat(file_name).mtime - raise "EximLog.load_file: file not found " + file_name if modified.nil? + raise "MailServerLog.load_file: file not found " + file_name if modified.nil? ActiveRecord::Base.transaction do # see if we already have it - done = EximLogDone.find_by_filename(file_name_db) + done = MailServerLogDone.find_by_filename(file_name_db) if done if modified.utc == done.last_stat.utc # already have that, nothing to do return else - EximLog.delete_all "exim_log_done_id = " + done.id.to_s + MailServerLog.delete_all "mail_server_log_done_id = " + done.id.to_s end else - done = EximLogDone.new(:filename => file_name_db) + done = MailServerLogDone.new(:filename => file_name_db) end done.last_stat = modified # update done structure so we know when we last read this file @@ -66,7 +65,7 @@ class EximLog < ActiveRecord::Base end # Scan the file - def EximLog.load_exim_log_data(f, done) + def MailServerLog.load_exim_log_data(f, done) order = 0 f.each do |line| order = order + 1 @@ -74,7 +73,7 @@ class EximLog < ActiveRecord::Base for email in emails info_request = InfoRequest.find_by_incoming_email(email) if info_request - info_request.exim_logs.create!(:line => line, :order => order, :exim_log_done => done) + info_request.mail_server_logs.create!(:line => line, :order => order, :mail_server_log_done => done) else puts "Warning: Could not find request with email #{email}" end @@ -82,7 +81,7 @@ class EximLog < ActiveRecord::Base end end - def EximLog.load_postfix_log_data(f, done) + def MailServerLog.load_postfix_log_data(f, done) order = 0 emails = scan_for_postfix_queue_ids(f) # Go back to the beginning of the file @@ -94,7 +93,7 @@ class EximLog < ActiveRecord::Base emails[queue_id].each do |email| info_request = InfoRequest.find_by_incoming_email(email) if info_request - info_request.exim_logs.create!(:line => line, :order => order, :exim_log_done => done) + info_request.mail_server_logs.create!(:line => line, :order => order, :mail_server_log_done => done) else puts "Warning: Could not find request with email #{email}" end @@ -103,7 +102,7 @@ class EximLog < ActiveRecord::Base end end - def EximLog.scan_for_postfix_queue_ids(f) + def MailServerLog.scan_for_postfix_queue_ids(f) result = {} f.each do |line| emails = email_addresses_on_line(line) @@ -115,17 +114,17 @@ class EximLog < ActiveRecord::Base end # Retuns nil if there is no queue id - def EximLog.extract_postfix_queue_id_from_syslog_line(line) + def MailServerLog.extract_postfix_queue_id_from_syslog_line(line) # Assume the log file was written using syslog and parse accordingly m = SyslogProtocol.parse("<13>" + line).content.match(/^\S+: (\S+):/) m[1] if m end - def EximLog.email_addresses_on_line(line) + def MailServerLog.email_addresses_on_line(line) line.scan(/request-[^\s]+@#{Configuration::incoming_email_domain}/).sort.uniq end - def EximLog.request_sent?(ir) + def MailServerLog.request_sent?(ir) case(Configuration::mta_log_type.to_sym) when :exim request_exim_sent?(ir) @@ -137,17 +136,17 @@ class EximLog < ActiveRecord::Base end # Look at the log for a request and check that an email was delivered - def EximLog.request_exim_sent?(ir) + def MailServerLog.request_exim_sent?(ir) # Look for line showing request was sent found = false - ir.exim_logs.each do |exim_log| + ir.mail_server_logs.each do |mail_server_log| test_outgoing = " <= " + ir.incoming_email + " " - if exim_log.line.include?(test_outgoing) + if mail_server_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) - $stderr.puts("unexpected parsing of exim line: [#{exim_log.line.chomp}]") + if !mail_server_log.line.include?(envelope_from) + $stderr.puts("unexpected parsing of exim line: [#{mail_server_log.line.chomp}]") else found = true end @@ -156,10 +155,10 @@ class EximLog < ActiveRecord::Base found end - def EximLog.request_postfix_sent?(ir) + def MailServerLog.request_postfix_sent?(ir) # dsn=2.0.0 is the magic word that says that postfix delivered the email # See http://tools.ietf.org/html/rfc3464 - ir.exim_logs.any? { |l| l.line.include?("dsn=2.0.0") } + ir.mail_server_logs.any? { |l| l.line.include?("dsn=2.0.0") } end # Check that the last day of requests has been sent in Exim and we got the @@ -173,7 +172,7 @@ class EximLog < ActiveRecord::Base # NB: There can be several emails involved in a request. This just checks that # at least one of them has been succesfully sent. # - def EximLog.check_recent_requests_have_been_sent + def MailServerLog.check_recent_requests_have_been_sent # Get all requests sent for from 2 to 10 days ago. The 2 day gap is # because we load exim log lines via cron at best an hour after they # are made) diff --git a/app/models/exim_log_done.rb b/app/models/mail_server_log_done.rb index 3cedc1379..0dcae37a8 100644 --- a/app/models/exim_log_done.rb +++ b/app/models/mail_server_log_done.rb @@ -1,7 +1,7 @@ # == Schema Information -# Schema version: 114 +# Schema version: 20121010214348 # -# Table name: exim_log_dones +# Table name: mail_server_log_dones # # id :integer not null, primary key # filename :text not null @@ -10,7 +10,6 @@ # updated_at :datetime not null # -# models/exim_log_done.rb: # Stores that a particular exim file has been loaded in, see exim_log.rb # # Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. @@ -18,8 +17,8 @@ # # $Id: exim_log_done.rb,v 1.8 2009-09-17 21:10:05 francis Exp $ -class EximLogDone < ActiveRecord::Base - has_many :exim_logs +class MailServerLogDone < ActiveRecord::Base + has_many :mail_server_logs end diff --git a/app/views/admin_request/show.rhtml b/app/views/admin_request/show.rhtml index d0c0b0594..bea808bc8 100644 --- a/app/views/admin_request/show.rhtml +++ b/app/views/admin_request/show.rhtml @@ -217,11 +217,11 @@ <p><i>(Lines containing the request incoming email address, updated hourly.)</i></p> -<% for exim_log_done_id, exim_logs in @info_request.exim_logs.group_by(&:exim_log_done_id) %> - <!-- <h3><%=h exim_logs[0].exim_log_done.filename %></h3> --> - <pre><% for exim_log in exim_logs %><%=h exim_log.line%><% end %></pre> +<% for mail_server_log_done_id, mail_server_logs in @info_request.mail_server_logs.group_by(&:mail_server_log_done_id) %> + <!-- <h3><%=h mail_server_logs[0].mail_server_log_done.filename %></h3> --> + <pre><% for mail_server_log in mail_server_logs %><%=h mail_server_log.line%><% end %></pre> <% end %> -<% if @info_request.exim_logs.size == 0 %> +<% if @info_request.mail_server_logs.size == 0 %> <p>None (perhaps this is an old or a very new request)</p> <% end %> diff --git a/db/migrate/20121010214348_rename_exim_log_tables.rb b/db/migrate/20121010214348_rename_exim_log_tables.rb new file mode 100644 index 000000000..75fcff065 --- /dev/null +++ b/db/migrate/20121010214348_rename_exim_log_tables.rb @@ -0,0 +1,13 @@ +class RenameEximLogTables < ActiveRecord::Migration + def self.up + rename_table :exim_logs, :mail_server_logs + rename_table :exim_log_dones, :mail_server_log_dones + rename_column :mail_server_logs, :exim_log_done_id, :mail_server_log_done_id + end + + def self.down + rename_table :mail_server_logs, :exim_logs + rename_table :mail_server_log_dones, :exim_log_dones + rename_column :exim_logs, :mail_server_log_done_id, :exim_log_done_id + end +end diff --git a/script/check-recent-requests-sent b/script/check-recent-requests-sent index 588c6b73a..7840dba4a 100755 --- a/script/check-recent-requests-sent +++ b/script/check-recent-requests-sent @@ -2,7 +2,7 @@ cd "`dirname "$0"`" -bundle exec ./runner 'EximLog.check_recent_requests_have_been_sent' +bundle exec ./runner 'MailServerLog.check_recent_requests_have_been_sent' diff --git a/script/load-exim-logs b/script/load-exim-logs index ab21c3bb0..234aecd3b 100755 --- a/script/load-exim-logs +++ b/script/load-exim-logs @@ -14,7 +14,7 @@ then *) f=$(pwd)/$1 ;; esac cd "$LOC" - bundle exec ./runner 'EximLog.load_file("'$f'")' + bundle exec ./runner 'MailServerLog.load_file("'$f'")' exit fi @@ -23,5 +23,5 @@ cd "$LOC" LATEST=$( ls -rt $OPTION_MTA_LOG_PATH 2>/dev/null | tail -3 ) for X in $LATEST do - bundle exec ./runner 'EximLog.load_file("'$X'")' + bundle exec ./runner 'MailServerLog.load_file("'$X'")' done diff --git a/spec/lib/timezone_fixes_spec.rb b/spec/lib/timezone_fixes_spec.rb index eef7e865c..8dd1ff480 100644 --- a/spec/lib/timezone_fixes_spec.rb +++ b/spec/lib/timezone_fixes_spec.rb @@ -1,6 +1,6 @@ # This is a test of the monkey patches in timezone_fixes.rb -# We use EximLogDone here just as a totally random model that has a datetime type. +# We use MailServerLogDone here just as a totally random model that has a datetime type. require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') @@ -10,8 +10,8 @@ describe "when doing things with timezones" do with_env_tz 'America/New_York' do with_active_record_default_timezone :utc do time = Time.local(2000) - exim_log_done = EximLogDone.create('last_stat' => time, 'filename' => 'dummy') - saved_time = EximLogDone.find(exim_log_done.id).last_stat + mail_server_log_done = MailServerLogDone.create('last_stat' => time, 'filename' => 'dummy') + saved_time = MailServerLogDone.find(mail_server_log_done.id).last_stat assert_equal time, saved_time assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "EST"], time.to_a assert_equal [0, 0, 5, 1, 1, 2000, 6, 1, false, "UTC"], saved_time.to_a @@ -24,8 +24,8 @@ describe "when doing things with timezones" do with_active_record_default_timezone :utc do Time.use_zone 'Central Time (US & Canada)' do time = Time.zone.local(2000) - exim_log_done = EximLogDone.create('last_stat' => time, 'filename' => 'dummy') - saved_time = EximLogDone.find(exim_log_done.id).last_stat + mail_server_log_done = MailServerLogDone.create('last_stat' => time, 'filename' => 'dummy') + saved_time = MailServerLogDone.find(mail_server_log_done.id).last_stat assert_equal time, saved_time assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "CST"], time.to_a assert_equal [0, 0, 6, 1, 1, 2000, 6, 1, false, "UTC"], saved_time.to_a @@ -39,8 +39,8 @@ describe "when doing things with timezones" do #it "should preserve time objects with UTC time conversion to default timezone local" do # with_env_tz 'America/New_York' do # time = Time.utc(2000) - # exim_log_done = EximLogDone.create('last_stat' => time, 'filename' => 'dummy') - # saved_time = EximLogDone.find(exim_log_done.id).last_stat + # mail_server_log_done = MailServerLogDone.create('last_stat' => time, 'filename' => 'dummy') + # saved_time = MailServerLogDone.find(mail_server_log_done.id).last_stat # assert_equal time, saved_time # assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "UTC"], time.to_a # assert_equal [0, 0, 19, 31, 12, 1999, 5, 365, false, "EST"], saved_time.to_a @@ -52,8 +52,8 @@ describe "when doing things with timezones" do with_active_record_default_timezone :local do Time.use_zone 'Central Time (US & Canada)' do time = Time.zone.local(2000) - exim_log_done = EximLogDone.create('last_stat' => time, 'filename' => 'dummy') - saved_time = EximLogDone.find(exim_log_done.id).last_stat + mail_server_log_done = MailServerLogDone.create('last_stat' => time, 'filename' => 'dummy') + saved_time = MailServerLogDone.find(mail_server_log_done.id).last_stat assert_equal time, saved_time assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "CST"], time.to_a assert_equal [0, 0, 1, 1, 1, 2000, 6, 1, false, "EST"], saved_time.to_a diff --git a/spec/models/exim_log_spec.rb b/spec/models/mail_server_log_spec.rb index 43796cf17..cad64f7ff 100644 --- a/spec/models/exim_log_spec.rb +++ b/spec/models/mail_server_log_spec.rb @@ -1,6 +1,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -describe EximLog do +describe MailServerLog do describe ".load_file" do before :each do Configuration.stub!(:incoming_email_domain).and_return("example.com") @@ -17,14 +17,14 @@ describe EximLog do it "loads relevant lines of an uncompressed exim log file" do File.should_receive(:open).with("/var/log/exim4/exim-mainlog-2012-10-10", "r").and_return(log) InfoRequest.should_receive(:find_by_incoming_email).with("request-1234@example.com").twice.and_return(ir) - EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") + MailServerLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") - ir.exim_logs.count.should == 2 - log = ir.exim_logs[0] + ir.mail_server_logs.count.should == 2 + log = ir.mail_server_logs[0] log.order.should == 1 log.line.should == "This is a line of a logfile relevant to foi+request-1234@example.com" - log = ir.exim_logs[1] + log = ir.mail_server_logs[1] log.order.should == 2 log.line.should == "This is the second line for the same foi+request-1234@example.com email address" end @@ -32,33 +32,33 @@ describe EximLog do it "doesn't load the log file twice if it's unchanged" do File.should_receive(:open).with("/var/log/exim4/exim-mainlog-2012-10-10", "r").once.and_return([]) - EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") - EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") + MailServerLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") + MailServerLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") end it "loads the log file again if it's changed" do File.should_receive(:open).with("/var/log/exim4/exim-mainlog-2012-10-10", "r").twice.and_return([]) - EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") + MailServerLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") File.stub_chain(:stat, :mtime).and_return(DateTime.new(2012, 10, 11)) - EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") + MailServerLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") end it "doesn't end up with two copies of each line when the same file is actually loaded twice" do File.should_receive(:open).with("/var/log/exim4/exim-mainlog-2012-10-10", "r").twice.and_return(log) InfoRequest.should_receive(:find_by_incoming_email).with("request-1234@example.com").any_number_of_times.and_return(ir) - EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") - ir.exim_logs.count.should == 2 + MailServerLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") + ir.mail_server_logs.count.should == 2 File.stub_chain(:stat, :mtime).and_return(DateTime.new(2012, 10, 11)) - EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") - ir.exim_logs.count.should == 2 + MailServerLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10") + ir.mail_server_logs.count.should == 2 end it "easily handles gzip compress log files" do File.should_not_receive(:open) Zlib::GzipReader.should_receive(:open).with("/var/log/exim4/exim-mainlog-2012-10-10.gz").and_return([]) - EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10.gz") + MailServerLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10.gz") end end @@ -83,31 +83,31 @@ describe EximLog do ir2 = info_requests(:naughty_chicken_request) InfoRequest.should_receive(:find_by_incoming_email).with("request-14-e0e09f97@example.com").any_number_of_times.and_return(ir1) InfoRequest.should_receive(:find_by_incoming_email).with("request-10-1234@example.com").any_number_of_times.and_return(ir2) - EximLog.load_postfix_log_data(log, EximLogDone.new(:filename => "foo", :last_stat => DateTime.now)) + MailServerLog.load_postfix_log_data(log, MailServerLogDone.new(:filename => "foo", :last_stat => DateTime.now)) # TODO: Check that each log line is attached to the correct request - ir1.exim_logs.count.should == 5 - ir1.exim_logs[0].order.should == 1 - ir1.exim_logs[0].line.should == "Oct 3 16:39:35 host postfix/pickup[2257]: CB55836EE58C: uid=1003 from=<foitest+request-14-e0e09f97@example.com>" - ir1.exim_logs[1].order.should == 2 - ir1.exim_logs[1].line.should == "Oct 3 16:39:35 host postfix/cleanup[7674]: CB55836EE58C: message-id=<ogm-15+506bdda7a4551-20ee@example.com>" - ir1.exim_logs[2].order.should == 4 - ir1.exim_logs[2].line.should == "Oct 3 16:39:35 host postfix/qmgr[15615]: CB55836EE58C: from=<foitest+request-14-e0e09f97@example.com>, size=1695, nrcpt=1 (queue active)" - ir1.exim_logs[3].order.should == 5 - ir1.exim_logs[3].line.should == "Oct 3 16:39:38 host postfix/smtp[7676]: CB55836EE58C: to=<foi@some.gov.au>, relay=aspmx.l.google.com[74.125.25.27]:25, delay=2.5, delays=0.13/0.02/1.7/0.59, dsn=2.0.0, status=sent (250 2.0.0 OK 1349246383 j9si1676296paw.328)" - ir1.exim_logs[4].order.should == 7 - ir1.exim_logs[4].line.should == "Oct 3 16:39:38 host postfix/qmgr[15615]: CB55836EE58C: removed" - ir2.exim_logs.count.should == 2 - ir2.exim_logs[0].order.should == 3 - ir2.exim_logs[0].line.should == "Oct 3 16:39:35 host postfix/qmgr[1673]: 9634B16F7F7: from=<foitest+request-10-1234@example.com>, size=368, nrcpt=1 (queue active)" - ir2.exim_logs[1].order.should == 6 - ir2.exim_logs[1].line.should == "Oct 3 16:39:38 host postfix/smtp[1681]: 9634B16F7F7: to=<kdent@example.com>, relay=none, delay=46, status=deferred (connect to 216.150.150.131[216.150.150.131]: No route to host)" + ir1.mail_server_logs.count.should == 5 + ir1.mail_server_logs[0].order.should == 1 + ir1.mail_server_logs[0].line.should == "Oct 3 16:39:35 host postfix/pickup[2257]: CB55836EE58C: uid=1003 from=<foitest+request-14-e0e09f97@example.com>" + ir1.mail_server_logs[1].order.should == 2 + ir1.mail_server_logs[1].line.should == "Oct 3 16:39:35 host postfix/cleanup[7674]: CB55836EE58C: message-id=<ogm-15+506bdda7a4551-20ee@example.com>" + ir1.mail_server_logs[2].order.should == 4 + ir1.mail_server_logs[2].line.should == "Oct 3 16:39:35 host postfix/qmgr[15615]: CB55836EE58C: from=<foitest+request-14-e0e09f97@example.com>, size=1695, nrcpt=1 (queue active)" + ir1.mail_server_logs[3].order.should == 5 + ir1.mail_server_logs[3].line.should == "Oct 3 16:39:38 host postfix/smtp[7676]: CB55836EE58C: to=<foi@some.gov.au>, relay=aspmx.l.google.com[74.125.25.27]:25, delay=2.5, delays=0.13/0.02/1.7/0.59, dsn=2.0.0, status=sent (250 2.0.0 OK 1349246383 j9si1676296paw.328)" + ir1.mail_server_logs[4].order.should == 7 + ir1.mail_server_logs[4].line.should == "Oct 3 16:39:38 host postfix/qmgr[15615]: CB55836EE58C: removed" + ir2.mail_server_logs.count.should == 2 + ir2.mail_server_logs[0].order.should == 3 + ir2.mail_server_logs[0].line.should == "Oct 3 16:39:35 host postfix/qmgr[1673]: 9634B16F7F7: from=<foitest+request-10-1234@example.com>, size=368, nrcpt=1 (queue active)" + ir2.mail_server_logs[1].order.should == 6 + ir2.mail_server_logs[1].line.should == "Oct 3 16:39:38 host postfix/smtp[1681]: 9634B16F7F7: to=<kdent@example.com>, relay=none, delay=46, status=deferred (connect to 216.150.150.131[216.150.150.131]: No route to host)" end end describe ".scan_for_postfix_queue_ids" do it "returns the queue ids of interest with the connected email addresses" do Configuration.stub!(:incoming_email_domain).and_return("example.com") - EximLog.scan_for_postfix_queue_ids(log).should == { + MailServerLog.scan_for_postfix_queue_ids(log).should == { "CB55836EE58C" => ["request-14-e0e09f97@example.com"], "9634B16F7F7" => ["request-10-1234@example.com"] } @@ -116,21 +116,21 @@ describe EximLog do describe ".extract_postfix_queue_id_from_syslog_line" do it "returns nil if there is no queue id" do - EximLog.extract_postfix_queue_id_from_syslog_line("Oct 7 07:16:48 kedumba postfix/smtp[14294]: connect to mail.neilcopp.com.au[110.142.151.66]:25: Connection refused").should be_nil + MailServerLog.extract_postfix_queue_id_from_syslog_line("Oct 7 07:16:48 kedumba postfix/smtp[14294]: connect to mail.neilcopp.com.au[110.142.151.66]:25: Connection refused").should be_nil end end describe ".request_postfix_sent?" do it "returns true when the logs say the message was sent" do ir = info_requests(:fancy_dog_request) - ir.exim_logs.create!(:line => "Oct 10 16:58:38 kedumba postfix/smtp[26358]: A664436F218D: to=<contact@openaustraliafoundation.org.au>, relay=aspmx.l.google.com[74.125.25.26]:25, delay=2.7, delays=0.16/0.02/1.8/0.67, dsn=2.0.0, status=sent (250 2.0.0 OK 1349848723 e6si653316paw.346)", :order => 1) - EximLog.request_postfix_sent?(ir).should be_true + ir.mail_server_logs.create!(:line => "Oct 10 16:58:38 kedumba postfix/smtp[26358]: A664436F218D: to=<contact@openaustraliafoundation.org.au>, relay=aspmx.l.google.com[74.125.25.26]:25, delay=2.7, delays=0.16/0.02/1.8/0.67, dsn=2.0.0, status=sent (250 2.0.0 OK 1349848723 e6si653316paw.346)", :order => 1) + MailServerLog.request_postfix_sent?(ir).should be_true end it "returns false when the logs say the message hasn't been sent" do ir = info_requests(:fancy_dog_request) - ir.exim_logs.create!(:line => "Oct 10 13:22:49 kedumba postfix/smtp[11876]: 6FB9036F1307: to=<foo@example.com>, relay=mta7.am0.yahoodns.net[74.6.136.244]:25, delay=1.5, delays=0.03/0/0.48/1, dsn=5.0.0, status=bounced (host mta7.am0.yahoodns.net[74.6.136.244] said: 554 delivery error: dd Sorry your message to foo@example.com cannot be delivered. This account has been disabled or discontinued [#102]. - mta1272.mail.sk1.yahoo.com (in reply to end of DATA command))", :order => 1) - EximLog.request_postfix_sent?(ir).should be_false + ir.mail_server_logs.create!(:line => "Oct 10 13:22:49 kedumba postfix/smtp[11876]: 6FB9036F1307: to=<foo@example.com>, relay=mta7.am0.yahoodns.net[74.6.136.244]:25, delay=1.5, delays=0.03/0/0.48/1, dsn=5.0.0, status=bounced (host mta7.am0.yahoodns.net[74.6.136.244] said: 554 delivery error: dd Sorry your message to foo@example.com cannot be delivered. This account has been disabled or discontinued [#102]. - mta1272.mail.sk1.yahoo.com (in reply to end of DATA command))", :order => 1) + MailServerLog.request_postfix_sent?(ir).should be_false end end end |