Class | SOAP::MIMEMessage |
In: |
soap/mimemessage.rb
|
Parent: | Object |
Classes for MIME message handling. Should be put somewhere else! Tried using the ‘tmail’ module but found that I needed something lighter in weight.
MultipartContentType | = | 'multipart/\w+' |
headers | [R] | |
parts | [R] |
# File soap/mimemessage.rb, line 148 def initialize @parts = [] @headers = Headers.new @root = nil end
# 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
# 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
# File soap/mimemessage.rb, line 192 def boundary if @boundary == nil @boundary = "----=Part_" + __id__.to_s + rand.to_s end @boundary end
# File soap/mimemessage.rb, line 160 def close @headers.add( "Content-Type", "multipart/related; type=\"text/xml\"; boundary=\"#{boundary}\"; start=\"#{@parts[0].contentid}\"" ) end
# 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
# 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