Method: RMail::Header#address_list_assign

Defined in:
lib/rmail/header.rb

#address_list_assign(field_name, addresses) ⇒ Object

Set a given field to a list of supplied addresses.

The addresses may be a String, RMail::Address, or Array. If a String, it is parsed for valid email addresses and those found are used. If an RMail::Address, the result of RMail::Address#format is used. If an Array, each element of the array must be either a String or RMail::Address and is treated as above.

This method is used to implement many of the convenience methods such as #from=, #to=, etc.



874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
# File 'lib/rmail/header.rb', line 874

def address_list_assign(field_name, addresses)
  if addresses.kind_of?(Array)
    value = addresses.collect { |e|
      if e.kind_of?(RMail::Address)
        e.format
      else
        RMail::Address.parse(e.to_str).collect { |a|
          a.format
        }
      end
    }.flatten.join(", ")
    set(field_name, value)
  elsif addresses.kind_of?(RMail::Address)
    set(field_name, addresses.format)
  else
    address_list_assign(field_name,
                        RMail::Address.parse(addresses.to_str))
  end
end