Sha256: 9ffc5baf6dba70ceed9628973298baade42f495343520259f904050d6918ea6f

Contents?: true

Size: 1.08 KB

Versions: 25

Compression:

Stored size: 1.08 KB

Contents

# -*- coding: binary -*-
module Rex
module MIME
class Part

  require 'rex/mime/header'
  require 'rex/mime/encoding'

  include Rex::MIME::Encoding

  attr_accessor :header, :content

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

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

  # Returns the part content with any necessary encoding or transformation
  # applied.
  #
  # @return [String] Content with encoding or transformations applied.
  def content_encoded
    binary_content? ? content : force_crlf(content)
  end

  # Answers if the part content is binary.
  #
  # @return [Boolean] true if the part content is binary, false otherwise.
  def binary_content?
    transfer_encoding && transfer_encoding == 'binary'
  end

  # Returns the Content-Transfer-Encoding of the part.
  #
  # @return [nil] if the part hasn't Content-Transfer-Encoding.
  # @return [String] The Content-Transfer-Encoding or the part.
  def transfer_encoding
    h = header.find('Content-Transfer-Encoding')
    return nil if h.nil?

    h[1]
  end

end
end
end

Version data entries

25 entries across 25 versions & 4 rubygems

Version Path
rex-mime-0.1.10 lib/rex/mime/part.rb
rex-mime-0.1.9 lib/rex/mime/part.rb
rex-mime-0.1.8 lib/rex/mime/part.rb
rex-mime-0.1.7 lib/rex/mime/part.rb
rex-mime-0.1.6 lib/rex/mime/part.rb
rex-2.0.13 lib/rex/mime/part.rb
rex-2.0.12 lib/rex/mime/part.rb
rex-2.0.11 lib/rex/mime/part.rb
rex-mime-0.1.5 lib/rex/mime/part.rb
rex-mime-0.1.4 lib/rex/mime/part.rb
rex-mime-0.1.3 lib/rex/mime/part.rb
rex-mime-0.1.2 lib/rex/mime/part.rb
rex-mime-0.1.1 lib/rex/mime/part.rb
rex-2.0.10 lib/rex/mime/part.rb
rex-2.0.9 lib/rex/mime/part.rb
rex-2.0.8 lib/rex/mime/part.rb
rex-2.0.7 lib/rex/mime/part.rb
rex-2.0.5 lib/rex/mime/part.rb
rex-2.0.4 lib/rex/mime/part.rb
dstruct-0.0.1 lib/rex/mime/part.rb