Class: RMail::Parser::Handler

Inherits:
StreamHandler show all
Defined in:
lib/rmail/parser.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeHandler

Returns a new instance of Handler.



349
350
351
352
353
# File 'lib/rmail/parser.rb', line 349

def initialize
  @parts = [ RMail::Message.new ]
  @preambles = []
  @epilogues = []
end

Instance Method Details

#body_beginObject



360
361
362
# File 'lib/rmail/parser.rb', line 360

def body_begin
  @body = nil
end

#body_chunk(chunk) ⇒ Object



363
364
365
366
367
368
369
# File 'lib/rmail/parser.rb', line 363

def body_chunk(chunk)
  if @body
    @body << chunk
  else
    @body = chunk
  end
end

#body_endObject



370
371
372
# File 'lib/rmail/parser.rb', line 370

def body_end
  @parts.last.body = @body
end

#epilogue_chunk(chunk) ⇒ Object



384
385
386
387
388
389
390
# File 'lib/rmail/parser.rb', line 384

def epilogue_chunk(chunk)
  if @epilogues.last
    @epilogues.last << chunk
  else
    @epilogues[-1] = chunk
  end
end

#header_field(field, name, value) ⇒ Object



357
358
359
# File 'lib/rmail/parser.rb', line 357

def header_field(field, name, value)
  @parts.last.header.add_raw(field)
end

#mbox_from(field) ⇒ Object



354
355
356
# File 'lib/rmail/parser.rb', line 354

def mbox_from(field)
  @parts.last.header.mbox_from = field
end

#messageObject



406
407
408
# File 'lib/rmail/parser.rb', line 406

def message
  @parts.first
end

#multipart_body_beginObject



373
374
375
376
# File 'lib/rmail/parser.rb', line 373

def multipart_body_begin
  @preambles.push(nil)
  @epilogues.push(nil)
end

#multipart_body_end(delimiters, boundary) ⇒ Object



391
392
393
394
395
396
397
398
# File 'lib/rmail/parser.rb', line 391

def multipart_body_end(delimiters, boundary)
  @parts.last.preamble = @preambles.pop
  @parts.last.epilogue = @epilogues.pop
  if @parts.last.body.nil?
    @parts.last.body = []
  end
  @parts.last.set_delimiters(delimiters, boundary)
end

#part_beginObject



399
400
401
# File 'lib/rmail/parser.rb', line 399

def part_begin
  @parts << RMail::Message.new
end

#part_endObject



402
403
404
405
# File 'lib/rmail/parser.rb', line 402

def part_end
  part = @parts.pop
  @parts.last.add_part(part)
end

#preamble_chunk(chunk) ⇒ Object



377
378
379
380
381
382
383
# File 'lib/rmail/parser.rb', line 377

def preamble_chunk(chunk)
  if @preambles.last
    @preambles.last << chunk
  else
    @preambles[-1] = chunk
  end
end