[Spambayes-checkins] spambayes/Outlook2000 addin.py, 1.98, 1.99 config.py, 1.26, 1.27 manager.py, 1.80, 1.81

Mark Hammond mhammond at users.sourceforge.net
Mon Aug 25 20:35:47 EDT 2003


Update of /cvsroot/spambayes/spambayes/Outlook2000
In directory sc8-pr-cvs1:/tmp/cvs-serv20493

Modified Files:
	addin.py config.py manager.py 
Log Message:
The experimental 'timers' options got upgraded to the 'filter' 
section.  Existing values should be migrated (but note you won't see
the migration until the config is saved - ie, after the manager dialog
is shown).  New values are floating point seconds (and the migration
also does the conversion from the old milli-seconds).  I'm too nice :)


Index: addin.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/addin.py,v
retrieving revision 1.98
retrieving revision 1.99
diff -C2 -d -r1.98 -r1.99
*** addin.py	25 Aug 2003 14:29:33 -0000	1.98
--- addin.py	26 Aug 2003 02:35:45 -0000	1.99
***************
*** 290,297 ****
      def Init(self, *args):
          _BaseItemsEvent.Init(self, *args)
!         
!         start_delay = self.manager.config.experimental.timer_start_delay
!         interval = self.manager.config.experimental.timer_interval
!         use_timer = start_delay and interval
          if use_timer and not hasattr(timer, "__version__"):
              # No binaries will see this.
--- 290,301 ----
      def Init(self, *args):
          _BaseItemsEvent.Init(self, *args)
!         timer_enabled = self.manager.config.filter.timer_enabled
!         start_delay = self.manager.config.filter.timer_start_delay
!         interval = self.manager.config.filter.timer_interval
!         use_timer = timer_enabled and start_delay and interval
!         if timer_enabled and not use_timer:
!             print "*" * 50
!             print "The timer is enabled, but one of the timer intervals values is zero"
!             print "You must set both intervals before the timer will enable"
          if use_timer and not hasattr(timer, "__version__"):
              # No binaries will see this.
***************
*** 308,325 ****
              # the timer for known 'inbox' folders, or for all watched folders.
              is_inbox = self.target.IsReceiveFolder()
!             if not is_inbox and self.manager.config.experimental.timer_only_receive_folders:
                  use_timer = False
  
!         # Good chance someone will assume timer is seconds, not ms.
!         if use_timer and (start_delay < 500 or interval < 500):
!             print "*" * 50
!             print "The timer is configured to fire way too often " \
                    "(delay=%s milliseconds, interval=%s milliseconds)" \
                    % (start_delay, interval)
!             print "This is very high, and is likely to starve Outlook and the "
!             print "SpamBayes addin.  Please adjust your configuration"
!             print "The timer is NOT enabled..."
!             print "*" * 50
!             use_timer = False
  
          self.use_timer = use_timer
--- 312,337 ----
              # the timer for known 'inbox' folders, or for all watched folders.
              is_inbox = self.target.IsReceiveFolder()
!             if not is_inbox and self.manager.config.filer.timer_only_receive_folders:
                  use_timer = False
  
!         # Don't allow insane values for the timer.
!         if use_timer:
!             too = None
!             if type(start_delay) != type(0.0) or type(interval) != type(0.0):
!                 print "*" * 50
!                 print "Timer values are garbage!", repr(start_delay), repr(interval)
!                 use_timer = False
!             elif start_delay < 0.4 or interval < 0.4:
!                 too = "too often"
!             elif start_delay > 30 or interval > 30:
!                 too = "too infrequently"
!             if too:
!                 print "*" * 50
!                 print "The timer is configured to fire way " + too + \
                    "(delay=%s milliseconds, interval=%s milliseconds)" \
                    % (start_delay, interval)
!                 print "Please adjust your configuration.  The timer is NOT enabled..."
!                 print "*" * 50
!                 use_timer = False
  
          self.use_timer = use_timer
***************
*** 338,343 ****
--- 350,357 ----
          assert thread.get_ident() == self.owner_thread_ident
          assert self.timer_id is None, "Shouldn't start a timer when already have one"
+         assert type(delay)==type(0.0), "Timer values are float seconds"
          # And start a new timer.
          assert delay, "No delay means no timer!"
+         delay = int(delay*1000) # convert to ms.
          self.timer_id = timer.set_timer(delay, self._TimerFunc)
          self.manager.LogDebug(1, "New message timer started - id=%d, delay=%d" % (self.timer_id, delay))
***************
*** 347,351 ****
          self._KillTimer()
          # And start a new timer.
!         delay = self.manager.config.experimental.timer_start_delay
          field_name = self.manager.config.general.field_score_name
          self.timer_generator = self.target.GetNewUnscoredMessageGenerator(field_name)
--- 361,365 ----
          self._KillTimer()
          # And start a new timer.
!         delay = self.manager.config.filter.timer_start_delay
          field_name = self.manager.config.general.field_score_name
          self.timer_generator = self.target.GetNewUnscoredMessageGenerator(field_name)
***************
*** 392,396 ****
              finally:
                  # And setup the timer for the next check.
!                 delay = self.manager.config.experimental.timer_interval
                  self._DoStartTimer(delay)
  
--- 406,410 ----
              finally:
                  # And setup the timer for the next check.
!                 delay = self.manager.config.filter.timer_interval
                  self._DoStartTimer(delay)
  
***************
*** 675,678 ****
--- 689,693 ----
              if restore_folder is None or \
                 msgstore_message.GetFolder() == restore_folder:
+                 print "Unable to determine source folder for message '%s' - restoring to Inbox" % (subject,)
                  restore_folder = inbox_folder
  

Index: config.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/config.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** config.py	24 Aug 2003 12:02:21 -0000	1.26
--- config.py	26 Aug 2003 02:35:45 -0000	1.27
***************
*** 110,135 ****
      # Experimental options may change, may get removed, and *will* get moved
      # should they be kept.
      "Experimental" : (
!         ("timer_start_delay", "The interval, (in ms) before the timer starts.", 0,
!             """Once a new item is received in the inbox, SpamBayes will begin
!             processing messages after the given delay.  If a new message arrives
!             during this period, the timer will be reset and delay will start again.""",
!             INTEGER, RESTORE),
!         ("timer_interval", "The interval between subsequent timer checks (in ms)", 1000,
!             """Once the new message timer finds a new message, how long should
!             SpamBayes wait before checking for another new message, assuming no
!             other new messages arrive.  Should a new message arrive during this
!             process, the timer will reset, meaning that timer_start_delay will
!             elapse before the process begins again.""",
!             INTEGER, RESTORE),
!         ("timer_only_receive_folders",
!             "Should the timer only be used for 'Inbox' type folders", True,
!             """The point of using a timer is to prevent the SpamBayes filter
!             getting in the way the builtin Outlook rules.  Therefore, is it 
!             generally only necessary to use a timer for folders that have new
!             items being delivered directly to them.  Folders that are not inbox
!             style folders generally are not subject to builtin filtering, so
!             generally have no problems filtering messages in 'real time'.""",
!             BOOLEAN, RESTORE),
      ),
      "Training" : (
--- 110,121 ----
      # Experimental options may change, may get removed, and *will* get moved
      # should they be kept.
+     # Experimental options will *never* be exposed via the GUI, meaning that
+     # migrating any such options should be considered a favour :)
      "Experimental" : (
!         # These are migrated, so must remain while migration code remains in place.
!         # This isn't critical, so should be deleted after just a few version.
!         ("timer_start_delay", "obsolete", 0, "", INTEGER, RESTORE),
!         ("timer_interval", "obsolete", 1000, "", INTEGER, RESTORE),
!         ("timer_only_receive_folders", "obsolete", True, "", BOOLEAN, RESTORE),
      ),
      "Training" : (
***************
*** 231,234 ****
--- 217,249 ----
          """""",
          BOOLEAN, RESTORE),
+     # Options that allow the filtering to be done by a timer.
+     ("timer_enabled", "Should items be filtered by a timer?", False,
+         """Depending on a number of factors, SpamBayes may occasionally miss
+         messages or conflict with builtin Outlook rules.  If this option
+         is set, SpamBayes will filter all messages in the background.  This
+         generally solves both of these problem, at the cost of having Spam stay
+         in your inbox for a few extra seconds.""",
+         BOOLEAN, RESTORE),
+     ("timer_start_delay", "The interval (in seconds) before the timer starts.", 2.0,
+         """Once a new item is received in the inbox, SpamBayes will begin
+         processing messages after the given delay.  If a new message arrives
+         during this period, the timer will be reset and the delay will start again.""",
+         REAL, RESTORE),
+     ("timer_interval", "The interval between subsequent timer checks (in seconds)", 1.0,
+         """Once the new message timer finds a new message, how long should
+         SpamBayes wait before checking for another new message, assuming no
+         other new messages arrive.  Should a new message arrive during this
+         process, the timer will reset, meaning that timer_start_delay will
+         elapse before the process begins again.""",
+         REAL, RESTORE),
+     ("timer_only_receive_folders",
+         "Should the timer only be used for 'Inbox' type folders?", True,
+         """The point of using a timer is to prevent the SpamBayes filter
+         getting in the way the builtin Outlook rules.  Therefore, is it 
+         generally only necessary to use a timer for folders that have new
+         items being delivered directly to them.  Folders that are not inbox
+         style folders generally are not subject to builtin filtering, so
+         generally have no problems filtering messages in 'real time'.""",
+         BOOLEAN, RESTORE),
      ),
      "Filter_Now": (
***************
*** 287,290 ****
--- 302,326 ----
      options.load_defaults(defaults)
      return options
+ 
+ def MigrateOptions(options):
+     # Migrate some "old" options to "new" options.  Can be deleted in
+     # a few versions :)
+     # Binary007 last with experimental timer values.
+     delay = options.get("Experimental", "timer_start_delay")
+     interval = options.get("Experimental", "timer_interval")
+     if delay and interval:
+         options.set("Filter", "timer_enabled", True)
+         options.set("Filter", "timer_start_delay", float(delay / 1000))
+         options.set("Filter", "timer_interval", float(interval / 1000))
+         # and reset the old options so they are not written to the new file
+         # (actually, resetting isn't enough - must hack and clobber)
+         del options._options["Experimental", "timer_start_delay"]
+         del options._options["Experimental", "timer_interval"]
+ 
+     torf = options.get("Experimental", "timer_only_receive_folders")
+     if not torf:
+         options.set("Filter", "timer_only_receive_folders", False)
+         # and reset old
+         del options._options["Experimental", "timer_only_receive_folders"]
  
  # Old code when we used a pickle.  Still needed so old pickles can be

Index: manager.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/manager.py,v
retrieving revision 1.80
retrieving revision 1.81
diff -C2 -d -r1.80 -r1.81
*** manager.py	25 Aug 2003 14:29:33 -0000	1.80
--- manager.py	26 Aug 2003 02:35:45 -0000	1.81
***************
*** 646,650 ****
--- 646,655 ----
              self.LogDebug(self.verbose, "System verbosity set to", self.verbose)
  
+         # Do any migrations - first the old pickle into the new format.
          self.MigrateOldPickle()
+         # Then any options we change (particularly any 'experimental' ones we
+         # consider important)
+         import config
+         config.MigrateOptions(self.options)
  
          if self.verbose > 1:





More information about the Spambayes-checkins mailing list