aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mail_handler/backends
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2012-12-04 09:53:16 +0000
committerLouise Crow <louise.crow@gmail.com>2012-12-04 09:53:16 +0000
commit9dfe9de140242c176eef8af65d78ced3f2992cc1 (patch)
treea823ea107091fa496796b00f738fb92f2745844e /lib/mail_handler/backends
parent30dd01f931ae3dea9a56812387bfea2544818e31 (diff)
Move method for getting the to, cc and envelope-to addresses of a mail to the mail handler.
Diffstat (limited to 'lib/mail_handler/backends')
-rw-r--r--lib/mail_handler/backends/mail_backend.rb7
-rw-r--r--lib/mail_handler/backends/tmail_backend.rb6
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/mail_handler/backends/mail_backend.rb b/lib/mail_handler/backends/mail_backend.rb
index 4a8bd446c..2b1cef0d4 100644
--- a/lib/mail_handler/backends/mail_backend.rb
+++ b/lib/mail_handler/backends/mail_backend.rb
@@ -77,6 +77,13 @@ module MailHandler
end
end
+ def get_all_addresses(mail)
+ envelope_to = mail['envelope-to'] ? [mail['envelope-to'].value] : []
+ ((mail.to || []) +
+ (mail.cc || []) +
+ (envelope_to || [])).uniq
+ 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 445a81124..b8fdb2c88 100644
--- a/lib/mail_handler/backends/tmail_backend.rb
+++ b/lib/mail_handler/backends/tmail_backend.rb
@@ -59,6 +59,12 @@ module MailHandler
mail.from_name_if_present
end
+ def get_all_addresses(mail)
+ ((mail.to || []) +
+ (mail.cc || []) +
+ (mail.envelope_to || [])).uniq
+ 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"