struct Athena::MIME::Address
inherits Struct
#
Represents an email address with an optional name.
Constructors#
.create(address : self | String) : self
#
Creates a new AMIME::Address
.
If the address is already an AMIME::Address
, it is returned as is.
Otherwise if it's a String
, then attempt to parse the name and address from the provided string.
.new(address : String, name : String = "")
#
Creates a new AMIME::Address
with the provided address and optionally name.
Class methods#
.create_multiple(addresses : Enumerable(self | String)) : Array(self)
#
Creates an array of AMIME::Address
from the provided enumerable addresses.
AMIME::Address.create_multiple({"[email protected]", "Mr Smith <[email protected]>", AMIME::Address.new("[email protected]")}) # =>
# [
# Athena::MIME::Address(@address="[email protected]", @name=""),
# Athena::MIME::Address(@address="[email protected]", @name="Mr Smith"),
# Athena::MIME::Address(@address="[email protected]", @name=""),
# ]
.create_multiple(*addresses : self | String) : Array(self)
#
Creates an array of AMIME::Address
from the provided addresses.
AMIME::Address.create_multiple "[email protected]", "Mr Smith <[email protected]>", AMIME::Address.new("[email protected]") # =>
# [
# Athena::MIME::Address(@address="[email protected]", @name=""),
# Athena::MIME::Address(@address="[email protected]", @name="Mr Smith"),
# Athena::MIME::Address(@address="[email protected]", @name=""),
# ]
Methods#
#address : String
#
Returns the raw email address portion of this Address.
Use #encoded_address
to get a safe representation for use in a MIME header.
address = AMIME::Address.new "[email protected]", "First Last"
address.address # => "[email protected]"
#clone
#
Returns a copy of self
with all instance variables cloned.
#encoded_address : String
#
Returns an encoded representation of #address
safe to use within a MIME header.
AMIME::Address.new("contact@athenï.org").encoded_address # => "xn--athen-gta.org"
#encoded_name : String
#
Returns an encoded representation of #name
safe to use within a MIME header.
AMIME::Address.new("[email protected]", %(Me, "You)).encoded_name # => "Me, \"You"
#has_unicode_local_part? : Bool
#
Returns true
if this Address's localpart contains at least one non-ASCII character.
Otherwise returns false
.
AMIME::Address.new("info@dømi.com").has_unicode_local_part? # => false
AMIME::Address.new("dømi@dømi.com").has_unicode_local_part? # => true
#name : String
#
Returns the raw name portion of this Address, or an empty string if none was set.
Use #encoded_name
to get a safe representation for use in a MIME header.
address = AMIME::Address.new "[email protected]"
address.name # => ""
address = AMIME::Address.new "[email protected]", "First Last"
address.name # => "First Last"
#to_s(io : IO) : Nil
#
Writes an encoded representation of this Address to the provided io for use in a MIME header.
AMIME::Address.new "contact@athenï.org", "George").to_s # => "\"George\" <[email protected]>"