📄 config.py
字号:
FOLDER_ID, DO_NOT_RESTORE), ("ham_action", _("The action to take for new good messages"), FILTER_ACTION[0], _("""The action that should be taken as good messages arrive."""), FILTER_ACTION, RESTORE), ("ham_mark_as_read", _("Should filtered good message also be marked as 'read'"), False, _("""Determines if good messages are marked as 'Read' as they are filtered. See 'spam_mark_as_read' for more details."""), BOOLEAN, RESTORE), ("enabled", _("Is filtering enabled?"), False, _(""""""), BOOLEAN, RESTORE), # Options that allow the filtering to be done by a timer. ("timer_enabled", _("Should items be filtered by a timer?"), True, _("""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": ( (FolderIDOption, "folder_ids", _("Folders to filter in a 'Filter Now' operation"), [], _("""The list of folders that will be filtered by this process."""), FOLDER_ID, DO_NOT_RESTORE), ("include_sub", _("Does the nominated folders include sub-folders?"), False, _(""""""), BOOLEAN, DO_NOT_RESTORE), ("only_unread", _("Only filter unread messages?"), False, _("""When scoring messages, should only messages that are unread be considered?"""), BOOLEAN, RESTORE), ("only_unseen", _("Only filter previously unseen ?"), False, _("""When scoring messages, should only messages that have never previously Spam scored be considered?"""), BOOLEAN, RESTORE), ("action_all", _("Perform all filter actions?"), True, _("""When scoring the messages, should all items be performed (such as moving the items based on the score) or should the items only be scored, but otherwise untouched."""), 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 unsure 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 unsure 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 unsure 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 then SpamBayes will play the appropriate notification sound for the received messages."""), REAL, RESTORE), ),}# A simple container that provides "." access to itemsclass SectionContainer: def __init__(self, options, section): self.__dict__['_options'] = options self.__dict__['_section'] = section def __getattr__(self, attr): return self._options.get(self._section, attr) def __setattr__(self, attr, val): return self._options.set(self._section, attr, val)class OptionsContainer: def __init__(self, options): self.__dict__['_options'] = options def __getattr__(self, attr): attr = attr.lower() for key in self._options.sections(): if attr == key.lower(): container = SectionContainer(self._options, key) self.__dict__[attr] = container return container raise AttributeError, "Options has no section '%s'" % attr def __setattr__(self, attr, val): raise AttributeError, "No section [%s]" % attr # and delegate a few methods so this object can be used in place of # a real options object. maybe should add this to getattr. do we want all? def get_option(self, section, name): return self._options.get_option(section, name)def CreateConfig(defaults=defaults): options = OptionsClass() options.load_defaults(defaults) return optionsdef MigrateOptions(options): # Migrate some "old" options to "new" options. Can be deleted in # a few versions :) pass# Old code when we used a pickle. Still needed so old pickles can be# loaded, and moved to the new options file format.class _ConfigurationContainer: def __init__(self, **kw): self.__dict__.update(kw) def __setstate__(self, state): self.__dict__.update(state) def _dump(self, thisname="<root>", level=0): import pprint prefix = " " * level print "%s%s:" % (prefix, thisname) for name, ob in self.__dict__.items(): d = getattr(ob, "_dump", None) if d is None: print "%s %s: %s" % (prefix, name, pprint.pformat(ob)) else: d(name, level+1)class ConfigurationRoot(_ConfigurationContainer): def __init__(self): pass# End of old pickle code.if __name__=='__main__': options = CreateConfig() options.merge_files(['delme.cfg']) c = OptionsContainer(options) f = options.get("Training", "ham_folder_ids") print "Folders before set are", f for i in f: print i, type(i) new_folder_ids = [('000123','456789'), ('ABCDEF', 'FEDCBA')] options.set("Training", "ham_folder_ids", new_folder_ids) f = options.get("Training", "ham_folder_ids") print "Folders after set are", f for i in f: print i, type(i) try: c.filter.oops = "Foo" except (AttributeError,KeyError): # whatever :) pass else: print "ERROR: I was able to set an invalid sub-property!" try: c.oops = "Foo" except (AttributeError,KeyError): # whatever :) pass else: print "ERROR: I was able to set an invalid top-level property!" # Test single ID folders. if c.filter.unsure_folder_id is not None: print "It appears we loaded a folder ID - resetting" c.filter.unsure_folder_id = None unsure_id = c.filter.unsure_folder_id if unsure_id is not None: raise ValueError, "unsure_id wrong (%r)" % (c.filter.unsure_folder_id,) unsure_id = c.filter.unsure_folder_id = ('12345', 'abcdef') if unsure_id != c.filter.unsure_folder_id: raise ValueError, "unsure_id wrong (%r)" % (c.filter.unsure_folder_id,) c.filter.unsure_folder_id = None if c.filter.unsure_folder_id is not None: raise ValueError, "unsure_id wrong (%r)" % (c.filter.unsure_folder_id,) options.set("Filter", "filter_now", True) print "Filter_now from container is", c.filter.filter_now options.set("Filter", "filter_now", False) print "Filter_now from container is now", c.filter.filter_now c.filter.filter_now = True print "Filter_now from container is finally", c.filter.filter_now print "Only unread is", c.filter_now.only_unread v = r"/foo/bar" c.general.data_directory=v if c.general.data_directory!=v: print "Bad directory!", c.general.data_directory v = r"c:\test directory\some sub directory" c.general.data_directory=v if c.general.data_directory!=v: print "Bad directory!", c.general.data_directory v = r"\\server\c$" c.general.data_directory=v if c.general.data_directory!=v: print "Bad directory!", c.general.data_directory options.update_file("delme.cfg") print "Created 'delme.cfg'"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -