📄 config.py
字号:
# configuration classes for the plugin.# We used to use a little pickle, but have since moved to a "spambayes.Options"# class.# Hack for testing - setup sys.pathif __name__=='__main__': try: import spambayes.Options except ImportError: import sys, os sys.path.append(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "..")))import sys, typestry: _except NameError: _ = lambda arg: argtry: True, Falseexcept NameError: # Maintain compatibility with Python 2.2 True, False = 0==0, 1==0FOLDER_ID = r"\(\'[a-fA-F0-9]+\', \'[a-fA-F0-9]+\'\)"FIELD_NAME = r"[a-zA-Z0-9 ]+"FILTER_ACTION = _("Untouched"), _("Moved"), _("Copied")MSG_READ_STATE = _("None"), _("Read"), _("Unread")from spambayes.OptionsClass import OptionsClass, Optionfrom spambayes.OptionsClass import RESTORE, DO_NOT_RESTOREfrom spambayes.OptionsClass import BOOLEAN, INTEGER, REAL, PATH, FILE_WITH_PATHclass FolderIDOption(Option): def convert(self, value): #print "Convert called on", repr(value) error = None is_multi = self.multiple_values_allowed() # empty string means nothing to single value. if not is_multi and not value: return None # Now sure why we get non-strings here for multis if type(value) == types.ListType: return value # If we really care here, it would be fairly easy to use a regex # etc to pull these IDs apart. eval is easier for now :) try: items = eval(value) except: error = "Invalid value (%s:%s)" % (sys.exc_type, sys.exc_value) check_items = [] if error is None: if is_multi: if type(items) != types.ListType: error = "Multi-valued ID must yield a list" check_items = items else: check_items = [items] if error is None: for item in check_items: if item is None: error = "None isn't valid here (how did it get here anyway?" break if not self.is_valid_single(item): error = "Each ID must be a tuple of 2 strings" break if error is not None: print "Failed to convert FolderID value '%r', is_multi=%d" % \ (value, is_multi) print error if is_multi: return [] else: return None return items def unconvert(self): #print "unconvert called with", repr(self.value) if self.value is None: return "" return str(self.value) def multiple_values_allowed(self): return type(self.value)==types.ListType def is_valid_single(self, value): return value is None or \ (type(value)==types.TupleType and \ len(value)==2 and \ type(value[0])==type(value[1])==types.StringType)defaults = { "General" : ( ("field_score_name", _("The name of the field used to store the spam score"), _("Spam"), _("""SpamBayes stores the spam score for each message in a custom field. This option specifies the name of the field"""), FIELD_NAME, RESTORE), ("data_directory", _("The directory to store the data files."), "", _(""""""), PATH, DO_NOT_RESTORE), ("delete_as_spam_message_state", _("How the 'read' flag on a message is modified"), "None", _("""When the 'Spam' function is used, the message 'read' flag can also be set."""), MSG_READ_STATE, RESTORE), ("recover_from_spam_message_state", _("How the 'read' flag on a message is modified"), "None", _("""When the 'Not Spam' function is used, the message 'read' flag can also be set."""), MSG_READ_STATE, RESTORE), ("verbose", _("Changes the verbosity of the debug output from the program"), 0, _("""Indicates how much information is written to the SpamBayes log file."""), INTEGER, RESTORE), ), # 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" : ( (FolderIDOption, "ham_folder_ids", _("Folders containing known good messages"), [], _("""A list of folders known to contain good (ham) messages. When SpamBayes is trained, these messages will be used as examples of good messages."""), FOLDER_ID, DO_NOT_RESTORE), ("ham_include_sub", _("Does the nominated ham folders include sub-folders?"), False, _(""""""), BOOLEAN, DO_NOT_RESTORE), (FolderIDOption, "spam_folder_ids", _("Folders containing known bad or spam messages"), [], _("""A list of folders known to contain bad (spam) messages. When SpamBayes is trained, these messages will be used as examples of messages to filter."""), FOLDER_ID, DO_NOT_RESTORE), ("spam_include_sub", _("Does the nominated spam folders include sub-folders?"), False, _(""""""), BOOLEAN, DO_NOT_RESTORE), ("train_recovered_spam", _("Train as good as items are recovered?"), True, _("""SpamBayes can detect when a message previously classified as spam (or unsure) is moved back to the folder from which it was filtered. If this option is enabled, SpamBayes will automatically train on such messages"""), BOOLEAN, RESTORE), ("train_manual_spam", _("Train as spam items are manually moved?"), True, _("""SpamBayes can detect when a message previously classified as good (or unsure) is manually moved to the Spam folder. If this option is enabled, SpamBayes will automatically train on such messages"""), BOOLEAN, RESTORE), ("rescore", _("Rescore message after training?"), True, _("""After the training has completed, should all the messages be scored for their Spam value. This is particularly useful after your initial training runs, so you can see how effective your sorting of spam and ham was."""), BOOLEAN, RESTORE), ("rebuild", _("Rescore message after training?"), True, _("""Should the entire database be rebuilt? If enabled, then all training information is reset, and a complete new database built from the existing messages in your folders. If disabled, then only new messages in the folders that have not previously been trained on will be processed"""), BOOLEAN, RESTORE), ), # These options control how a message is categorized "Filter" : ( ("filter_now", _("State of 'Filter Now' checkbox"), False, _("""Something useful."""), BOOLEAN, RESTORE), ("save_spam_info", _("Save spam score"), True, _("""Should the spam score and other information be saved in each message as it is filtered or scored?"""), BOOLEAN, RESTORE), (FolderIDOption, "watch_folder_ids", _("Folders to watch for new messages"), [], _("""The list of folders SpamBayes will watch for new messages, processing messages as defined by the filters."""), FOLDER_ID, DO_NOT_RESTORE), ("watch_include_sub", _("Does the nominated watch folders include sub-folders?"), False, _(""""""), BOOLEAN, DO_NOT_RESTORE), (FolderIDOption, "spam_folder_id", _("The folder used to track spam"), None, _("""The folder SpamBayes moves or copies spam to."""), FOLDER_ID, DO_NOT_RESTORE), ("spam_threshold", _("The score necessary to be considered 'certain' spam"), 90.0, _("""Any message with a Spam score greater than or equal to this value will be considered spam, and processed accordingly."""), REAL, RESTORE), ("spam_action", _("The action to take for new spam"), FILTER_ACTION[1], _("""The action that should be taken as Spam messages arrive."""), FILTER_ACTION, RESTORE), ("spam_mark_as_read", _("Should filtered spam also be marked as 'read'"), False, _("""Determines if spam messages are marked as 'Read' as they are filtered. This can be set to 'True' if the new-mail folder counts bother you when the only new items are spam. It can be set to 'False' if you use the 'read' state of these messages to determine which items you are yet to review. This option does not affect the new-mail icon in the system tray."""), BOOLEAN, RESTORE), (FolderIDOption, "unsure_folder_id", _("The folder used to track uncertain messages"), None, _("""The folder SpamBayes moves or copies uncertain messages to."""), FOLDER_ID, DO_NOT_RESTORE), ("unsure_threshold", _("The score necessary to be considered 'unsure'"), 15.0, _("""Any message with a Spam score greater than or equal to this value (but less than the spam threshold) will be considered spam, and processed accordingly."""), REAL, RESTORE), ("unsure_action", _("The action to take for new uncertain messages"), FILTER_ACTION[1], _("""The action that should be taken as unsure messages arrive."""), FILTER_ACTION, RESTORE), ("unsure_mark_as_read", _("Should filtered uncertain message also be marked as 'read'"), False, _("""Determines if unsure messages are marked as 'Read' as they are filtered. See 'spam_mark_as_read' for more details."""), BOOLEAN, RESTORE), (FolderIDOption, "ham_folder_id", _("The folder to which good messages are moved"), None, _("""The folder SpamBayes moves or copies good messages to."""),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -