class

Mail::Body

Inherits Reference < Object

= Body

The body is where the text of the email is stored. Mail treats the body as a single object. The body itself has no information about boundaries used in the MIME standard, it just looks at its content as either a single block of text, or (if it is a multipart message) as an array of blocks of text.

A body has to be told to split itself up into a multipart message by calling #split with the correct boundary. This is because the body object has no way of knowing what the correct boundary is for itself (there could be many boundaries in a body in the case of a nested MIME text).

Once split is called, Mail::Body will slice itself up on this boundary, assigning anything that appears before the first part to the preamble, and anything that appears after the closing boundary to the epilogue, then each part gets initialized into a Mail::Part object.

The boundary that is used to split up the Body is also stored in the Body object for use on encoding itself back out to a string. You can overwrite this if it needs to be changed.

On encoding, the body will return the preamble, then each part joined by the boundary, followed by a closing boundary string and then the epilogue.

Constructors

new(string : String = "")
Source

Instance methods

<<(val)
Source
==(other)

Matches this body with another body. Also matches the decoded value of this body with a string.

Examples:

body = Mail::Body.new('The body') body == body #=> true

body = Mail::Body.new('The body') body == 'The body' #=> true

body = Mail::Body.new("VGhlIGJvZHk=\n") body.encoding = 'base64' body == "The body" #=> true

Source
=~(regexp)

Accepts a string and performs a regular expression against the decoded text

Examples:

body = Mail::Body.new('The body') body =~ /The/ #=> 0

body = Mail::Body.new("VGhlIGJvZHk=\n") body.encoding = 'base64' body =~ /The/ #=> 0

Source
ascii_only?
Source
boundary

Returns and sets the boundary used by the body Allows you to change the boundary of this Body object

Source
boundary=(boundary : String | Nil)

Returns and sets the boundary used by the body Allows you to change the boundary of this Body object

Source
charset

Returns and sets the original character encoding

Source
charset=(charset : String | Nil)

Returns and sets the original character encoding

Source
decoded
Source
default_encoding
Source
empty?
Source
encoded(transfer_encoding = nil)

Returns a body encoded using transfer_encoding. Multipart always uses an identiy encoding (i.e. no encoding). Calling this directly is not a good idea, but supported for compatibility TODO: Validate that preamble and epilogue are valid for requested encoding

Source
encoding(val = nil)
Source
encoding=(val)
Source
epilogue

Returns and sets the epilogue as a string (any text that is after the last MIME boundary)

Source
epilogue=(epilogue : String | Nil)

Returns and sets the epilogue as a string (any text that is after the last MIME boundary)

Source
includes?(other)

Accepts anything that responds to #to_s and checks if it's a substring of the decoded text

Examples:

body = Mail::Body.new('The body') body.includes?('The') #=> true

body = Mail::Body.new("VGhlIGJvZHk=\n") body.encoding = 'base64' body.includes?('The') #=> true

Source
match(regexp)

Accepts a string and performs a regular expression against the decoded text

Examples:

body = Mail::Body.new('The body') body.match(/The/) #=> #<MatchData "The">

body = Mail::Body.new("VGhlIGJvZHk=\n") body.encoding = 'base64' body.match(/The/) #=> #<MatchData "The">

Source
multipart?

Returns true if there are parts defined in the body

Source
negotiate_best_encoding(message_encoding, allowed_encodings = nil)
Source
parts
Source
preamble

Returns and sets the preamble as a string (any text that is before the first MIME boundary)

Source
preamble=(preamble : String | Nil)

Returns and sets the preamble as a string (any text that is before the first MIME boundary)

Source
raw_source

Returns the raw source that the body was initialized with, without any tampering

Source
set_sort_order(order : Array(String))

Allows you to set the sort order of the parts, overriding the default sort order. Defaults to 'text/plain', then 'text/enriched', then 'text/html', then 'multipart/alternative' with any other content type coming after.

Source
split!(boundary : Nil | String)
Source
to_s

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.

Source