class Mail::Body
- Mail::Body
- Reference
- Object
Overview
= 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.
Defined in:
mail/body.crConstructors
Instance Method Summary
- #<<(val)
-
#==(other)
Matches this body with another body.
-
#=~(regexp)
Accepts a string and performs a regular expression against the decoded text
- #ascii_only?
-
#boundary : String | Nil
Returns and sets the boundary used by the body Allows you to change the boundary of this Body object
-
#boundary=(boundary : String | Nil)
Returns and sets the boundary used by the body Allows you to change the boundary of this Body object
-
#charset : String | Nil
Returns and sets the original character encoding
-
#charset=(charset : String | Nil)
Returns and sets the original character encoding
- #decoded
- #default_encoding
- #empty?
-
#encoded(transfer_encoding = nil)
Returns a body encoded using transfer_encoding.
- #encoding(val = nil)
- #encoding=(val)
-
#epilogue : String | Nil
Returns and sets the epilogue as a string (any text that is after the last MIME boundary)
-
#epilogue=(epilogue : String | Nil)
Returns and sets the epilogue as a string (any text that is after the last MIME boundary)
-
#includes?(other)
Accepts anything that responds to #to_s and checks if it's a substring of the decoded text
-
#match(regexp)
Accepts a string and performs a regular expression against the decoded text
-
#multipart?
Returns true if there are parts defined in the body
- #negotiate_best_encoding(message_encoding, allowed_encodings = nil)
- #parts : PartsList
-
#preamble : String | Nil
Returns and sets the preamble as a string (any text that is before the first MIME boundary)
-
#preamble=(preamble : String | Nil)
Returns and sets the preamble as a string (any text that is before the first MIME boundary)
-
#raw_source : String
Returns the raw source that the body was initialized with, without any tampering
-
#set_sort_order(order : Array(String))
Allows you to set the sort order of the parts, overriding the default sort order.
- #split!(boundary : Nil | String)
-
#to_s
Returns a nicely readable and concise string representation of this object, typically intended for users.
Constructor Detail
Instance Method Detail
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
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
Returns and sets the boundary used by the body Allows you to change the boundary of this Body object
Returns and sets the boundary used by the body Allows you to change the boundary of this Body object
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
Returns and sets the epilogue as a string (any text that is after the last MIME boundary)
Returns and sets the epilogue as a string (any text that is after the last MIME boundary)
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
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">
Returns and sets the preamble as a string (any text that is before the first MIME boundary)
Returns and sets the preamble as a string (any text that is before the first MIME boundary)
Returns the raw source that the body was initialized with, without any tampering
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.
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
.