Class: MIME::Mail

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

Overview

Construct RFC 2822 Internet messages.

Constant Summary

Constants included from Headers::Internet

Headers::Internet::ATOM, Headers::Internet::DOT_ATOM, Headers::Internet::SPECIALS

Instance Attribute Summary collapse

Attributes included from Headers::Internet

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

Instance Method Summary collapse

Constructor Details

#initialize(content = nil) ⇒ Mail

Initialize a Mail object with body set to content.



18
19
20
21
22
# File 'lib/mime/mail.rb', line 18

def initialize content = nil
  @headers = Header.new
  self.body = content
  self.date = Time.now
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



13
14
15
# File 'lib/mime/mail.rb', line 13

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



13
14
15
# File 'lib/mime/mail.rb', line 13

def headers
  @headers
end

Instance Method Details

#to_sObject

Format the Mail object as an Internet message.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mime/mail.rb', line 27

def to_s
  self.sender       ||= sender_address
  self.message_id   ||= ID.generate_gid(domain)
  body.mime_version ||= "1.0 (Ruby MIME v#{VERSION})"

  #--
  # In an RFC 2822 message, the header and body sections must be separated
  # by two line breaks (i.e., 2*CRLF). One line break is deliberately
  # omitted here so the MIME body supplier can append headers to the
  # top-level message header section.
  #++
  "#{headers}\r\n#{body}"
end