class

Athena::MIME::Header::Collection

Inherits Reference < Object

Represents a collection of MIME headers.

Constructors

new(headers : Enumerable(AMIME::Header::Interface) = [] of AMIME::Header::Interface)
Source
new(*headers : AMIME::Header::Interface)
Source

Class methods

check_header_class(header : AMIME::Header::Interface) : Nil

Checks the provided header to ensure its name and type are compatible.

AMIME::Header::Collection.check_header_class AMIME::Header::Date.new("date", Time.utc) # => nil
AMIME::Header::Collection.check_header_class AMIME::Header::Unstructured.new("date", "blah")
# => AMIME::Exception::Logic: The 'date' header must be an instance of 'Athena::MIME::Header::Date' (got 'Athena::MIME::Header::Unstructured').

ameba:disable Metrics/CyclomaticComplexity:

Source
unique_header?(name : String) : Bool

Returns true if the provided header name is required to be unique.

Source

Instance methods

<<(header : AMIME::Header::Interface) : self

Adds the provided header to the collection.

Source
==(other : self)

Returns true if this reference is the same as other. Invokes same?.

Source
[](name : String, _type : T.class) : T forall T

Returns the first header with the provided name casted to type T. Raises an AMIME::Exception::HeaderNotFound exception if no header with that name exists.

Source
[](name : String) : AMIME::Header::Interface

Returns the first header with the provided name. Raises an AMIME::Exception::HeaderNotFound exception if no header with that name exists.

Source
[]?(name : String, _type : T.class) : T | Nil forall T

Returns the first header with the provided name casted to type T, or nil if no headers with that name exist.

Source
[]?(name : String) : AMIME::Header::Interface | Nil

Returns the first header with the provided name, or nil if no headers with that name exist.

Source
add_date_header(name : String, body : Time) : self

Adds an AMIME::Header::Date header to the collection with the provided name and body.

Source
add_id_header(name : String, body : String | Array(String)) : self

Adds an AMIME::Header::Identification header to the collection with the provided name and body.

Source
add_mailbox_header(name : String, body : AMIME::Address | String) : self

Adds an AMIME::Header::Mailbox header to the collection with the provided name and body.

Source
add_mailbox_list_header(name : String, body : Enumerable(AMIME::Address | String)) : self

Adds an AMIME::Header::MailboxList header to the collection with the provided name and body.

Source
add_parameterized_header(name : String, body : String, params : Hash(String, String) = {} of String => String) : self

Adds an AMIME::Header::Parameterized header to the collection with the provided name and body.

Source
add_path_header(name : String, body : AMIME::Address | String) : self

Adds an AMIME::Header::Path header to the collection with the provided name and body.

Source
add_text_header(name : String, body : String) : self

Adds an AMIME::Header::Unstructured header to the collection with the provided name and body.

Source
all

Returns an array of all AMIME::Header::Interface instances stored within the collection.

Source
all(name : String, & : AMIME::Header::Interface -> ) : Nil

Yields each AMIME::Header::Interface instance stored within the collection with the provided name.

Source
all

Yields each AMIME::Header::Interface instance stored within the collection.

Source
clone

Returns a copy of self with all instance variables cloned.

Source
delete(name : String) : Nil

Removes the header(s) with the provided name from the collection.

Source
has_key?(name : String) : Bool

Returns true if the collection contains a header with the provided name, otherwise false.

Source
header_body(name : String)

Returns the body of the first header with the provided name.

Source
header_parameter(name : String, parameter : String) : String | Nil

Returns the value of the provided parameter for the first AMIME::Header::Parameterized header with the provided name.

headers = AMIME::Header::Collection.new
headers.add_parameterized_header "content-type", "text/plain", {"charset" => "UTF-8"}
headers.header_parameter "content-type", "charset" # => "UTF-8"
Source
line_length

Returns the

Source
line_length=(line_length : Int32) : Nil

Sets the max line length to use for this collection.

Source
names

Returns the names of all headers stored within the collection as an array of strings.

Source
to_a

Returns the string representation of each header in the collection as an array of strings.

Source