aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailbox/lib/action_mailbox/mail_ext/addresses.rb
blob: 5eab1feb3d563328a29c76abc4ab1d00353c59a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module Mail
  class Message
    def from_address
      header[:from]&.address_list&.addresses&.first
    end

    def recipients_addresses
      to_addresses + cc_addresses + bcc_addresses + x_original_to_addresses
    end

    def to_addresses
      Array(header[:to]&.address_list&.addresses)
    end

    def cc_addresses
      Array(header[:cc]&.address_list&.addresses)
    end

    def bcc_addresses
      Array(header[:bcc]&.address_list&.addresses)
    end

    def x_original_to_addresses
      Array(header[:x_original_to]).collect { |header| Mail::Address.new header.to_s }
    end
  end
end