Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. # Returns all data of a given mime_type from a multipart message
  2. def extract_type(mime_type, multipart_text)
  3. data = "" # buffer for holding the returned lines
  4. begin_boundary = /Content-Type: \S+; boundary=(\S+)/
  5. end_content = %r{a^} # (at first, will not match against any value)
  6. matching_content = false
  7. multipart_text.each_line do |line|
  8. if matches = line.match(begin_boundary)
  9. end_content = %r{--#{matches[1]}}
  10. end
  11. matching_content = false if line.match end_content
  12. data += line if matching_content
  13. matching_content = true if line.match /Content-Type: #{mime_type}/
  14. end
  15. data
  16. end
Add Comment
Please, Sign In to add comment