class Hermes::Maildir
Constants
- DIRS
- NEW
Public Instance Methods
check( path) → true or false
click to toggle source
Check whether path is a Maildir
.
# File lib/hermes/boxes.rb, line 242 def check mailbox if File.directory? mailbox then DIRS.each do |d| s = File.join mailbox, d File.directory? s or return false end true end end
create → self
click to toggle source
Create the Maildir
.
# File lib/hermes/boxes.rb, line 259 def create Dir.mkdir! @mailbox DIRS.each do |d| s = File.join @mailbox, d Dir.mkdir s end self end
deliver( msg) → nil
click to toggle source
Store the mail into the local Maildir
.
# File lib/hermes/boxes.rb, line 273 def deliver msg tmp = mkfilename TMP File.open tmp, "w" do |f| f.write msg end new = mkfilename NEW File.rename tmp, new new end
each { |mail| ... } → nil
click to toggle source
Iterate through MBox
.
# File lib/hermes/boxes.rb, line 288 def each p = File.join @mailbox, CUR d = Dir.new p d.each { |f| next if f.starts_with? "." File.open f, :encoding => Encoding::ASCII_8BIT do |f| yield f end } end
Private Instance Methods
mkfilename(d)
click to toggle source
# File lib/hermes/boxes.rb, line 304 def mkfilename d dir = File.join @mailbox, d c = 0 begin n = "%.4f.%d_%d.%s" % [ Time.now.to_f, $$, c, Socket.gethostname] path = File.join dir, n File.open path, File::CREAT|File::EXCL do |f| end path rescue Errno::EEXIST c += 1 retry end end