Exemple #1
0
    def apply(self, ui):
        threadbuffer = ui.current_buffer
        # get messages and notification strings
        if self.all:
            thread = threadbuffer.get_selected_thread()
            tid = thread.get_thread_id()
            messages = thread.get_messages().keys()
            confirm_msg = 'remove all messages in thread?'
            ok_msg = 'removed all messages in thread: %s' % tid
        else:
            msg = threadbuffer.get_selected_message()
            messages = [msg]
            confirm_msg = 'remove selected message?'
            ok_msg = 'removed message: %s' % msg.get_message_id()

        # ask for confirmation
        if (yield ui.choice(confirm_msg, select='yes', cancel='no')) == 'no':
            return

        # notify callback
        def callback():
            threadbuffer.rebuild()
            ui.notify(ok_msg)

        # remove messages
        for m in messages:
            ui.dbman.remove_message(m, afterwards=callback)

        ui.apply_command(FlushCommand())
Exemple #2
0
    def apply(self, ui):
        lines = []
        if not self.all:
            lines.append(ui.current_buffer.get_selection())
        else:
            lines = ui.current_buffer.get_message_widgets()

        for widget in lines:
            msg = widget.get_message()

            # in case the thread is yet unread, remove this tag
            if self.visible or (self.visible == 'toggle' and widget.folded):
                if 'unread' in msg.get_tags():
                    msg.remove_tags(['unread'])
                    ui.apply_command(FlushCommand())

            if self.visible == 'toggle':
                self.visible = widget.folded
            if self.raw == 'toggle':
                self.raw = not widget.show_raw
            if self.all_headers == 'toggle':
                self.all_headers = not widget.show_all_headers

            logging.debug((self.visible, self.raw, self.all_headers))
            if self.visible is not None:
                widget.folded = not self.visible
            if self.raw is not None:
                widget.show_raw = self.raw
            if self.all_headers is not None:
                widget.show_all_headers = self.all_headers
            widget.rebuild()
Exemple #3
0
    def apply(self, ui):
        thread = ui.current_buffer.get_selected_thread()
        thread.remove_tags(['unread'])

        ui.apply_command(FlushCommand())
        ui.apply_command(BufferCloseCommand())
        ui.apply_command(RefreshCommand())
Exemple #4
0
    def apply(self, ui):
        tbuffer = ui.current_buffer
        logging.debug('matching lines %s...' % (self.query))
        if self.query is None:
            messagetrees = [tbuffer.get_selected_messagetree()]
        else:
            messagetrees = tbuffer.messagetrees()
            if self.query != '*':

                def matches(msgt):
                    msg = msgt.get_message()
                    return msg.matches(self.query)

                messagetrees = filter(matches, messagetrees)

        for mt in messagetrees:
            # determine new display values for this message
            if self.visible == 'toggle':
                visible = mt.is_collapsed(mt.root)
            else:
                visible = self.visible
            if self.raw == 'toggle':
                tbuffer.focus_selected_message()
            raw = not mt.display_source if self.raw == 'toggle' else self.raw
            all_headers = not mt.display_all_headers \
                if self.all_headers == 'toggle' else self.all_headers

            # collapse/expand depending on new 'visible' value
            if visible is False:
                mt.collapse(mt.root)

                # mark as read if needed
                if settings.get('auto_remove_unread'):
                    msg = mt.get_message()
                    if 'unread' in msg.get_tags():
                        msg.remove_tags(['unread'])
                        fcmd = FlushCommand(silent=True)
                        ui.apply_command(fcmd)
            elif visible is True:  # could be None
                mt.expand(mt.root)
            tbuffer.focus_selected_message()
            # set new values in messagetree obj
            if raw is not None:
                mt.display_source = raw
            if all_headers is not None:
                mt.display_all_headers = all_headers
            mt.debug()
            # let the messagetree reassemble itself
            mt.reassemble()
        # refresh the buffer (clears Tree caches etc)
        tbuffer.refresh()
Exemple #5
0
    def apply(self, ui):
        tbuffer = ui.current_buffer
        if self.all:
            messagetrees = tbuffer.messagetrees()
        else:
            messagetrees = [tbuffer.get_selected_messagetree()]

        def refresh_widgets():
            for mt in messagetrees:
                mt.refresh()

            # put currently selected message id on a block list for the
            # auto-remove-unread feature. This makes sure that explicit
            # tag-unread commands for the current message are not undone on the
            # next keypress (triggering the autorm again)...
            mid = tbuffer.get_selected_mid()
            tbuffer._auto_unread_dont_touch_mids.add(mid)

            tbuffer.refresh()

        tags = filter(lambda x: x, self.tagsstring.split(','))
        try:
            for mt in messagetrees:
                m = mt.get_message()
                if self.action == 'add':
                    m.add_tags(tags, afterwards=refresh_widgets)
                if self.action == 'set':
                    m.add_tags(tags,
                               afterwards=refresh_widgets,
                               remove_rest=True)
                elif self.action == 'remove':
                    m.remove_tags(tags, afterwards=refresh_widgets)
                elif self.action == 'toggle':
                    to_remove = []
                    to_add = []
                    for t in tags:
                        if t in m.get_tags():
                            to_remove.append(t)
                        else:
                            to_add.append(t)
                    m.remove_tags(to_remove)
                    m.add_tags(to_add, afterwards=refresh_widgets)

        except DatabaseROError:
            ui.notify('index in read-only mode', priority='error')
            return

        # flush index
        if self.flush:
            ui.apply_command(FlushCommand())
Exemple #6
0
    def apply(self, ui):
        all_message_widgets = ui.current_buffer.get_messagewidgets()
        if self.all:
            mwidgets = all_message_widgets
        else:
            mwidgets = [ui.current_buffer.get_selection()]
        messages = [mw.get_message() for mw in mwidgets]
        logging.debug('TAG %s' % str(messages))

        def refresh_widgets():
            for mw in all_message_widgets:
                mw.rebuild()

        tags = filter(lambda x: x, self.tagsstring.split(','))
        try:
            for m in messages:
                if self.action == 'add':
                    m.add_tags(tags, afterwards=refresh_widgets)
                if self.action == 'set':
                    m.add_tags(tags,
                               afterwards=refresh_widgets,
                               remove_rest=True)
                elif self.action == 'remove':
                    m.remove_tags(tags, afterwards=refresh_widgets)
                elif self.action == 'toggle':
                    to_remove = []
                    to_add = []
                    for t in tags:
                        if t in m.get_tags():
                            to_remove.append(t)
                        else:
                            to_add.append(t)
                    m.remove_tags(to_remove)
                    m.add_tags(to_add, afterwards=refresh_widgets)
        except DatabaseROError:
            ui.notify('index in read-only mode', priority='error')
            return

        # flush index
        if self.flush:
            ui.apply_command(FlushCommand())