⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proxyui.py

📁 用python实现的邮件过滤器
💻 PY
📖 第 1 页 / 共 3 页
字号:
        return keys, date, prior, start, end    def _sortMessages(self, messages, sort_order, reverse=False):        """Sorts the message by the appropriate attribute.  If this was the        previous sort order, then reverse it."""        if sort_order is None or sort_order == "received":            # Default sorting, which is in reverse order of appearance.            # This is complicated because the 'received' info is the key.            messages.sort()            if self.previous_sort == sort_order:                messages.reverse()                self.previous_sort = None            else:                self.previous_sort = 'received'            return messages        tmplist = [(getattr(x[1], sort_order), x) for x in messages]        tmplist.sort()        if reverse:            tmplist.reverse()        return [x for (key, x) in tmplist]    def _appendMessages(self, table, keyedMessageInfo, label, sort_order,                        reverse=False):        """Appends the rows of a table of messages to 'table'."""        stripe = 0        keyedMessageInfo = self._sortMessages(keyedMessageInfo, sort_order,                                              reverse)        nrows = options["html_ui", "rows_per_section"]        for key, messageInfo in keyedMessageInfo[:nrows]:            unused, unused, messageInfo.received = \                    self._getTimeRange(self._keyToTimestamp(key))            row = self.html.reviewRow.clone()            try:                score = messageInfo.score            except ValueError:                score = None            if label == _('Spam'):                if score is not None \                   and score > options["html_ui", "spam_discard_level"]:                    r_att = getattr(row, 'discard')                else:                    r_att = getattr(row, options["html_ui",                                           "default_spam_action"])            elif label == _('Ham'):                if score is not None \                   and score < options["html_ui", "ham_discard_level"]:                    r_att = getattr(row, 'discard')                else:                    r_att = getattr(row, options["html_ui",                                           "default_ham_action"])            else:                r_att = getattr(row, options["html_ui",                                           "default_unsure_action"])            setattr(r_att, "checked", 1)            row.optionalHeadersValues = '' # make way for real list            for header in options["html_ui", "display_headers"]:                header = header.lower()                text = getattr(messageInfo, "%sHeader" % (header,))                if header == "subject":                    # Subject is special, because it links to the body.                    # If the user doesn't display the subject, then there                    # is no link to the body.                    h = self.html.reviewRow.linkedHeaderValue.clone()                    h.text.title = messageInfo.bodySummary                    h.text.href = "view?key=%s&corpus=%s" % (key, label)                else:                    h = self.html.reviewRow.headerValue.clone()                h.text = text                row.optionalHeadersValues += h            # Apart from any message headers, we may also wish to display            # the message score, and the time the message was received.            if options["html_ui", "display_score"]:                if isinstance(messageInfo.score, types.StringTypes):                    # Presumably either "?" or "Err".                    row.score_ = messageInfo.score                else:                    row.score_ = "%.2f%%" % (messageInfo.score,)            else:                del row.score_            if options["html_ui", "display_received_time"]:                row.received_ = messageInfo.received            else:                del row.received_            # Many characters can't go in the URL or they cause problems            # (&, ;, ?, etc).  So we use the hex values for them all.            subj_list = []            for c in messageInfo.subjectHeader:                subj_list.append("%%%s" % (hex(ord(c))[2:],))            subj = "".join(subj_list)            row.classify.href="showclues?key=%s&subject=%s" % (key, subj)            row.tokens.href="showclues?key=%s&subject=%s&tokens=1" % (key, subj)            setattr(row, 'class', ['stripe_on', 'stripe_off'][stripe]) # Grr!            setattr(row, 'onMouseOut',                    ["this.className='stripe_on';",                     "this.className='stripe_off';"][stripe])            row = str(row).replace('TYPE', label).replace('KEY', key)            table += row            stripe = stripe ^ 1    def onReview(self, **params):        """Present a list of message for (re)training."""        # Train/discard sumbitted messages.        self._writePreamble("Review")        id = ''        numTrained = 0        numDeferred = 0        if params.get('go') != _('Refresh'):            for key, value in params.items():                if key.startswith('classify:'):                    old_class, id = key.split(':')[1:3]                    if value == _('spam'):                        targetCorpus = state.spamCorpus                        stats_as_ham = False                    elif value == _('ham'):                        targetCorpus = state.hamCorpus                        stats_as_ham = True                    elif value == _('discard'):                        targetCorpus = None                        try:                            state.unknownCorpus.removeMessage(\                                state.unknownCorpus[id])                        except KeyError:                            pass  # Must be a reload.                    else: # defer                        targetCorpus = None                        numDeferred += 1                    if targetCorpus:                        sourceCorpus = None                        if state.unknownCorpus.get(id) is not None:                            sourceCorpus = state.unknownCorpus                        elif state.hamCorpus.get(id) is not None:                            sourceCorpus = state.hamCorpus                        elif state.spamCorpus.get(id) is not None:                            sourceCorpus = state.spamCorpus                        if sourceCorpus is not None:                            try:                                # fromCache is a fix for sf #851785.                                # See the comments in Corpus.py                                targetCorpus.takeMessage(id, sourceCorpus,                                                         fromCache=True)                                if numTrained == 0:                                    self.write(_("<p><b>Training... "))                                    self.flush()                                numTrained += 1                                self.stats.RecordTraining(\                                  stats_as_ham, old_class=old_class)                            except KeyError:                                pass  # Must be a reload.        # Report on any training, and save the database if there was any.        if numTrained > 0:            plural = ''            if numTrained == 1:                response = "Trained on one message. "            else:                response = "Trained on %d messages. " % (numTrained,)            self._doSave()            self.write(response)            self.write("<br>&nbsp;")        title = ""        keys = []        sourceCorpus = state.unknownCorpus        # If any messages were deferred, show the same page again.        if numDeferred > 0:            start = self._keyToTimestamp(id)        # Else after submitting a whole page, display the prior page or the        # next one.  Derive the day of the submitted page from the ID of the        # last processed message.        elif id:            start = self._keyToTimestamp(id)            unused, unused, prior, unused, next = self._buildReviewKeys(start)            if prior:                start = prior            else:                start = next        # Else if they've hit Previous or Next, display that page.        elif params.get('go') == _('Next day'):            start = self._keyToTimestamp(params['next'])        elif params.get('go') == _('Previous day'):            start = self._keyToTimestamp(params['prior'])        # Else if an id has been specified, just show that message        # Else if search criteria have been specified, show the messages        # that match those criteria.        elif params.get('find') is not None:            prior = next = 0            keys = Set()        # so we don't end up with duplicates            push = keys.add            try:                max_results = int(params['max_results'])            except ValueError:                max_results = 1            key = params['find']            if params.has_key('ignore_case'):                ic = True            else:                ic = False            error = False            if key == "":                error = True                page = _("<p>You must enter a search string.</p>")            else:                if len(keys) < max_results and \                   params.has_key('id'):                    if state.unknownCorpus.get(key):                        push((key, state.unknownCorpus))                    elif state.hamCorpus.get(key):                        push((key, state.hamCorpus))                    elif state.spamCorpus.get(key):                        push((key, state.spamCorpus))                if params.has_key('subject') or params.has_key('body') or \                   params.has_key('headers'):                    # This is an expensive operation, so let the user know                    # that something is happening.                    self.write(_('<p>Searching...</p>'))                    for corp in [state.unknownCorpus, state.hamCorpus,                                   state.spamCorpus]:                        for k in corp.keys():                            if len(keys) >= max_results:                                break                            msg = corp[k]                            msg.load()                            if params.has_key('subject'):                                subj = str(msg['Subject'])                                if self._contains(subj, key, ic):                                    push((k, corp))                            if params.has_key('body'):                                # For [ 906581 ] Assertion failed in search                                # subject.  Can the headers be a non-string?                                msg_body = msg.as_string()                                msg_body = msg_body[msg_body.index('\r\n\r\n'):]                                if self._contains(msg_body, key, ic):                                    push((k, corp))                            if params.has_key('headers'):                                for nm, val in msg.items():                                    # For [ 906581 ] Assertion failed in                                    # search subject.  Can the headers be                                    # a non-string?                                    nm = str(nm)                                    val = str(val)                                    if self._contains(nm, key, ic) or \                                       self._contains(val, key, ic):                                        push((k, corp))                if len(keys):                    if len(keys) == 1:                        title = _("Found message")                    else:                                              title = _("Found messages")                    keys = list(keys)                else:                    page = _("<p>Could not find any matching messages. " \                             "Maybe they expired?</p>")                    title = _("Did not find message")                    box = self._buildBox(title, 'status.gif', page)                    self.write(box)                    self.write(self._buildBox(_('Find message'),                                              'query.gif',                                              self.html.findMessage))                    self._writePostamble()                    return        # Else show the most recent day's page, as decided by _buildReviewKeys.        else:            start = 0        # Build the lists of messages: spams, hams and unsure.        if len(keys) == 0:            keys, date, prior, this, next = self._buildReviewKeys(start)        keyedMessageInfo = {options["Headers", "header_unsure_string"]: [],                            options["Headers", "header_ham_string"]: [],

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -