Method: Mail::Message#delivered_to

Defined in:
lib/kns_email_endpoint/core_extensions/message.rb

#delivered_toObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kns_email_endpoint/core_extensions/message.rb', line 13

def delivered_to
  # Messages can be sent to multiple people AND if it was forwarded will have multiple
  # Delivered-To headers. What this bit of code does is take the
  # intersection of the "to" recipients and the "Delivered-To" recipients to find
  # out who the message was actually delivered to. There will almost never
  # be more than one recipient in that intersection, but if there is, we'll just 
  # return the first.
  delivered_to_headers = []
  self.header_fields.each { |f| delivered_to_headers << f.value if f.name == "Delivered-To"} 
  actual_to = self.to.to_set.intersection delivered_to_headers
  return actual_to.first
end