Update of /cvsroot/spambayes/spambayes/Outlook2000
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4934/Outlook2000
Modified Files:
addin.py config.py manager.py
Log Message:
Add notification sound support as per patch #858925.
Index: addin.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/addin.py,v
retrieving revision 1.140
retrieving revision 1.141
diff -C2 -d -r1.140 -r1.141
*** addin.py 26 Nov 2004 03:11:43 -0000 1.140
--- addin.py 3 Dec 2004 21:43:19 -0000 1.141
***************
*** 223,226 ****
--- 223,228 ----
folder_name,
disposition)
+
+ manager.HandleNotification(disposition)
else:
print "Spam filtering is disabled - ignoring new message"
Index: config.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/config.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** config.py 2 Nov 2004 21:37:37 -0000 1.33
--- config.py 3 Dec 2004 21:43:19 -0000 1.34
***************
*** 28,32 ****
from spambayes.OptionsClass import OptionsClass, Option
from spambayes.OptionsClass import RESTORE, DO_NOT_RESTORE
! from spambayes.OptionsClass import BOOLEAN, INTEGER, REAL, PATH
class FolderIDOption(Option):
--- 28,32 ----
from spambayes.OptionsClass import OptionsClass, Option
from spambayes.OptionsClass import RESTORE, DO_NOT_RESTORE
! from spambayes.OptionsClass import BOOLEAN, INTEGER, REAL, PATH,
FILE_WITH_PATH
class FolderIDOption(Option):
***************
*** 269,272 ****
--- 269,309 ----
BOOLEAN, RESTORE),
),
+
+ # These options control how the user is notified of new messages.
+ "Notification": (
+ ("notify_sound_enabled", _("Play a notification sound when new
messages arrive?"), False,
+ _("""If enabled, SpamBayes will play a notification sound after a
+ batch of new messages is processed. A different sound can be
+ assigned to each of the three classifications of messages. The
+ good sound will be played if any good messages are received. The
+ possible spam sound will be played if unsure messages are
received,
+ but no good messages. The spam sound will be played if all
+ received messages are spam."""),
+ BOOLEAN, RESTORE),
+ ("notify_ham_sound", _("Sound file to play for good messages"), "",
+ _("""Specifies the full path to a Windows sound file (WAV format)
that
+ will be played as notification that a good message has been
received."""),
+ FILE_WITH_PATH, DO_NOT_RESTORE),
+ ("notify_unsure_sound", _("Sound file to play for possible spam
messages"), "",
+ _("""Specifies the full path to a Windows sound file (WAV format)
that
+ will be played as notification that a possible spam message has
been
+ received. The possible spam notification sound will only be
played
+ if no good messages have been received."""),
+ FILE_WITH_PATH, DO_NOT_RESTORE),
+ ("notify_spam_sound", _("Sound file to play for spam messages"), "",
+ _("""Specifies the full path to a Windows sound file (WAV format)
that
+ will be played as notification that a spam message has been
+ received. The spam notification sound will only be played if no
+ good or possible spam messages have been received."""),
+ FILE_WITH_PATH, DO_NOT_RESTORE),
+ ("notify_accumulate_delay", _("The delay time to wait for additional
received messages (in seconds)"), 10.0,
+ _("""When SpamBayes classifies a new message, it sets a timer to
wait
+ for additional new messages. If another new message is received
+ before the timer expires then the delay time is reset and
SpamBayes
+ continues to wait. If no new messages arrive within the delay
time
+ the SpamBayes will play the appropriate notification sound for the
+ received messages."""),
+ REAL, RESTORE),
+ ),
}
Index: manager.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/manager.py,v
retrieving revision 1.99
retrieving revision 1.100
diff -C2 -d -r1.99 -r1.100
*** manager.py 25 Nov 2004 23:26:58 -0000 1.99
--- manager.py 3 Dec 2004 21:43:19 -0000 1.100
***************
*** 10,13 ****
--- 10,15 ----
import win32api, win32con, win32gui
+ import timer, thread
+
import win32com.client
import win32com.client.gencache
***************
*** 331,334 ****
--- 333,337 ----
class BayesManager:
def __init__(self, config_base="default", outlook=None, verbose=0):
+ self.owner_thread_ident = thread.get_ident() # check we aren't
multi-threaded
self.never_configured = True
self.reported_error_map = {}
***************
*** 340,343 ****
--- 343,348 ----
self.dialog_parser = None
self.test_suite_running = False
+ self.received_ham = self.received_unsure = self.received_spam = 0
+ self.notify_timer_id = None
import_early_core_spambayes_stuff()
***************
*** 786,789 ****
--- 791,795 ----
def Close(self):
global _mgr
+ self._KillNotifyTimer()
self.classifier_data.Close()
self.config = self.options = None
***************
*** 909,912 ****
--- 915,976 ----
SetWaitCursor(0)
+ def HandleNotification(self, disposition):
+ if self.config.notification.notify_sound_enabled:
+ if disposition == "Yes":
+ self.received_spam += 1
+ elif disposition == "No":
+ self.received_ham += 1
+ else:
+ self.received_unsure += 1
+ self._StartNotifyTimer()
+
+ def _StartNotifyTimer(self):
+ # First kill any existing timer
+ self._KillNotifyTimer()
+ # And start a new timer.
+ delay = self.config.notification.notify_accumulate_delay
+ self._DoStartNotifyTimer(delay)
+ pass
+
+ def _DoStartNotifyTimer(self, delay):
+ assert thread.get_ident() == self.owner_thread_ident
+ assert self.notify_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.notify_timer_id = timer.set_timer(delay, self._NotifyTimerFunc)
+ self.LogDebug(1, "Notify timer started - id=%d, delay=%d" %
(self.notify_timer_id, delay))
+
+ def _KillNotifyTimer(self):
+ assert thread.get_ident() == self.owner_thread_ident
+ if self.notify_timer_id is not None:
+ timer.kill_timer(self.notify_timer_id)
+ self.LogDebug(2, "The notify timer with id=%d was stopped" %
self.notify_timer_id)
+ self.notify_timer_id = None
+
+ def _NotifyTimerFunc(self, event, time):
+ # Kill the timer first
+ assert thread.get_ident() == self.owner_thread_ident
+ self.LogDebug(1, "The notify timer with id=%s fired" %
self.notify_timer_id)
+ self._KillNotifyTimer()
+
+ import winsound
+ config = self.config.notification
+ sound_opts = winsound.SND_FILENAME | winsound.SND_ASYNC |
winsound.SND_NOSTOP | winsound.SND_NODEFAULT
+ self.LogDebug(3, "Notify received ham=%d, unsure=%d, spam=%d" %
+ (self.received_ham, self.received_unsure,
self.received_spam))
+ if self.received_ham > 0 and len(config.notify_ham_sound) > 0:
+ self.LogDebug(3, "Playing ham sound '%s'" %
config.notify_ham_sound)
+ winsound.PlaySound(config.notify_ham_sound, sound_opts)
+ elif self.received_unsure > 0 and len(config.notify_unsure_sound) > 0:
+ self.LogDebug(3, "Playing unsure sound '%s'" %
config.notify_unsure_sound)
+ winsound.PlaySound(config.notify_unsure_sound, sound_opts)
+ elif self.received_spam > 0 and len(config.notify_spam_sound) > 0:
+ self.LogDebug(3, "Playing spam sound '%s'" %
config.notify_spam_sound)
+ winsound.PlaySound(config.notify_spam_sound, sound_opts)
+ # Reset received counts to zero after notify.
+ self.received_ham = self.received_unsure = self.received_spam = 0
+
_mgr = None
_______________________________________________
Spambayes-checkins mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/spambayes-checkins