Methods
- eof?
- init_scanner
- new
- readchar
- readstr
- rest_size
- scan
- scan_comment
- scan_domain_literal
- scan_error!
- scan_main
- scan_qstr
- scan_quoted_word
- skip
Constants
| Version | = | '0.10.7' |
| MIME_HEADERS | = | { :CTYPE => true, :CENCODING => true, :CDISPOSITION => true |
| PATTERN_TABLE | = | {} |
| RECV_TOKEN | = | { 'from' => :FROM, 'by' => :BY, 'via' => :VIA, 'with' => :WITH, 'id' => :ID, 'for' => :FOR |
Attributes
| [RW] | debug |
Public Class methods
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 101
101: def initialize( str, scantype, comments )
102: init_scanner str
103: @comments = comments || []
104: @debug = false
105:
106: # fix scanner mode
107: @received = (scantype == :RECEIVED)
108: @is_mime_header = MIME_HEADERS[scantype]
109:
110: atom, token, @quoted_re, @domlit_re, @comment_re = PATTERN_TABLE[$KCODE]
111: @word_re = (MIME_HEADERS[scantype] ? token : atom)
112: end
Public Instance methods
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 116
116: def scan( &block )
117: if @debug
118: scan_main do |arr|
119: s, v = arr
120: printf "%7d %-10s %s\n",
121: rest_size(),
122: s.respond_to?(:id2name) ? s.id2name : s.inspect,
123: v.inspect
124: yield arr
125: end
126: else
127: scan_main(&block)
128: end
129: end
Private Instance methods
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 227
227: def eof?
228: @src.empty?
229: end
string scanner
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 223
223: def init_scanner( str )
224: @src = str
225: end
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 244
244: def readchar
245: readstr(/\A./)
246: end
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 235
235: def readstr( re )
236: if m = re.match(@src)
237: @src = m.post_match
238: m[0]
239: else
240: nil
241: end
242: end
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 231
231: def rest_size
232: @src.size
233: end
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 201
201: def scan_comment
202: result = ''
203: nest = 1
204: content = @comment_re
205:
206: until eof?
207: if s = readstr(content) then result << s
208: elsif skip(/\A\)/) then nest -= 1
209: return result if nest == 0
210: result << ')'
211: elsif skip(/\A\(/) then nest += 1
212: result << '('
213: elsif skip(/\A\\/) then result << readchar()
214: else
215: raise 'TMail FATAL: not match in comment'
216: end
217: end
218: scan_error! 'found unterminated comment'
219: end
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 184
184: def scan_domain_literal
185: '[' + scan_qstr(@domlit_re, /\A\]/, 'domain-literal') + ']'
186: end
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 257
257: def scan_error!( msg )
258: raise SyntaxError, msg
259: end
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 142
142: def scan_main
143: until eof?
144: if skip(/\A[\n\r\t ]+/n) # LWSP
145: break if eof?
146: end
147:
148: if s = readstr(@word_re)
149: if @is_mime_header
150: yield :TOKEN, s
151: else
152: # atom
153: if /\A\d+\z/ === s
154: yield :DIGIT, s
155: elsif @received
156: yield RECV_TOKEN[s.downcase] || :ATOM, s
157: else
158: yield :ATOM, s
159: end
160: end
161:
162: elsif skip(/\A"/)
163: yield :QUOTED, scan_quoted_word()
164:
165: elsif skip(/\A\[/)
166: yield :DOMLIT, scan_domain_literal()
167:
168: elsif skip(/\A\(/)
169: @comments.push scan_comment()
170:
171: else
172: c = readchar()
173: yield c, c
174: end
175: end
176:
177: yield false, '$'
178: end
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 188
188: def scan_qstr( pattern, terminal, type )
189: result = ''
190: until eof?
191: if s = readstr(pattern) then result << s
192: elsif skip(terminal) then return result
193: elsif skip(/\A\\/) then result << readchar()
194: else
195: raise "TMail FATAL: not match in #{type}"
196: end
197: end
198: scan_error! "found unterminated #{type}"
199: end
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 180
180: def scan_quoted_word
181: scan_qstr(@quoted_re, /\A"/, 'quoted-word')
182: end
[ show source ]
# File lib/action_mailer/vendor/tmail/scanner_r.rb, line 248
248: def skip( re )
249: if m = re.match(@src)
250: @src = m.post_match
251: true
252: else
253: false
254: end
255: end