diff options
-rw-r--r-- | app/models/mail_server_log.rb | 4 | ||||
-rw-r--r-- | spec/models/mail_server_log_spec.rb | 9 |
2 files changed, 10 insertions, 3 deletions
diff --git a/app/models/mail_server_log.rb b/app/models/mail_server_log.rb index f220132cb..8a978ae07 100644 --- a/app/models/mail_server_log.rb +++ b/app/models/mail_server_log.rb @@ -120,8 +120,10 @@ class MailServerLog < ActiveRecord::Base m[1] if m end + # We also check the email prefix so that we could, for instance, separately handle a staging and production + # instance running on the same server with different email prefixes. def MailServerLog.email_addresses_on_line(line) - line.scan(/request-[^\s]+@#{Configuration::incoming_email_domain}/).sort.uniq + line.scan(/#{Regexp::quote(Configuration::incoming_email_prefix)}request-[^\s]+@#{Configuration::incoming_email_domain}/).sort.uniq end def MailServerLog.request_sent?(ir) diff --git a/spec/models/mail_server_log_spec.rb b/spec/models/mail_server_log_spec.rb index f4de7ee68..3f87b76f1 100644 --- a/spec/models/mail_server_log_spec.rb +++ b/spec/models/mail_server_log_spec.rb @@ -65,21 +65,26 @@ describe MailServerLog do describe ".email_addresses_on_line" do before :each do Configuration.stub!(:incoming_email_domain).and_return("example.com") + Configuration.stub!(:incoming_email_prefix).and_return("foi+") end it "recognises a single incoming email" do MailServerLog.email_addresses_on_line("a random log line foi+request-14-e0e09f97@example.com has an email").should == - ["request-14-e0e09f97@example.com"] + ["foi+request-14-e0e09f97@example.com"] end it "recognises two email addresses on the same line" do MailServerLog.email_addresses_on_line("two email addresses here foi+request-10-1234@example.com and foi+request-14-e0e09f97@example.com").should == - ["request-10-1234@example.com", "request-14-e0e09f97@example.com"] + ["foi+request-10-1234@example.com", "foi+request-14-e0e09f97@example.com"] end it "returns an empty array when there is an email address from a different domain" do MailServerLog.email_addresses_on_line("other foi+request-10-1234@foo.com").should be_empty end + + it "ignores an email with a different prefix" do + MailServerLog.email_addresses_on_line("foitest+request-14-e0e09f97@example.com").should be_empty + end end context "Postfix" do |