Method: Message.each_multipart_message

Defined in:
lib/nchan_tools/pubsub.rb

.each_multipart_message(content_type, body) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/nchan_tools/pubsub.rb', line 94

def self.each_multipart_message(content_type, body)
  content_type = content_type.last if Array === content_type 
  matches=/^multipart\/mixed; boundary=(?<boundary>.*)/.match content_type
  
  if matches
    splat = body.split(/^--#{Regexp.escape matches[:boundary]}-?-?\r?\n?/)
    splat.shift
    
    splat.each do |v|
      mm=(/(Content-Type:\s(?<content_type>.*?)\r\n)?\r\n(?<body>.*)\r\n/m).match v
      yield mm[:content_type], mm[:body], true
    end
    
  else
    yield content_type, body
  end
end