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.

Methods

add_attachment   add_part   boundary   close   content_str   has_parts?   headers_str   new   parse   parse   root   to_s  

Classes and Modules

Class SOAP::MIMEMessage::Header
Class SOAP::MIMEMessage::Headers
Class SOAP::MIMEMessage::MIMEMessageError
Class SOAP::MIMEMessage::Part

Constants

MultipartContentType = 'multipart/\w+'

Attributes

headers  [R] 
parts  [R] 

Public Class methods

[Source]

     # File lib/soap/mimemessage.rb, line 148
148:   def initialize
149:     @parts = []
150:     @headers = Headers.new
151:     @root = nil
152:   end

[Source]

     # File lib/soap/mimemessage.rb, line 154
154:   def self.parse(head, str)
155:     new.parse(head, str)
156:   end

Public Instance methods

[Source]

     # 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

[Source]

     # 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

[Source]

     # 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

[Source]

     # 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

[Source]

     # 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

[Source]

     # File lib/soap/mimemessage.rb, line 216
216:   def has_parts?
217:     (@parts.length > 0)
218:   end

[Source]

     # File lib/soap/mimemessage.rb, line 220
220:   def headers_str
221:     @headers.to_s
222:   end

[Source]

     # 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

[Source]

     # File lib/soap/mimemessage.rb, line 183
183:   def root
184:     if @root == nil
185:       start = @headers['content-type']['start']
186:       @root = (start && @parts.find { |prt| prt.contentid == start }) ||
187:         @parts[0]
188:     end
189:     @root
190:   end

[Source]

     # File lib/soap/mimemessage.rb, line 234
234:   def to_s
235:     str = headers_str + "\r\n\r\n" + conent_str
236:   end

[Validate]