Module: IETF::RFC2045

Defined in:
lib/ietf/rfc2045.rb

Class Method Summary collapse

Class Method Details

.parse_rfc2045_content_from(raw, boundary) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/ietf/rfc2045.rb', line 19

def self.parse_rfc2045_content_from(raw, boundary)
  parts = ("\r\n" + raw).split(/#{CRLF.source}--#{boundary}(?:--)?(?:#{CRLF.source}|$)/)
  parts.reject! {|p| p.gsub(/^[ \r\n#{HTAB}]?$/,'') == ''} # Remove any parts that are blank
  puts "[RFC2045] PARTS:\n\t#{parts.map {|p| p.gsub(/\n/,"\n\t")}.join("\n---\n\t")}" if $DEBUG
  parts.collect {|part|
    puts "[RFC2045] Parsing PART with boundary #{boundary.inspect}:\n\t#{part.gsub(/\n/,"\n\t")}" if $DEBUG
    IETF::RFC2045.parse_rfc2045_from(part)
  }
end

.parse_rfc2045_from(raw) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ietf/rfc2045.rb', line 4

def self.parse_rfc2045_from(raw)
  headers, raw = IETF::RFC822.parse_rfc822_from(raw)

  if headers['content-type'] =~ /multipart\/(\w+); boundary=([\"\'])(.*)\2/ || headers['content-type'] =~ /multipart\/(\w+); boundary(=)(.*)$/
    content = {}
    content[:type] = $1
    content[:boundary] = $3
    content[:content] = IETF::RFC2045.parse_rfc2045_content_from(raw, content[:boundary])
  else
    content = raw
  end

  return [headers, content]
end