class Mail::Field

Overview

Provides a single class to call to create a new structured or unstructured field. Works out per RFC what field of field it is being given and returns the correct field of class back on new.

===Per RFC 2822

2.2. Header Fields

Header fields are lines composed of a field name, followed by a colon
(":"), followed by a field body, and terminated by CRLF.  A field
name MUST be composed of printable US-ASCII characters (i.e.,
characters that have values between 33 and 126, inclusive), except
colon.  A field body may be composed of any US-ASCII characters,
except for CR and LF.  However, a field body may contain CRLF when
used in header "folding" and  "unfolding" as described in section
2.2.3.  All field bodies MUST conform to the syntax described in
sections 3 and 4 of this standard.

Included Modules

Defined in:

mail/field.cr

Constant Summary

FIELD_NAME_MAP = {"to" => ToField.field_name, "from" => FromField.field_name, "content-transfer-encoding" => ContentTransferEncodingField.field_name, "content-type" => ContentTypeField.field_name}
FIELD_ORDER_LOOKUP = (["return-path", "received", "resent-date", "resent-from", "resent-sender", "resent-to", "resent-cc", "resent-bcc", "resent-message-id", "date", "from", "sender", "reply-to", "to", "cc", "bcc", "message-id", "in-reply-to", "references", "subject", "comments", "keywords", "mime-version", "content-type", "content-transfer-encoding", "content-location", "content-disposition", "content-description"] of ::String).each_with_index.to_h
FIELDS_MAP = {"to" => ToField, "from" => FromField, "content-transfer-encoding" => ContentTransferEncodingField, "content-type" => ContentTypeField}
KNOWN_FIELDS = STRUCTURED_FIELDS + ["comments", "subject"]
STRUCTURED_FIELDS = ["bcc", "cc", "content-description", "content-disposition", "content-id", "content-location", "content-transfer-encoding", "content-type", "date", "from", "in-reply-to", "keywords", "message-id", "mime-version", "received", "references", "reply-to", "resent-bcc", "resent-cc", "resent-date", "resent-from", "resent-message-id", "resent-sender", "resent-to", "return-path", "sender", "to"] of ::String

Constructors

Class Method Summary

Instance Method Summary

Macro Summary

Constructor Detail

def self.new(name, value = nil, charset = "UTF-8") #

Create a field by name and optional value:

Mail::Field.new("field-name", "value")

=> #<Mail::Field …>

Values that aren't strings or arrays are coerced to Strings with #to_s.

Mail::Field.new("field-name", 1234)

=> #<Mail::Field …>

Mail::Field.new('content-type', ['text', 'plain', {:charset => 'UTF-8'}])

=> #<Mail::Field …>


[View source]

Class Method Detail

def self.parse(field : String, charset = "UTF-8") #

Parse a field from a raw header line:

Mail::Field.parse("field-name: field data")

=> #<Mail::Field …>


[View source]
def self.split(raw_field) #

[View source]

Instance Method Detail

def <=>(other) #

[View source]
def ==(other) #
Description copied from class Reference

Returns false (other can only be a Value here).


[View source]
def field #

[View source]
def field=(field : Mail::CommonField | Nil) #

[View source]
def field_order_id #

[View source]
def name : String #

[View source]
def responsible_for?(field_name) #

[View source]
def same(other) #

[View source]
def to_s #
Description copied from class Object

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.


[View source]
def unparsed_value : String | Nil #

[View source]
def unparsed_value=(unparsed_value : String | Nil) #

[View source]
def value #

[View source]
def value=(val) #

[View source]

Macro Detail

macro method_missing(call) #

[View source]
macro process_fields_name_map #

[View source]