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.


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

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

Instance Method Details

#body_beginObject


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

def body_begin
  @body = nil
end

#body_chunk(chunk) ⇒ Object


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

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

#body_endObject


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

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

#epilogue_chunk(chunk) ⇒ Object


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

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

#header_field(field, name, value) ⇒ Object


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

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

#mbox_from(field) ⇒ Object


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

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

#messageObject


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

def message
  @parts.first
end

#multipart_body_beginObject


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

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

#multipart_body_end(delimiters, boundary) ⇒ Object


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

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


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

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

#part_endObject


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

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

#preamble_chunk(chunk) ⇒ Object


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

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