Class: MailParser::RFC2045::Scanner

Inherits:
MailParser::RFC2822::Scanner show all
Defined in:
lib/mailparser/rfc2045/scanner.rb

Direct Known Subclasses

MailParser::RFC2183::Scanner

Constant Summary collapse

TOKEN_RE =
'\x21\x23-\x27\x2a\x2b\x2d\x2e\x30-\x39\x41-\x5a\x5e-\x7f'

Constants inherited from MailParser::RFC2822::Scanner

MailParser::RFC2822::Scanner::ATEXT_RE, MailParser::RFC2822::Scanner::CTEXT_RE, MailParser::RFC2822::Scanner::DTEXT_RE, MailParser::RFC2822::Scanner::QTEXT_RE, MailParser::RFC2822::Scanner::TEXT_RE, MailParser::RFC2822::Scanner::UTEXT_RE

Instance Attribute Summary

Attributes inherited from MailParser::RFC2822::Scanner

#comments

Instance Method Summary collapse

Methods inherited from MailParser::RFC2822::Scanner

#cfws, #cfws_sub, #get_comment, #get_comment_by_id, #initialize, #rest

Constructor Details

This class inherits a constructor from MailParser::RFC2822::Scanner

Instance Method Details

#scan(&block) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/mailparser/rfc2045/scanner.rb', line 10

def scan(&block)
  case @header_type
  when :MIME_VERSION
    scan_mime_version(&block)
  else
    scan_structured(&block)
  end
end

#scan_mime_version {|nil| ... } ⇒ Object

Yields:

  • (nil)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mailparser/rfc2045/scanner.rb', line 38

def scan_mime_version()
  until @ss.eos?
    case
    when s = @ss.scan(/\s*\(/)
      s << cfws(@ss)
      next
    when s = @ss.scan(/\s+/)
      next
    when s = @ss.scan(/\d+/)
      yield [:DIGIT, s]
    when s = @ss.scan(/./)
      yield [s, s]
    end
  end
  yield nil
end

#scan_structured {|nil| ... } ⇒ Object

Yields:

  • (nil)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mailparser/rfc2045/scanner.rb', line 19

def scan_structured()
  until @ss.eos?
    case
    when s = @ss.scan(/\s*\(/)
      s << cfws(@ss)
      next
    when s = @ss.scan(/\s+/)
      next
    when s = @ss.scan(/\"(\s*(\\[#{TEXT_RE}]|[#{QTEXT_RE}]))*\s*\"/o)
      yield [:QUOTED_STRING, s]
    when s = @ss.scan(/[#{TOKEN_RE}]+/o)
      yield [:TOKEN, s]
    when s = @ss.scan(/./)
      yield [s, s]
    end
  end
  yield nil
end