]> git.cworth.org Git - sup/commitdiff
added before-add-message hook, thanks to Marcus Williams
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 5 Nov 2007 02:42:23 +0000 (02:42 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 5 Nov 2007 02:42:23 +0000 (02:42 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@666 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/hook.rb
lib/sup/poll.rb

index dae2ce575f756b106a6277f4692ba548e0e28a14..f1157ca708453d3cd1dd015b164a1c719c1c43f8 100644 (file)
@@ -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 
index f36c37fb0407e3746513c520023f48ebea029851..e124af1ddb2805c3669be30663a8a39fc69af1db 100644 (file)
@@ -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