Class: MIME::Message
- Inherits:
-
Object
- Object
- MIME::Message
- 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
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
HeaderContainer access.
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
-
#initialize(body = nil) ⇒ Message
constructor
Return a Message object with body optionally set to
body
. -
#to_s ⇒ Object
Return the Internet message formatted representation of the instance.
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. = "#{rand(1E9)}@#{__id__.abs}" self.mime_version = "1.0 (Ruby MIME v#{VERSION})" end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
19 20 21 |
# File 'lib/mime/message.rb', line 19 def body @body end |
#headers ⇒ Object (readonly)
HeaderContainer access
17 18 19 |
# File 'lib/mime/message.rb', line 17 def headers @headers end |
Instance Method Details
#to_s ⇒ Object
Return the Internet message formatted representation of the instance.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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. #++ # FIXME writing directly to body VS setting body with a MediaType gives an # imbalance of "\r\n". Setting body directly with string requires a CRLF # prepended, but not the case for TextMedia for instance. So where do we # handle this? Perhaps HeaderContainer#to_s should append a CRLF, or # self#body should detect String and automatically prepend CRLF??? Then we # remove the CRLF here between the headers and body. # # Also, TextMedia adds the Content-ID and Content-Type headers, which we # don't get if body is set directly with String. Does this matter? "#{headers}\r\n#{body}\r\n" end |