Class: TMail::Maildir
- Extended by:
- Mutex_m
- Defined in:
- lib/gems/tmail-1.2.3.1/lib/tmail/mailbox.rb,
lib/gems/tmail-1.2.3.1/lib/tmail/obsolete.rb
Constant Summary collapse
- PORT_CLASS =
MaildirPort
- TOO_OLD =
36 hour
60 * 60 * 36
Class Method Summary collapse
Instance Method Summary collapse
- #check_tmp ⇒ Object
- #close ⇒ Object
- #directory ⇒ Object
- #each_new_port ⇒ Object (also: #each_newmail)
- #each_port ⇒ Object (also: #each, #each_mail)
-
#initialize(dir = nil) ⇒ Maildir
constructor
A new instance of Maildir.
- #inspect ⇒ Object
- #new_port ⇒ Object (also: #new_mail)
- #reverse_each_port ⇒ Object (also: #reverse_each)
Constructor Details
#initialize(dir = nil) ⇒ Maildir
Returns a new instance of Maildir.
391 392 393 394 395 396 397 398 |
# File 'lib/gems/tmail-1.2.3.1/lib/tmail/mailbox.rb', line 391 def initialize( dir = nil ) @dirname = dir || ENV['MAILDIR'] raise ArgumentError, "not directory: #{@dirname}"\ unless FileTest.directory? @dirname @new = "#{@dirname}/new" @tmp = "#{@dirname}/tmp" @cur = "#{@dirname}/cur" end |
Class Method Details
Instance Method Details
#check_tmp ⇒ Object
461 462 463 464 465 466 467 468 469 470 |
# File 'lib/gems/tmail-1.2.3.1/lib/tmail/mailbox.rb', line 461 def check_tmp old = Time.now.to_i - TOO_OLD each_filename(@tmp) do |full, fname| if FileTest.file? full and File.stat(full).mtime.to_i < old File.unlink full end end end |
#close ⇒ Object
408 409 |
# File 'lib/gems/tmail-1.2.3.1/lib/tmail/mailbox.rb', line 408 def close end |
#directory ⇒ Object
400 401 402 |
# File 'lib/gems/tmail-1.2.3.1/lib/tmail/mailbox.rb', line 400 def directory @dirname end |
#each_new_port ⇒ Object Also known as: each_newmail
449 450 451 452 453 454 455 456 457 |
# File 'lib/gems/tmail-1.2.3.1/lib/tmail/mailbox.rb', line 449 def each_new_port mail_files(@new).each do |path| dest = @cur + '/' + File.basename(path) File.rename path, dest yield PORT_CLASS.new(dest) end check_tmp end |
#each_port ⇒ Object Also known as: each, each_mail
411 412 413 414 415 |
# File 'lib/gems/tmail-1.2.3.1/lib/tmail/mailbox.rb', line 411 def each_port mail_files(@cur).each do |path| yield PORT_CLASS.new(path) end end |
#inspect ⇒ Object
404 405 406 |
# File 'lib/gems/tmail-1.2.3.1/lib/tmail/mailbox.rb', line 404 def inspect "#<#{self.class} #{@dirname}>" end |
#new_port ⇒ Object Also known as: new_mail
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/gems/tmail-1.2.3.1/lib/tmail/mailbox.rb', line 427 def new_port fname = nil tmpfname = nil newfname = nil begin fname = "#{Time.now.to_i}.#{$$}_#{Maildir.unique_number}.#{Socket.gethostname}" tmpfname = "#{@tmp}/#{fname}" newfname = "#{@new}/#{fname}" end while FileTest.exist? tmpfname if block_given? File.open(tmpfname, 'w') {|f| yield f } File.rename tmpfname, newfname PORT_CLASS.new(newfname) else File.open(tmpfname, 'w') {|f| f.write "\n\n" } PORT_CLASS.new(tmpfname) end end |
#reverse_each_port ⇒ Object Also known as: reverse_each
419 420 421 422 423 |
# File 'lib/gems/tmail-1.2.3.1/lib/tmail/mailbox.rb', line 419 def reverse_each_port mail_files(@cur).reverse_each do |path| yield PORT_CLASS.new(path) end end |