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)

Instance Method Details

- (Object) <<(val)



83
84
85
86
87
88
89
90
91
92
# File 'lib/mail/fields/common/common_address.rb', line 83

def <<(val)
  case
  when val.nil?
    raise ArgumentError, "Need to pass an address to <<"
  when val.blank?
    parse(encoded)
  else
    self.value = [self.value, val].reject {|a| a.blank? }.join(", ")
  end
end

- (Object) addresses

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 = address_list.addresses.map { |a| a.address }
  Mail::AddressContainer.new(self, list)
end

- (Object) addrs

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 = address_list.addresses
  Mail::AddressContainer.new(self, list)
end

- (Object) charset



15
16
17
# File 'lib/mail/fields/common/common_address.rb', line 15

def charset
  @charset
end

- (Object) decoded_group_addresses

Returns a list of decoded group addresses



65
66
67
# File 'lib/mail/fields/common/common_address.rb', line 65

def decoded_group_addresses
  groups.map { |k,v| v.map { |a| a.decoded } }.flatten
end

- (Object) default



79
80
81
# File 'lib/mail/fields/common/common_address.rb', line 79

def default
  addresses
end

- (Object) display_names

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 = address_list.addresses.map { |a| a.display_name }
  Mail::AddressContainer.new(self, list)
end

- (Object) each

Allows you to iterate through each address object in the address_list



24
25
26
27
28
# File 'lib/mail/fields/common/common_address.rb', line 24

def each
  address_list.addresses.each do |address|
    yield(address)
  end
end

- (Object) encode_if_needed(val)



19
20
21
# File 'lib/mail/fields/common/common_address.rb', line 19

def encode_if_needed(val)
  Encodings.address_encode(val, charset)
end

- (Object) encoded_group_addresses

Returns a list of encoded group addresses



70
71
72
# File 'lib/mail/fields/common/common_address.rb', line 70

def encoded_group_addresses
  groups.map { |k,v| v.map { |a| a.encoded } }.flatten
end

- (Object) formatted

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 = address_list.addresses.map { |a| a.format }
  Mail::AddressContainer.new(self, list)
end

- (Object) group_addresses

Returns the addresses that are part of groups



60
61
62
# File 'lib/mail/fields/common/common_address.rb', line 60

def group_addresses
  decoded_group_addresses
end

- (Object) group_names

Returns the name of all the groups in a string



75
76
77
# File 'lib/mail/fields/common/common_address.rb', line 75

def group_names # :nodoc:
  address_list.group_names
end

- (Object) groups

Returns a hash of group name => address strings for the address list



55
56
57
# File 'lib/mail/fields/common/common_address.rb', line 55

def groups
  address_list.addresses_grouped_by_group
end

- (Object) parse(val = value)



7
8
9
10
11
12
13
# File 'lib/mail/fields/common/common_address.rb', line 7

def parse(val = value)
  unless val.blank?
    @address_list = AddressList.new(encode_if_needed(val))
  else
    nil
  end
end

- (Object) value=(val)



94
95
96
97
# File 'lib/mail/fields/common/common_address.rb', line 94

def value=(val)
  super
  parse(self.value)
end