Skip to content

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({"me@example.com", "Mr Smith <smith@example.com>", AMIME::Address.new("you@example.com")}) # =>
# [
#   Athena::MIME::Address(@address="me@example.com", @name=""),
#   Athena::MIME::Address(@address="smith@example.com", @name="Mr Smith"),
#   Athena::MIME::Address(@address="you@example.com", @name=""),
# ]

.create_multiple(*addresses : self | String) : Array(self)#

Creates an array of AMIME::Address from the provided addresses.

AMIME::Address.create_multiple "me@example.com", "Mr Smith <smith@example.com>", AMIME::Address.new("you@example.com") # =>
# [
#   Athena::MIME::Address(@address="me@example.com", @name=""),
#   Athena::MIME::Address(@address="smith@example.com", @name="Mr Smith"),
#   Athena::MIME::Address(@address="you@example.com", @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 "first.last@example.com", "First Last"
address.address # => "first.last@example.com"

#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("us@example.com", %(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 "first.last@example.com"
address.name # => ""

address = AMIME::Address.new "first.last@example.com", "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\" <contact@xn--athen-gta.org>"