Example #1
0
def main(imap_folder_name):
    "Mostly copy-pasted form drymail-train; probably need to be cleaned up"

    with config.IMAP_connection() as im:
        for msg_num, msg in each_imap_message(im,imap_folder_name):
            cat, prob = Category.classify(str(msg))

            print "%s(%f): %s" % (cat.name, prob,
                                  msg.get('Subject', '(none)').replace('\n',' '))
Example #2
0
def main(category_name, imap_folder_name):
    cat = Category.get(category_name)

    with config.IMAP_connection() as im:
        for msg_num, msg in each_imap_message(im, imap_folder_name):
            print ('Training "%s"'
                   % msg.get('Subject', '(none)').replace('\n',' '))
            cat.train(str(msg))

    return 'not implemented'
Example #3
0
    def _reload(self):
        numbery = re.compile('^[0-9]+$')
        self.current_message_index = None
        self.current_message = None
        self.current_probability = None
        self.current_category = None

        def msgs_cmp(a,b):
            if isinstance(a[0], str) and self.numbery.match(a[0]):
                a = int(a[0]), a[1]
            if isinstance(b[0], str) and self.numbery.match(b[0]):
                b = int(b[0]), b[1]
            return cmp(a,b)

        self.messages = []
        for msg_num, msg in sorted(each_imap_message(self.im, self.imap_folder, flags = '(UNSEEN)'),
                                   cmp = msgs_cmp):
            self.messages.append((msg_num, msg))

        if self.messages:
            self._select_idx(0)

        self._lsub_cache = None