Class: Rex::MIME::Part

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Encoding

#force_crlf

Constructor Details

#initialize ⇒ Part

Returns a new instance of Part.



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

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

Instance Attribute Details

#content ⇒ Object

Returns the value of attribute content.



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

def content
  @content
end

#header ⇒ Object

Returns the value of attribute header.



11
12
13
# File 'lib/rex/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/rex/mime/part.rb', line 33

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

#content_encoded ⇒ String

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

Returns:

  • (String) —

    Content with encoding or transformations applied.



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

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

#to_s ⇒ Object



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

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

#transfer_encoding ⇒ nil, 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/rex/mime/part.rb', line 41

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

  h[1]
end