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

Methods

Included Modules

TextUtils

External Aliases

new -> newobj

Public Class methods

make _From line

[Source]

# File lib/tmail/mailbox.rb, line 172
    def UNIXMbox.create_from_line(port)
      sprintf 'From %s %s',
              fromaddr(port), time2str(File.mtime(port.filename))
    end

[Source]

# File lib/tmail/mailbox.rb, line 113
    def UNIXMbox.lock(fname, mode)
      begin
        f = File.open(fname, mode)
        f.flock File::LOCK_EX
        yield f
      ensure
        f.flock File::LOCK_UN
        f.close if f and not f.closed?
      end
    end

[Source]

# File lib/tmail/mailbox.rb, line 149
    def UNIXMbox.mkfinal(mh, mboxfile, writeback_p, cleanup_p)
      lambda {
        if writeback_p
          lock(mboxfile, "r+") {|f|
            mh.each_port do |port|
              f.puts create_from_line(port)
              port.ropen {|r|
                f.puts r.read
              }
            end
          }
        end
        if cleanup_p
          Dir.foreach(mh.dirname) do |fname|
            next if /\A\.\.?\z/ =~ fname
            File.unlink "#{mh.dirname}/#{fname}"
          end
          Dir.rmdir mh.dirname
        end
      }
    end

[Source]

# File lib/tmail/mailbox.rb, line 138
    def initialize(fname, mhdir, readonly, static)
      @filename = fname
      @readonly = readonly
      @closed = false

      Dir.mkdir mhdir
      @real = MhMailbox.new(mhdir)
      @finalizer = UNIXMbox.mkfinal(@real, @filename, !@readonly, !static)
      ObjectSpace.define_finalizer self, @finalizer
    end

[Source]

# File lib/tmail/mailbox.rb, line 129
    def UNIXMbox.new(fname, tmpdir = nil, readonly = false)
      tmpdir = ENV['TEMP'] || ENV['TMP'] || '/tmp'
      newobj(fname, "#{tmpdir}/ruby_tmail_#{$$}_#{rand()}", readonly, false)
    end

[Source]

# File lib/tmail/mailbox.rb, line 134
    def UNIXMbox.static_new(fname, dir, readonly = false)
      newobj(fname, dir, readonly, true)
    end

Public Instance methods

[Source]

# File lib/tmail/mailbox.rb, line 185
    def close
      return if @closed

      ObjectSpace.undefine_finalizer self
      @finalizer.call
      @finalizer = nil
      @real = nil
      @closed = true
      @updated = nil
    end
each(&block)

Alias for each_port

each_mail(&block)

Alias for each_port

 old #each_mail returns Port

def each_mail( &block )

  each_port do |port|
    yield Mail.new(port)
  end

end

[Source]

# File lib/tmail/mailbox.rb, line 219
    def each_new_port(mtime = nil)
      close_check
      update
      @real.each_new_port(mtime) {|p| yield p }
    end
each_newmail(mtime = nil)

Alias for each_new_port

[Source]

# File lib/tmail/mailbox.rb, line 196
    def each_port(&block)
      close_check
      update
      @real.each_port(&block)
    end
new_mail()

Alias for new_port

[Source]

# File lib/tmail/mailbox.rb, line 225
    def new_port
      close_check
      @real.new_port
    end
reverse_each(&block)

Alias for reverse_each_port

[Source]

# File lib/tmail/mailbox.rb, line 204
    def reverse_each_port(&block)
      close_check
      update
      @real.reverse_each_port(&block)
    end

[Validate]