Class | TMail::UNIXMbox |
In: |
lib/action_mailer/vendor/tmail-1.2.3/tmail/mailbox.rb
|
Parent: | Object |
new | -> | newobj |
Creates a new mailbox object that you can iterate through to collect the emails from with "each_port".
You need to pass it a filename of a unix mailbox format file, the format of this file can be researched at this page at wikipedia
filename: The filename of the mailbox you want to open
tmpdir: Can be set to override TMail using the system environment‘s temp dir. TMail will first use the temp dir specified by you (if any) or then the temp dir specified in the Environment‘s TEMP value then the value in the Environment‘s TMP value or failing all of the above, ’/tmp‘
readonly: If set to false, each email you take from the mail box will be removed from the mailbox. default is false - ie, it WILL truncate your mailbox file to ZERO once it has read the emails out.
None
# First show using readonly true: require 'ftools' File.size("../test/fixtures/mailbox") #=> 20426 mailbox = TMail::UNIXMbox.new("../test/fixtures/mailbox", nil, true) #=> #<TMail::UNIXMbox:0x14a2aa8 @readonly=true.....> mailbox.each_port do |port| mail = TMail::Mail.new(port) puts mail.subject end #Testing mailbox 1 #Testing mailbox 2 #Testing mailbox 3 #Testing mailbox 4 require 'ftools' File.size?("../test/fixtures/mailbox") #=> 20426 # Now show with readonly set to the default false mailbox = TMail::UNIXMbox.new("../test/fixtures/mailbox") #=> #<TMail::UNIXMbox:0x14a2aa8 @readonly=false.....> mailbox.each_port do |port| mail = TMail::Mail.new(port) puts mail.subject end #Testing mailbox 1 #Testing mailbox 2 #Testing mailbox 3 #Testing mailbox 4 File.size?("../test/fixtures/mailbox") #=> nil