Пример #1
0
    def update_tag_stats(self, session, config, update_tags=None):
        session = session or Session(config)
        new_tid = config.get_tag_id('new')
        new_msgs = (new_tid
                    and GlobalPostingList(session, '%s:tag' % new_tid).hits()
                    or set([]))
        self.STATS.update({'ALL': [len(self.INDEX), len(new_msgs)]})
        for tid in (update_tags or config.tags.keys()):
            if session:
                session.ui.mark('Counting messages in tag:%s' % tid)
            hits = GlobalPostingList(session, '%s:tag' % tid).hits()
            self.STATS[tid] = [len(hits), len(hits & new_msgs)]

        return self.STATS
Пример #2
0
 def remove_tag(self,
                session,
                tag_id,
                msg_info=None,
                msg_idxs=None,
                conversation=False):
     pls = GlobalPostingList(session, '%s:tag' % tag_id)
     if msg_info and msg_idxs is None:
         msg_idxs = set([int(msg_info[self.MSG_MID], 36)])
     else:
         msg_idxs = set(msg_idxs)
     if not msg_idxs:
         return
     session.ui.mark('Untagging conversations (%s)' % (tag_id, ))
     for msg_idx in list(msg_idxs):
         if conversation:
             for reply in self.get_conversation(msg_idx=msg_idx):
                 if reply[self.MSG_MID]:
                     msg_idxs.add(int(reply[self.MSG_MID], 36))
     session.ui.mark('Untagging %d messages (%s)' % (len(msg_idxs), tag_id))
     eids = []
     for msg_idx in msg_idxs:
         if msg_idx >= 0 and msg_idx < len(self.INDEX):
             msg_info = self.get_msg_at_idx_pos(msg_idx)
             tags = set(
                 [r for r in msg_info[self.MSG_TAGS].split(',') if r])
             if tag_id in tags:
                 tags.remove(tag_id)
                 msg_info[self.MSG_TAGS] = ','.join(list(tags))
                 self.INDEX[msg_idx] = self.m2l(msg_info)
                 self.MODIFIED.add(msg_idx)
             eids.append(msg_info[self.MSG_MID])
     pls.remove(eids)
     pls.save()
Пример #3
0
 def hits(term):
     if term.endswith(':in'):
         return self.TAGS.get(term.rsplit(':', 1)[0], [])
     else:
         session.ui.mark(_('Searching for %s') % term)
         return [
             int(h, 36)
             for h in GlobalPostingList(session, term).hits()
         ]
Пример #4
0
 def hits(term):
     session.ui.mark('Searching for %s' % term)
     return [
         int(h, 36)
         for h in GlobalPostingList(session, term).hits()
     ]