## this is basically fail-fast.
   class HookContext
     def initialize name
+      @__say_id = nil
       @__name = name
       @__locals = {}
     end
     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
     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 
 
 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.
                        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
 
           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