Class: Hermeneutics::Maildir

Inherits:
Box
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hermeneutics/boxes.rb

Constant Summary collapse

DIRS =
%w(cur tmp new)

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Box

#exists?, find, #initialize, #path, #to_s

Constructor Details

This class inherits a constructor from Hermeneutics::Box

Class Method Details

.check(mailbox) ⇒ Object

:call-seq:

Maildir.check( path)     -> true or false

Check whether path is a Maildir.



242
243
244
245
246
247
248
249
250
# File 'lib/hermeneutics/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

Instance Method Details

#createObject

:call-seq:

maildir.create     -> self

Create the Maildir.



259
260
261
262
263
264
265
266
# File 'lib/hermeneutics/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) ⇒ Object

:call-seq:

maildir.deliver( msg)     -> nil

Store the mail into the local Maildir.



273
274
275
276
277
278
279
280
281
# File 'lib/hermeneutics/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

#eachObject

:call-seq:

mbox.each { |mail| ... }    -> nil

Iterate through MBox.



288
289
290
291
292
293
294
295
296
297
# File 'lib/hermeneutics/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