Module: Mail::CommonAddress
- Included in:
- BccField, CcField, FromField, ReplyToField, ResentBccField, ResentCcField, ResentFromField, ResentSenderField, ResentToField, ReturnPathField, SenderField, ToField
- Defined in:
- lib/mail/fields/common/common_address.rb
Overview
:nodoc:
Instance Method Summary collapse
- #<<(val) ⇒ Object
-
#addresses ⇒ Object
Returns the address string of all the addresses in the address list.
-
#addrs ⇒ Object
Returns the actual address objects in the address list.
- #charset ⇒ Object
- #default ⇒ Object
-
#display_names ⇒ Object
Returns the display name of all the addresses in the address list.
-
#each ⇒ Object
Allows you to iterate through each address object in the syntax tree.
- #encode_if_needed(val) ⇒ Object
-
#formatted ⇒ Object
Returns the formatted string of all the addresses in the address list.
-
#group_addresses ⇒ Object
Returns the addresses that are part of groups.
-
#group_names ⇒ Object
Returns the name of all the groups in a string.
-
#groups ⇒ Object
Returns a hash of group name => address strings for the address list.
- #parse(val = value) ⇒ Object
Instance Method Details
#<<(val) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/mail/fields/common/common_address.rb', line 77 def <<(val) case when val.nil? raise ArgumentError, "Need to pass an address to <<" when val.blank? parse(encoded) else parse((formatted + [val]).join(", ")) end end |
#addresses ⇒ Object
Returns the address string of all the addresses in the address list
31 32 33 34 |
# File 'lib/mail/fields/common/common_address.rb', line 31 def addresses list = tree.addresses.map { |a| a.address } Mail::AddressContainer.new(self, list) end |
#addrs ⇒ Object
Returns the actual address objects in the address list
49 50 51 52 |
# File 'lib/mail/fields/common/common_address.rb', line 49 def addrs list = tree.addresses Mail::AddressContainer.new(self, list) end |
#charset ⇒ Object
15 16 17 |
# File 'lib/mail/fields/common/common_address.rb', line 15 def charset @charset end |
#default ⇒ Object
73 74 75 |
# File 'lib/mail/fields/common/common_address.rb', line 73 def default addresses end |
#display_names ⇒ Object
Returns the display name of all the addresses in the address list
43 44 45 46 |
# File 'lib/mail/fields/common/common_address.rb', line 43 def display_names list = tree.addresses.map { |a| a.display_name } Mail::AddressContainer.new(self, list) end |
#each ⇒ Object
Allows you to iterate through each address object in the syntax tree
24 25 26 27 28 |
# File 'lib/mail/fields/common/common_address.rb', line 24 def each tree.addresses.each do |address| yield(address) end end |
#encode_if_needed(val) ⇒ Object
19 20 21 |
# File 'lib/mail/fields/common/common_address.rb', line 19 def encode_if_needed(val) Encodings.address_encode(val, charset) end |
#formatted ⇒ Object
Returns the formatted string of all the addresses in the address list
37 38 39 40 |
# File 'lib/mail/fields/common/common_address.rb', line 37 def formatted list = tree.addresses.map { |a| a.format } Mail::AddressContainer.new(self, list) end |
#group_addresses ⇒ Object
Returns the addresses that are part of groups
64 65 66 |
# File 'lib/mail/fields/common/common_address.rb', line 64 def group_addresses groups.map { |k,v| v.map { |a| a.format } }.flatten end |
#group_names ⇒ Object
Returns the name of all the groups in a string
69 70 71 |
# File 'lib/mail/fields/common/common_address.rb', line 69 def group_names # :nodoc: tree.group_names end |
#groups ⇒ Object
Returns a hash of group name => address strings for the address list
55 56 57 58 59 60 61 |
# File 'lib/mail/fields/common/common_address.rb', line 55 def groups @groups = Hash.new tree.group_recipients.each do |group| @groups[group.group_name.text_value.to_str] = get_group_addresses(group.group_list) end @groups end |
#parse(val = value) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/mail/fields/common/common_address.rb', line 7 def parse(val = value) unless val.blank? @tree = AddressList.new(encode_if_needed(val)) else nil end end |