Class: Hermeneutics::Box

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

Overview

Mailboxes

Direct Known Subclasses

MBox, Maildir

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailbox) ⇒ Box

:call-seq:

Box.new( path)          -> box

Instantiate a Box object, just store the path.



78
79
80
# File 'lib/hermeneutics/boxes.rb', line 78

def initialize mailbox
  @mailbox = mailbox
end

Class Attribute Details

.default_formatObject

Returns the value of attribute default_format.



33
34
35
# File 'lib/hermeneutics/boxes.rb', line 33

def default_format
  @default_format
end

Class Method Details

.check(path) ⇒ Object

:call-seq:

Box.check( path)     -> nil

By default, subclass mailboxes do not exist. You should overwrite this behaviour.



62
63
# File 'lib/hermeneutics/boxes.rb', line 62

def check path
end

.find(path, default_format = nil) ⇒ Object

:call-seq:

Box.find( path, default = nil)          -> box

Create a Box object (some subclass of Box), depending on what type the box is found at path.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/hermeneutics/boxes.rb', line 41

def find path, default_format = nil
  b = @boxes.find { |b| b.check path }
  b ||= default_format
  b ||= @default_format
  b ||= if File.directory? path then
    Maildir
  elsif File.file? path then
    MBox
  else
    # If still nothing was found use Postfix convention:
    path =~ /\/$/ ? Maildir : MBox
  end
  b.new path
end

Instance Method Details

#each(&block) ⇒ Object

:call-seq:

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

Iterate through MBox. Alias for MBox#each_mail.



111
# File 'lib/hermeneutics/boxes.rb', line 111

def each &block ; each_mail &block ; end

#exists?Boolean Also known as: exist?

:call-seq:

box.exists?     -> true or false

Test whether the Box exists.

Returns:

  • (Boolean)


91
92
93
# File 'lib/hermeneutics/boxes.rb', line 91

def exists?
  self.class.check @mailbox
end

#pathObject



84
# File 'lib/hermeneutics/boxes.rb', line 84

def path ; @mailbox ; end

#store(msg) ⇒ Object

:call-seq:

mbox.store( msg)     -> nil

Store the mail to the local MBox.



101
102
103
# File 'lib/hermeneutics/boxes.rb', line 101

def store msg
  store_raw msg.to_s, msg.plain_from, msg.created
end

#to_sObject



82
# File 'lib/hermeneutics/boxes.rb', line 82

def to_s ; path ; end