class Mail::Field
- Mail::Field
- Reference
- Object
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
- Comparable(Mail::Field)
Defined in:
mail/field.crConstant 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
-
.new(name, value = nil, charset = "UTF-8")
Create a field by name and optional value:
Class Method Summary
-
.parse(field : String, charset = "UTF-8")
Parse a field from a raw header line:
- .split(raw_field)
Instance Method Summary
- #<=>(other)
-
#==(other)
Returns
false
(other can only be aValue
here). - #field
- #field=(field : Mail::CommonField | Nil)
- #field_order_id
- #name : String
- #responsible_for?(field_name)
- #same(other)
-
#to_s
Returns a nicely readable and concise string representation of this object, typically intended for users.
- #unparsed_value : String | Nil
- #unparsed_value=(unparsed_value : String | Nil)
- #value
- #value=(val)
Macro Summary
Constructor Detail
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 …>
Class Method Detail
Parse a field from a raw header line:
Mail::Field.parse("field-name: field data")
=> #<Mail::Field …>
Instance Method Detail
Returns false
(other can only be a Value
here).
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
.