aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Landauer <matthew@openaustralia.org>2012-10-10 13:45:10 +1100
committerMatthew Landauer <matthew@openaustralia.org>2012-10-10 13:45:10 +1100
commit089ce980170b1b2f96ed6b86c26e4d6e2069f39d (patch)
tree1bd93255d12ba05f02ffad3707c1f5d8dfe7c3f2
parent6cf5fb63e07259ba5a47da7dc164bd891eb2806f (diff)
Extract postfix queue ids from logs
-rw-r--r--app/models/exim_log.rb13
-rw-r--r--spec/models/exim_log_spec.rb22
2 files changed, 35 insertions, 0 deletions
diff --git a/app/models/exim_log.rb b/app/models/exim_log.rb
index ac3cb11a3..e7f4a4e8d 100644
--- a/app/models/exim_log.rb
+++ b/app/models/exim_log.rb
@@ -74,6 +74,19 @@ class EximLog < ActiveRecord::Base
end
end
+ def EximLog.scan_for_postfix_queue_ids(f)
+ result = {}
+ f.each do |line|
+ email_domain = Configuration::incoming_email_domain
+ emails = line.scan(/request-[^\s]+@#{email_domain}/).sort.uniq
+ # Assume the log file was written using syslog and parse accordingly
+ queue_id = SyslogProtocol.parse("<13>" + line).content.match(/^\S+: (\S+):/)[1]
+ result[queue_id] = [] unless result.has_key?(queue_id)
+ result[queue_id] = (result[queue_id] + emails).uniq
+ end
+ result
+ 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
diff --git a/spec/models/exim_log_spec.rb b/spec/models/exim_log_spec.rb
index 48dc9876e..563ca5d06 100644
--- a/spec/models/exim_log_spec.rb
+++ b/spec/models/exim_log_spec.rb
@@ -61,4 +61,26 @@ describe EximLog do
EximLog.load_file("/var/log/exim4/exim-mainlog-2012-10-10.gz")
end
end
+
+ context "Postfix" do
+ let(:log) {[
+"Oct 3 16:39:35 host postfix/pickup[2257]: CB55836EE58C: uid=1003 from=<foitest+request-14-e0e09f97@example.com>",
+"Oct 3 16:39:35 host postfix/cleanup[7674]: CB55836EE58C: message-id=<ogm-15+506bdda7a4551-20ee@example.com>",
+"Oct 3 16:39:35 host postfix/qmgr[1673]: 9634B16F7F7: from=<foitest+request-10-1234@example.com>, size=368, nrcpt=1 (queue active)",
+"Oct 3 16:39:35 host postfix/qmgr[15615]: CB55836EE58C: from=<foitest+request-14-e0e09f97@example.com>, size=1695, nrcpt=1 (queue active)",
+"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)",
+"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)",
+"Oct 3 16:39:38 host postfix/qmgr[15615]: CB55836EE58C: removed",
+ ]}
+
+ 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 == {
+ "CB55836EE58C" => ["request-14-e0e09f97@example.com"],
+ "9634B16F7F7" => ["request-10-1234@example.com"]
+ }
+ end
+ end
+ end
end