Class | SOAP::MIMEMessage |
In: |
lib/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 lib/soap/mimemessage.rb, line 148 148: def initialize 149: @parts = [] 150: @headers = Headers.new 151: @root = nil 152: end
# File lib/soap/mimemessage.rb, line 154 154: def self.parse(head, str) 155: new.parse(head, str) 156: end
# File lib/soap/mimemessage.rb, line 208 208: def add_attachment(attach) 209: part = Part.new 210: part.headers.add("Content-Type", attach.contenttype) 211: part.headers.add("Content-ID", attach.mime_contentid) 212: part.body = attach.content 213: @parts.unshift(part) 214: end
# File lib/soap/mimemessage.rb, line 199 199: def add_part(content) 200: part = Part.new 201: part.headers.add("Content-Type", 202: "text/xml; charset=" + XSD::Charset.xml_encoding_label) 203: part.headers.add("Content-ID", Attachment.contentid(part)) 204: part.body = content 205: @parts.unshift(part) 206: end
# File lib/soap/mimemessage.rb, line 192 192: def boundary 193: if @boundary == nil 194: @boundary = "----=Part_" + __id__.to_s + rand.to_s 195: end 196: @boundary 197: end
# File lib/soap/mimemessage.rb, line 160 160: def close 161: @headers.add( 162: "Content-Type", 163: "multipart/related; type=\"text/xml\"; boundary=\"#{boundary}\"; start=\"#{@parts[0].contentid}\"" 164: ) 165: end
# File lib/soap/mimemessage.rb, line 224 224: def content_str 225: str = '' 226: @parts.each do |prt| 227: str << "--" + boundary + "\r\n" 228: str << prt.to_s + "\r\n" 229: end 230: str << '--' + boundary + "--\r\n" 231: str 232: end
# File lib/soap/mimemessage.rb, line 167 167: def parse(head, str) 168: @headers = Headers.parse(head + "\r\n" + "From: jfh\r\n") 169: boundary = @headers['content-type']['boundary'] 170: if boundary != nil 171: parts = str.split(/--#{Regexp.quote(boundary)}\s*(?:\r\n|--\r\n)/) 172: part = parts.shift # preamble must be ignored. 173: @parts = parts.collect { |part| Part.parse(part) } 174: else 175: @parts = [Part.parse(str)] 176: end 177: if @parts.length < 1 178: raise MIMEMessageError.new("This message contains no valid parts!") 179: end 180: self 181: end