diff --git a/lib/mail_handler/backends/mail_backend.rb b/lib/mail_handler/backends/mail_backend.rb index ae1f79307e4..9354f9ff882 100644 --- a/lib/mail_handler/backends/mail_backend.rb +++ b/lib/mail_handler/backends/mail_backend.rb @@ -399,19 +399,12 @@ def address_from_string(string) end def get_emails_within_received_headers(email) - received_addresses = [] - received_headers = email['Received'] - if received_headers - if received_headers.class == Mail::Field - received_header_string = received_headers.to_s - else - received_header_string = received_headers. - map { | header | header.to_s } * ' ' - end - received_addresses = received_header_string. - scan(MySociety::Validate.email_find_regexp).flatten - end - received_addresses + received_headers = Array(email['Received']) + return [] if received_headers.empty? + received_headers.map(&:to_s). + join(' '). + scan(MySociety::Validate.email_find_regexp). + flatten end end end