Class | Mail::Body |
In: |
lib/mail/body.rb
|
Parent: | Object |
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 it‘s 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.
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
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">
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’ with any other content type coming after.
Allows you to sort the parts according to the default sort order, or the sort order you set with :set_sort_order.
sort_parts! is also called from :encode, so there is no need for you to call this explicitly