Class: Maildir::Queue

Inherits:
Maildir
  • Object
show all
Defined in:
lib/maildir/queue.rb

Instance Method Summary collapse

Instance Method Details

#push(data) ⇒ Object

Adds a new message to the queue. Returns a Maildir::Message object



5
6
7
# File 'lib/maildir/queue.rb', line 5

def push(data)
  add(data)
end

#requeue_stalled_messages(time) ⇒ Object

Returns a count of requeued messages



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/maildir/queue.rb', line 27

def requeue_stalled_messages(time)
  stalled_messages(time).inject(0) do |count, message|
    begin
      push(message.data)
      message.destroy
      count + 1
    rescue Errno::ENOENT
      # Could not read message.data
      count
    end
  end
end

#shiftObject

Finds a new message and marks it as being processed (i.e. moves message from new to cur). Returns message if successful; nil if there are no new messages.



12
13
14
15
16
17
# File 'lib/maildir/queue.rb', line 12

def shift
  loop do
    message = do_shift
    return message unless false == message
  end
end

#stalled_messages(time) ⇒ Object

Returns messages in cur that haven’t been modified since time



20
21
22
23
24
# File 'lib/maildir/queue.rb', line 20

def stalled_messages(time)
  list(:cur).select do |message|
    (mtime = message.mtime) && mtime < time
  end
end