Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

In Files

  • soap/mimemessage.rb

Class/Module Index [+]

Quicksearch

SOAP::MIMEMessage

Classes for MIME message handling. Should be put somewhere else! Tried using the ‘tmail’ module but found that I needed something lighter in weight.

Attributes

headers[R]
parts[R]

Public Class Methods

new() click to toggle source
 
               # File soap/mimemessage.rb, line 148
def initialize
  @parts = []
  @headers = Headers.new
  @root = nil
end
            
parse(head, str) click to toggle source
 
               # File soap/mimemessage.rb, line 154
def self.parse(head, str)
  new.parse(head, str)
end
            

Public Instance Methods

add_attachment(attach) click to toggle source
 
               # File soap/mimemessage.rb, line 208
def add_attachment(attach)
  part = Part.new
  part.headers.add("Content-Type", attach.contenttype)
  part.headers.add("Content-ID", attach.mime_contentid)
  part.body = attach.content
  @parts.unshift(part)
end
            
add_part(content) click to toggle source
 
               # File soap/mimemessage.rb, line 199
def add_part(content)
  part = Part.new
  part.headers.add("Content-Type",
    "text/xml; charset=" + XSD::Charset.xml_encoding_label)
  part.headers.add("Content-ID", Attachment.contentid(part))
  part.body = content
  @parts.unshift(part)
end
            
boundary() click to toggle source
 
               # File soap/mimemessage.rb, line 192
def boundary
  if @boundary == nil
    @boundary = "----=Part_" + __id__.to_s + rand.to_s
  end
  @boundary
end
            
close() click to toggle source
 
               # File soap/mimemessage.rb, line 160
def close
  @headers.add(
    "Content-Type",
    "multipart/related; type=\"text/xml\"; boundary=\"#{boundary}\"; start=\"#{@parts[0].contentid}\""
  )
end
            
content_str() click to toggle source
 
               # File soap/mimemessage.rb, line 224
def content_str
  str = ''
  @parts.each do |prt|
    str << "--" + boundary + "\r\n"
    str << prt.to_s + "\r\n"
  end
  str << '--' + boundary + "--\r\n"
  str
end
            
has_parts?() click to toggle source
 
               # File soap/mimemessage.rb, line 216
def has_parts?
  (@parts.length > 0)
end
            
headers_str() click to toggle source
 
               # File soap/mimemessage.rb, line 220
def headers_str
  @headers.to_s
end
            
parse(head, str) click to toggle source
 
               # File soap/mimemessage.rb, line 167
def parse(head, str)
  @headers = Headers.parse(head + "\r\n" + "From: jfh\r\n")
  boundary = @headers['content-type']['boundary']
  if boundary != nil
    parts = str.split(/--#{Regexp.quote(boundary)}\s*(?:\r\n|--\r\n)/)
    part = parts.shift        # preamble must be ignored.
    @parts = parts.collect { |part| Part.parse(part) }
  else
    @parts = [Part.parse(str)]
  end
  if @parts.length < 1
    raise MIMEMessageError.new("This message contains no valid parts!")
  end
  self
end
            
root() click to toggle source
 
               # File soap/mimemessage.rb, line 183
def root
  if @root == nil
    start = @headers['content-type']['start']
    @root = (start && @parts.find { |prt| prt.contentid == start }) ||
      @parts[0]
  end
  @root
end
            
to_s() click to toggle source
 
               # File soap/mimemessage.rb, line 234
def to_s
  str = headers_str + "\r\n\r\n" + content_str
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus