Exemple #1
0
    def command(self):
        session, config = self.session, self.session.config
        if len(self.args) < 1:
            raise UsageError('Delete what?')

        removed = 0
        filters = config.get('filter', {})
        filter_terms = config.get('filter_terms', {})
        args = list(self.args)
        for fid in self.args:
            if fid not in filters:
                match = [f for f in filters if filter_terms[f] == fid]
                if match:
                    args.remove(fid)
                    args.extend(match)

        for fid in args:
            if (config.parse_unset(session, 'filter:%s' % fid)
                    and config.parse_unset(session, 'filter_tags:%s' % fid)
                    and config.parse_unset(session, 'filter_terms:%s' % fid)):
                removed += 1
            else:
                session.ui.warning('Failed to remove %s' % fid)
        if removed:
            self.finish()
        return True
Exemple #2
0
    def command(self):
        session, config = self.session, self.session.config
        if len(self.args) < 1:
            raise UsageError('Delete what?')

        removed = 0
        filters = config.get('filter', {})
        filter_terms = config.get('filter_terms', {})
        args = list(self.args)
        for fid in self.args:
            if fid not in filters:
                match = [f for f in filters if filter_terms[f] == fid]
                if match:
                    args.remove(fid)
                    args.extend(match)

        for fid in args:
            if (config.parse_unset(session, 'filter:%s' % fid)
                    and config.parse_unset(session, 'filter_tags:%s' % fid)
                    and config.parse_unset(session, 'filter_terms:%s' % fid)):
                removed += 1
            else:
                session.ui.warning('Failed to remove %s' % fid)
        if removed:
            self.finish()
        return True
Exemple #3
0
 def command(self):
   config = self.session.config
   existing = [v.lower() for v in config.get('tag', {}).values()]
   creating = (self.args or []) + self.data.get('name', [])
   for tag in creating:
     if ' ' in tag:
       return self._error('Invalid tag: %s' % tag)
     if tag.lower() in existing:
       return self._error('Tag already exists: %s' % tag)
   result = []
   for tag in sorted(creating):
     if config.parse_set(self.session, 'tag:%s=%s' % (config.nid('tag'), tag)):
       result.append({'name': tag, 'tid': config.get_tag_id(tag), 'new': 0})
   if result:
     self._background('Save config', lambda: config.save())
   return {'added': result}
Exemple #4
0
    def command(self):
        session, config = self.session, self.session.config
        if len(self.args) < 1:
            raise UsageError('Delete what?')

        args = list(self.args)
        args.sort(key=lambda fid: int(fid, 36))

        filter_keys = config.get('filters', {}).keys()
        removed = 0
        for fid in reversed(args):
            if fid in filter_keys:
                self.session.config.filter_delete(fid)
                removed += 1
            else:
                session.ui.warning('Failed to remove %s' % fid)
        if removed:
            self.finish()

        return self._success(_('Removed %d filter(s)') % removed)
Exemple #5
0
    def command(self):
        session, config = self.session, self.session.config
        if len(self.args) < 1:
            raise UsageError('Delete what?')

        args = list(self.args)
        args.sort(key=lambda fid: int(fid, 36))

        filter_keys = config.get('filters', {}).keys()
        removed = 0
        for fid in reversed(args):
            if fid in filter_keys:
                self.session.config.filter_delete(fid)
                removed += 1
            else:
                session.ui.warning('Failed to remove %s' % fid)
        if removed:
            self.finish()

        return self._success(_('Removed %d filter(s)') % removed)
Exemple #6
0
 def command(self):
   session, config = self.session, self.session.config
   existing = [v.lower() for v in config.get('tag', {}).values()]
   clean_session = mailpile.ui.Session(config)
   clean_session.ui = session.ui
   result = []
   for tag in self.args:
     tag_id = config.get_tag_id(tag)
     if tag_id:
       # FIXME: Update filters too
       if (Search(clean_session, arg=['tag:%s' % tag]).run()
       and Tag(clean_session, arg=['-%s' % tag, 'all']).run()
       and config.parse_unset(session, 'tag:%s' % tag_id)):
         result.append({'name': tag, 'tid': tag_id})
       else:
         raise Exception('That failed, not sure why?!')
     else:
       self._error('No such tag %s' % tag)
   if result:
     config.save()
   return {'removed': result}