Class: Vagrant::Util::Mime::Multipart

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/util/mime.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content_type = "multipart/mixed") ⇒ Multipart

Returns a new instance of Multipart.

Parameters:

  • (optional) (String)

    mime content type

  • (optional) (String)

    mime version


20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant/util/mime.rb', line 20

def initialize(content_type="multipart/mixed")
  @content_id = "#{Time.now.to_i}@#{SecureRandom.alphanumeric(24)}.local"
  @boundary = "Boundary_#{SecureRandom.alphanumeric(24)}"
  @content_type = MIME::Types[content_type].first
  @content = []
  @headers = {
    "Content-ID"=> "<#{@content_id}>",
    "Content-Type"=> "#{content_type}; boundary=#{@boundary}",
  }
end

Instance Attribute Details

#contentArray<String>

Returns collection of content part of the multipart mime.

Returns:

  • (Array<String>)

    collection of content part of the multipart mime


10
11
12
# File 'lib/vagrant/util/mime.rb', line 10

def content
  @content
end

#content_typeString

Returns type of the content.

Returns:

  • (String)

    type of the content


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

def content_type
  @content_type
end

#headersHash

Returns headers for the mime.

Returns:

  • (Hash)

    headers for the mime


16
17
18
# File 'lib/vagrant/util/mime.rb', line 16

def headers
  @headers
end

Instance Method Details

#add(entry) ⇒ Object

Add an entry to the multipart mime

Parameters:

  • entry

    to add


34
35
36
# File 'lib/vagrant/util/mime.rb', line 34

def add(entry)
  content << entry
end

#to_sString

Output MimeEntity as a string

Returns:

  • (String)

    mime data


41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vagrant/util/mime.rb', line 41

def to_s
  output_string = ""
  headers.each do |k, v|
    output_string += "#{k}: #{v}\n"
  end
  output_string += "\n--#{@boundary}\n"
  @content.each do |entry|
    output_string += entry.to_s
    output_string += "\n--#{@boundary}\n"
  end
  output_string
end