aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/exim_log.rb10
-rw-r--r--spec/models/exim_log_spec.rb1
2 files changed, 10 insertions, 1 deletions
diff --git a/app/models/exim_log.rb b/app/models/exim_log.rb
index 8a02d8b06..0012441de 100644
--- a/app/models/exim_log.rb
+++ b/app/models/exim_log.rb
@@ -27,7 +27,7 @@ class EximLog < ActiveRecord::Base
# 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.
- def EximLog.load_file(file_name, type = :exim)
+ def EximLog.load_file(file_name)
is_gz = file_name.include?(".gz")
file_name_db = is_gz ? file_name.gsub(".gz", "") : file_name
@@ -52,6 +52,7 @@ class EximLog < ActiveRecord::Base
done.save!
f = is_gz ? Zlib::GzipReader.open(file_name) : File.open(file_name, 'r')
+ type = detect_mta_log_type(f)
case(type)
when :exim
load_exim_log_data(f, done)
@@ -63,6 +64,13 @@ class EximLog < ActiveRecord::Base
end
end
+ # Unbelievably dumb heuristic for detecting whether this is an exim or a postfix log
+ def EximLog.detect_mta_log_type(f)
+ r = (f.readline =~ /postfix/) ? :postfix : :exim
+ f.rewind
+ r
+ end
+
# Scan the file
def EximLog.load_exim_log_data(f, done)
order = 0
diff --git a/spec/models/exim_log_spec.rb b/spec/models/exim_log_spec.rb
index 87aa6d610..b9826be72 100644
--- a/spec/models/exim_log_spec.rb
+++ b/spec/models/exim_log_spec.rb
@@ -5,6 +5,7 @@ describe EximLog do
before :each do
Configuration.stub!(:incoming_email_domain).and_return("example.com")
File.stub_chain(:stat, :mtime).and_return(DateTime.new(2012, 10, 10))
+ EximLog.stub!(:detect_mta_log_type).and_return(:exim)
end
let(:log) {[