Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Returns all data of a given mime_type from a multipart message
- def extract_type(mime_type, multipart_text)
- data = "" # buffer for holding the returned lines
- begin_boundary = /Content-Type: \S+; boundary=(\S+)/
- end_content = %r{a^} # (at first, will not match against any value)
- matching_content = false
- multipart_text.each_line do |line|
- if matches = line.match(begin_boundary)
- end_content = %r{--#{matches[1]}}
- end
- matching_content = false if line.match end_content
- data += line if matching_content
- matching_content = true if line.match /Content-Type: #{mime_type}/
- end
- data
- end
Add Comment
Please, Sign In to add comment