class Mail::Body

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(string : String = "") #

[View source]

Instance Method Detail

def <<(val) #

[View source]
def ==(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


[View source]
def =~(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


[View source]
def ascii_only? #

[View source]
def boundary : String | Nil #

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


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

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


[View source]
def charset : String | Nil #

Returns and sets the original character encoding


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

Returns and sets the original character encoding


[View source]
def decoded #

[View source]
def default_encoding #

[View source]
def empty? #

[View source]
def 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


[View source]
def encoding(val = nil) #

[View source]
def encoding=(val) #

[View source]
def epilogue : String | Nil #

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


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

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


[View source]
def 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


[View source]
def 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">


[View source]
def multipart? #

Returns true if there are parts defined in the body


[View source]
def negotiate_best_encoding(message_encoding, allowed_encodings = nil) #

[View source]
def parts : PartsList #

[View source]
def preamble : String | Nil #

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


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

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


[View source]
def raw_source : String #

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


[View source]
def 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.


[View source]
def split!(boundary : Nil | String) #

[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]