envelope.rb 760 B

1234567891011121314151617181920212223242526272829303132333435
  1. # encoding: utf-8
  2. #
  3. # = Mail Envelope
  4. #
  5. # The Envelope class provides a field for the first line in an
  6. # mbox file, that looks like "From mikel@test.lindsaar.net DATETIME"
  7. #
  8. # This envelope class reads that line, and turns it into an
  9. # Envelope.from and Envelope.date for your use.
  10. module Mail
  11. class Envelope < StructuredField
  12. def initialize(*args)
  13. super(FIELD_NAME, strip_field(FIELD_NAME, args.last))
  14. end
  15. def tree
  16. @element ||= Mail::EnvelopeFromElement.new(value)
  17. @tree ||= @element.tree
  18. end
  19. def element
  20. @element ||= Mail::EnvelopeFromElement.new(value)
  21. end
  22. def date
  23. ::DateTime.parse("#{element.date_time}")
  24. end
  25. def from
  26. element.address
  27. end
  28. end
  29. end