Class: Rexlite::MIME::Part

Inherits:
Object
  • Object
show all
Includes:
Encoding
Defined in:
lib/nexpose/rexlite/mime/part.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Encoding

#force_crlf

Constructor Details

#initializePart

Returns a new instance of Part.



13
14
15
16
# File 'lib/nexpose/rexlite/mime/part.rb', line 13

def initialize
  self.header = Rexlite::MIME::Header.new
  self.content = ''
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



11
12
13
# File 'lib/nexpose/rexlite/mime/part.rb', line 11

def content
  @content
end

#headerObject

Returns the value of attribute header.



11
12
13
# File 'lib/nexpose/rexlite/mime/part.rb', line 11

def header
  @header
end

Instance Method Details

#binary_content?Boolean

Answers if the part content is binary.

Returns:

  • (Boolean)

    true if the part content is binary, false otherwise.



33
34
35
# File 'lib/nexpose/rexlite/mime/part.rb', line 33

def binary_content?
  transfer_encoding && transfer_encoding == 'binary'
end

#content_encodedString

Returns the part content with any necessary encoding or transformation applied.

Returns:

  • (String)

    Content with encoding or transformations applied.



26
27
28
# File 'lib/nexpose/rexlite/mime/part.rb', line 26

def content_encoded
  binary_content? ? content : force_crlf(content)
end

#to_sObject



18
19
20
# File 'lib/nexpose/rexlite/mime/part.rb', line 18

def to_s
  self.header.to_s + "\r\n" + content_encoded + "\r\n"
end

#transfer_encodingnil, String

Returns the Content-Transfer-Encoding of the part.

Returns:

  • (nil)

    if the part hasn't Content-Transfer-Encoding.

  • (String)

    The Content-Transfer-Encoding or the part.



41
42
43
44
45
46
# File 'lib/nexpose/rexlite/mime/part.rb', line 41

def transfer_encoding
  h = header.find('Content-Transfer-Encoding')
  return nil if h.nil?

  h[1]
end