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



23
24
25
26
27
28
29
30
31
32
# File 'lib/vagrant/util/mime.rb', line 23

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



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

def content
  @content
end

#content_typeString

Returns type of the content.

Returns:

  • (String)

    type of the content



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

def content_type
  @content_type
end

#headersHash

Returns headers for the mime.

Returns:

  • (Hash)

    headers for the mime



19
20
21
# File 'lib/vagrant/util/mime.rb', line 19

def headers
  @headers
end

Instance Method Details

#add(entry) ⇒ Object

Add an entry to the multipart mime

Parameters:

  • entry

    to add



37
38
39
# File 'lib/vagrant/util/mime.rb', line 37

def add(entry)
  content << entry
end

#to_sString

Output MimeEntity as a string

Returns:

  • (String)

    mime data



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vagrant/util/mime.rb', line 44

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