Class | TMail::UNIXMbox |
In: |
lib/tmail/mailbox.rb
lib/tmail/obsolete.rb |
Parent: | Object |
new | -> | newobj |
make _From line
# 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
# 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
# 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
# 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
# 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
# File lib/tmail/mailbox.rb, line 134 def UNIXMbox.static_new(fname, dir, readonly = false) newobj(fname, dir, readonly, true) end
# 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
# File lib/tmail/mailbox.rb, line 196 def each_port(&block) close_check update @real.each_port(&block) end