Example #1
0
    def __init__(self, session, *args, **kwargs):
        LookupHandler.__init__(self, session, *args, **kwargs)
        Search.__init__(self, session)

        global GLOBAL_KEY_CACHE
        self.key_cache = GLOBAL_KEY_CACHE
        _PRUNE_GLOBAL_KEY_CACHE()
Example #2
0
    def __init__(self, session, *args, **kwargs):
        LookupHandler.__init__(self, session, *args, **kwargs)
        Search.__init__(self, session)

        global GLOBAL_KEY_CACHE
        self.key_cache = GLOBAL_KEY_CACHE
        _PRUNE_GLOBAL_KEY_CACHE()
Example #3
0
    def __init__(self, session, *args, **kwargs):
        LookupHandler.__init__(self, session, *args, **kwargs)
        Search.__init__(self, session)

        global GLOBAL_KEY_CACHE
        if len(GLOBAL_KEY_CACHE) > 50:
            GLOBAL_KEY_CACHE = {}
        self.key_cache = GLOBAL_KEY_CACHE
Example #4
0
    def __init__(self, session, *args, **kwargs):
        LookupHandler.__init__(self, session, *args, **kwargs)
        Search.__init__(self, session)

        global GLOBAL_KEY_CACHE
        if len(GLOBAL_KEY_CACHE) > 50:
            GLOBAL_KEY_CACHE = {}
        self.key_cache = GLOBAL_KEY_CACHE
Example #5
0
    def command(self):
        session, config = self.session, self.session.config
        clean_session = mailpile.ui.Session(config)
        clean_session.ui = session.ui
        result = []

        tag_names = []
        if self.args:
            tag_names = list(self.args)
        elif self.data.get('tag', []):
            tag_names = self.data.get('tag', [])

        for tag_name in tag_names:

            tag = config.get_tag(tag_name)

            if tag:
                tag_id = tag._key

                # FIXME: Refuse to delete tag if in use by filters

                rv = (Search(clean_session, arg=['tag:%s' % tag_id]).run() and
                      Tag(clean_session, arg=['-%s' % tag_id, 'all']).run())
                if rv:
                    del config.tags[tag_id]
                    result.append({'name': tag.name, 'tid': tag_id})
                else:
                    raise Exception('That failed: %s' % rv)
            else:
                self._error('No such tag %s' % tag_name)
        if result:
            self._reorder_all_tags()
            self.finish(save=True)
        return self._success(
            _('Deleted %d tags') % len(result), {'removed': result})
Example #6
0
    def command(self):
        session, config = self.session, self.session.config
        args = list(self.args)

        force = ('-force' in args) or ('--force' in args)
        dry_run = ('-test' in args) or ('--test' in args)

        today = time.time() // (24 * 3600)
        results = []
        for tag in self._tags(args):
            if tag.auto_after == 0 or not tag.auto_action:
                continue

            clean_session = mailpile.ui.Session(config)
            clean_session.ui = session.ui
            search_terms = ['in:%s' % tag.slug]
            if not force:
                if tag.auto_after < 0:
                    # If auto_after is negative, use a more conservative
                    # (and error-prone) approach. This will only act on
                    # messages that exactly match; if the app is off for
                    # a day, messages will never get processed at all.
                    search_terms.append('u:%x' % (today + tag.auto_after))
                else:
                    search_terms.extend(['-u:%x' % (today - n)
                                         for n in range(0, tag.auto_after)])

            Search(clean_session, arg=search_terms).run()
            if clean_session.results or dry_run:
                results.append(self._perform_auto_action(clean_session, tag,
                                                         dry_run=dry_run))

        return self._success(
            _('Performed automation for %d tags') % len(results),
            {'results': results})
Example #7
0
 def command(self):
     session, config = self.session, self.session.config
     clean_session = mailpile.ui.Session(config)
     clean_session.ui = session.ui
     result = []
     for tag_name in self.args:
         tag = config.get_tag(tag_name)
         if tag:
             tag_id = tag._key
             # FIXME: Refuse to delete tag if in use by filters
             rv = (Search(clean_session, arg=['tag:%s' % tag_id]).run() and
                   Tag(clean_session, arg=['-%s' % tag_id, 'all']).run())
             if rv:
                 del config.tags[tag_id]
                 result.append({'name': tag.name, 'tid': tag_id})
             else:
                 raise Exception('That failed: %s' % rv)
         else:
             self._error('No such tag %s' % tag_name)
     if result:
         self.finish(save=True, stats=False)
     return {'removed': result}
Example #8
0
 def __init__(self, session):
     Search.__init__(self, session)
     LookupHandler.__init__(self, session)