commit 8b1ceac46867999fbaf2793cb13f6e9cfe6a86c3
parent 6b2222c4b3e464ed6b97d2fe23ddf591994f12ae
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date: Mon, 5 Nov 2007 02:42:23 +0000
added before-add-message hook, thanks to Marcus Williams
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@666 5c8cc53c-5e98-4d25-b20a-d8db53a31250
Diffstat:
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/lib/sup/hook.rb b/lib/sup/hook.rb
@@ -12,6 +12,7 @@ class HookManager
## this is basically fail-fast.
class HookContext
def initialize name
+ @__say_id = nil
@__name = name
@__locals = {}
end
@@ -30,8 +31,12 @@ class HookManager
end
def say s
- @__say_id = BufferManager.say s, @__say_id
- BufferManager.draw_screen
+ if BufferManager.instantiated?
+ @__say_id = BufferManager.say s, @__say_id
+ BufferManager.draw_screen
+ else
+ log s
+ end
end
def log s
@@ -39,7 +44,12 @@ class HookManager
end
def ask_yes_or_no q
- BufferManager.ask_yes_or_no q
+ if BufferManager.instantiated?
+ BufferManager.ask_yes_or_no q
+ else
+ print q
+ gets.chomp.downcase == 'y'
+ end
end
def __binding
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
@@ -5,6 +5,12 @@ module Redwood
class PollManager
include Singleton
+ HookManager.register "before-add-message", <<EOS
+Executes immediately before a message is added to the index.
+Variables:
+ message: the new message
+EOS
+
HookManager.register "before-poll", <<EOS
Executes immediately before a poll for new messages commences.
No variables.
@@ -18,7 +24,7 @@ Variables:
not auto-archived).
from_and_subj: an array of (from email address, subject) pairs
from_and_subj_inbox: an array of (from email address, subject) pairs for
- messages appearing in the inbox
+ only those messages appearing in the inbox
EOS
DELAY = 300
@@ -148,6 +154,7 @@ EOS
docid, entry = Index.load_entry_for_id m.id
m = yield(m, offset, entry) or next
+ HookManager.run "before-add-message", :message => m
Index.sync_message m, docid, entry
UpdateManager.relay self, :add, m unless entry
rescue MessageFormatError => e