Class: MIME::Message

Inherits:
Object
  • Object
show all
Includes:
Headers::Internet, Headers::MIME
Defined in:
lib/mime/message.rb

Overview

Construct textual messages using the RFC 2822 Internet message format.

Instance Attribute Summary collapse

Attributes included from Headers::MIME

#content_description, #content_disposition, #content_id, #content_transfer_encoding, #content_type, #mime_version

Attributes included from Headers::Internet

#bcc, #cc, #comments, #date, #from, #keywords, #message_id, #reply_to, #subject, #to

Instance Method Summary collapse

Constructor Details

#initialize(body = nil) ⇒ Message

Return a Message object with body optionally set to body.



24
25
26
27
28
29
30
# File 'lib/mime/message.rb', line 24

def initialize body = nil
  @body = body
  @headers = HeaderContainer.new
  self.date = Time.now.rfc2822
  self.message_id = "#{rand(1E9)}@#{__id__.abs}"
  self.mime_version = "1.0 (Ruby MIME v#{VERSION})"
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



19
20
21
# File 'lib/mime/message.rb', line 19

def body
  @body
end

#headersObject (readonly)

HeaderContainer access



17
18
19
# File 'lib/mime/message.rb', line 17

def headers
  @headers
end

Instance Method Details

#to_sObject

Return the Internet message formatted representation of the instance.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/mime/message.rb', line 35

def to_s
  #--
  # In an RFC 2822 message, the header and body sections must be separated
  # by two line breaks (CRLF). One line break is deliberately missing,
  # allowing a body supplier to append headers to the top-level message
  # header section. Consequently, the body supplier is responsible for
  # handling the body-header separation. Furthermore, if the +body+ is
  # empty, the header section will be properly terminated, creating a
  # standards compliant message.
  #++

  "#{headers}\r\n#{body}\r\n"
end