Class TMail::Maildir
In: lib/tmail/mailbox.rb
lib/tmail/obsolete.rb
Parent: Object

Methods

Constants

PORT_CLASS = MaildirPort
TOO_OLD = 60 * 60 * 36

Public Class methods

[Source]

# File lib/tmail/mailbox.rb, line 291
    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

[Source]

# File lib/tmail/mailbox.rb, line 284
    def Maildir.unique_number
      synchronize {
        @seq += 1
        return @seq
      }
    end

Public Instance methods

[Source]

# File lib/tmail/mailbox.rb, line 358
    def check_tmp
      old = Time.now.to_i - TOO_OLD
      mail_entries(@tmp).each do |ent|
        begin
          path = "#{@tmp}/#{ent}"
          File.unlink path if File.mtime(path).to_i < old
        rescue Errno::ENOENT
          # maybe other process removed
        end
      end
    end

[Source]

# File lib/tmail/mailbox.rb, line 308
    def close
    end

[Source]

# File lib/tmail/mailbox.rb, line 300
    def directory
      @dirname
    end
each()

Alias for each_port

each_mail()

Alias for each_port

[Source]

# File lib/tmail/mailbox.rb, line 347
    def each_new_port
      sorted_mail_entries(@new).each do |ent|
        dest = "#{@cur}/#{ent}"
        File.rename "#{@new}/#{ent}", dest
        yield PORT_CLASS.new(dest)
      end
      check_tmp
    end
each_newmail()

Alias for each_new_port

[Source]

# File lib/tmail/mailbox.rb, line 311
    def each_port
      sorted_mail_entries(@cur).each do |ent|
        yield PORT_CLASS.new("#{@cur}/#{ent}")
      end
    end

[Source]

# File lib/tmail/mailbox.rb, line 304
    def inspect
      "#<#{self.class} #{@dirname}>"
    end
new_mail(&block)

Alias for new_port

[Source]

# File lib/tmail/mailbox.rb, line 327
    def new_port(&block)
      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', &block)
        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()

Alias for reverse_each_port

[Source]

# File lib/tmail/mailbox.rb, line 319
    def reverse_each_port
      sorted_mail_entries(@cur).reverse_each do |ent|
        yield PORT_CLASS.new("#{@cur}/#{ent}")
      end
    end

[Validate]