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.



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

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

Instance Method Details

#body_beginObject



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

def body_begin
  @body = nil
end

#body_chunk(chunk) ⇒ Object



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

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

#body_endObject



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

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

#epilogue_chunk(chunk) ⇒ Object



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

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

#header_field(field, name, value) ⇒ Object



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

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

#mbox_from(field) ⇒ Object



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

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

#messageObject



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

def message
  @parts.first
end

#multipart_body_beginObject



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

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

#multipart_body_end(delimiters, boundary) ⇒ Object



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

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



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

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

#part_endObject



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

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

#preamble_chunk(chunk) ⇒ Object



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

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