struct

Athena::MIME::Address

Inherits Struct < Value < Object

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.

Source
new(address : String, name : String = "")

Creates a new AMIME::Address with the provided address and optionally name.

Source

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=""),
# ]
Source
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=""),
# ]
Source

Instance methods

address

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"
Source
clone

Returns a copy of self with all instance variables cloned.

Source
encoded_address

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"
Source
encoded_name

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"
Source
has_unicode_local_part?

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
Source
name

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"
Source
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>"
Source