aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2012-12-04 10:35:22 +0000
committerLouise Crow <louise.crow@gmail.com>2012-12-04 10:35:22 +0000
commit6052df14bab5fe82cd5ccf1979dbfc6d6ab3befa (patch)
tree1ef78d352d1df179da67912e8239a87afc02b70b
parent700ba5932ff1ed92500d5c5b122b08172fea7d30 (diff)
Add methods for finding out if there is an empty return path on a mail and getting the auto-submitted field.
-rw-r--r--lib/mail_handler/backends/mail_backend.rb10
-rw-r--r--lib/mail_handler/backends/tmail_backend.rb10
-rw-r--r--spec/lib/mail_handler/mail_handler_spec.rb32
3 files changed, 52 insertions, 0 deletions
diff --git a/lib/mail_handler/backends/mail_backend.rb b/lib/mail_handler/backends/mail_backend.rb
index 2b1cef0d4..b86f84cef 100644
--- a/lib/mail_handler/backends/mail_backend.rb
+++ b/lib/mail_handler/backends/mail_backend.rb
@@ -84,6 +84,16 @@ module MailHandler
(envelope_to || [])).uniq
end
+ def empty_return_path?(mail)
+ return false if mail['return-path'].nil?
+ return true if mail['return-path'].value.blank?
+ return false
+ end
+
+ def get_auto_submitted(mail)
+ mail['auto-submitted'] ? mail['auto-submitted'].value : nil
+ end
+
# Format
def address_from_name_and_email(name, email)
if !MySociety::Validate.is_valid_email(email)
diff --git a/lib/mail_handler/backends/tmail_backend.rb b/lib/mail_handler/backends/tmail_backend.rb
index b8fdb2c88..e725f7e9f 100644
--- a/lib/mail_handler/backends/tmail_backend.rb
+++ b/lib/mail_handler/backends/tmail_backend.rb
@@ -65,6 +65,16 @@ module MailHandler
(mail.envelope_to || [])).uniq
end
+ def empty_return_path?(mail)
+ return false if mail['return-path'].nil?
+ return true if mail['return-path'].addr.to_s == '<>'
+ return false
+ end
+
+ def get_auto_submitted(mail)
+ mail['auto-submitted'] ? mail['auto-submitted'].body : nil
+ end
+
def address_from_name_and_email(name, email)
if !MySociety::Validate.is_valid_email(email)
raise "invalid email " + email + " passed to address_from_name_and_email"
diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb
index 4603b695f..e673c5bf0 100644
--- a/spec/lib/mail_handler/mail_handler_spec.rb
+++ b/spec/lib/mail_handler/mail_handler_spec.rb
@@ -106,3 +106,35 @@ describe 'when asked for all the addresses a mail has been sent to' do
MailHandler.get_all_addresses(mail).should == ["request-5555-xxxxxxxx@whatdotheyknow.com"]
end
end
+
+describe 'when asked for auto_submitted' do
+
+ it 'should return a string value for an email with an auto-submitted header' do
+ mail = get_fixture_mail('autoresponse-header.email')
+ MailHandler.get_auto_submitted(mail).should == 'auto-replied'
+ end
+
+ it 'should return a nil value for an email with no auto-submitted header' do
+ mail = get_fixture_mail('incoming-request-plain.email')
+ MailHandler.get_auto_submitted(mail).should == nil
+ end
+
+end
+
+describe 'when asked if there is an empty return path' do
+
+ it 'should return true if there is an empty return-path specified' do
+ mail = get_fixture_mail('empty-return-path.email')
+ MailHandler.empty_return_path?(mail).should == true
+ end
+
+ it 'should return false if there is no return-path header' do
+ mail = get_fixture_mail('incoming-request-attach-attachments.email')
+ MailHandler.empty_return_path?(mail).should == false
+ end
+
+ it 'should return false if there is a return path address' do
+ mail = get_fixture_mail('autoresponse-header.email')
+ MailHandler.empty_return_path?(mail).should == false
+ end
+end