From a93d6b56ba819b38b4a938b51d60051bde7f989d Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Thu, 20 Aug 2020 11:54:15 +0200 Subject: [PATCH] Remove delays with 0 --- config/alot/config | 3 +++ config/alot/hooks.py | 31 ++++++++++++++++++++++++------- local/bin/alot | 6 +++--- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/config/alot/config b/config/alot/config index 9acf872..887c1dc 100644 --- a/config/alot/config +++ b/config/alot/config @@ -4,6 +4,7 @@ periodic_hook_frequency = 60 edit_headers_blacklist = Content-Type, MIME-Version attachment_prefix = /data/temporary prefer_plaintext = True +thread_authors_replace_me = False editor_cmd = st -e vis @@ -93,6 +94,7 @@ theme = "mutt" 7 = call hooks.delay(ui,7) 8 = call hooks.delay(ui,8) 9 = call hooks.delay(ui,9) + 0 = call hooks.delay(ui,0) i = call hooks.spam(ui) [[thread]] @@ -110,6 +112,7 @@ theme = "mutt" 7 = call hooks.delay(ui,7) 8 = call hooks.delay(ui,8) 9 = call hooks.delay(ui,9) + 0 = call hooks.delay(ui,0) i = call hooks.spam(ui) [tags] diff --git a/config/alot/hooks.py b/config/alot/hooks.py index 72b95a1..a7485c2 100644 --- a/config/alot/hooks.py +++ b/config/alot/hooks.py @@ -1,17 +1,34 @@ #!/usr/bin/env python3 +from datetime import date, timedelta + +from alot.buffers import EnvelopeBuffer +from alot.db.envelope import Envelope +from alot.settings.const import settings async def delay(ui, days): - from datetime import date, timedelta - datestr = str(date.today() + timedelta(days=days)) - await ui.apply_commandline(f'toggletags inbox,delay,delay/{datestr}') + datetag = 'delay/' + str(date.today() + timedelta(days=days)) + + if ui.current_buffer.modename == 'search': + messages = ui.current_buffer.get_selected_thread().get_messages().keys() + elif ui.current_buffer.modename == 'thread': + messages = [ ui.current_buffer.get_selected_message() ] + + if days != 0: + for message in messages: + if 'inbox' in message.get_tags(): + message.add_tags(['delay', datetag]) + await ui.apply_commandline('untag inbox,unread') + else: + for message in messages: + if 'delay' in message.get_tags(): + message.remove_tags([t for t in message.get_tags() if t.startswith('delay')]) + message.add_tags(['inbox']) + await ui.apply_commandline('untag delay,delay/*') async def spam(ui): - from alot.buffers import EnvelopeBuffer - from alot.db.envelope import Envelope - from alot.settings.const import settings message = ui.current_buffer.get_selected_message() message.add_tags(['spam']) - message.remove_tags(['unread']) + message.remove_tags(['unread', 'inbox']) if 'ugent' in message.get_tags(): envelope = Envelope( headers=dict( diff --git a/local/bin/alot b/local/bin/alot index dfe4ef9..cf4f59d 100755 --- a/local/bin/alot +++ b/local/bin/alot @@ -1,6 +1,6 @@ #!/usr/bin/python3 -# EASY-INSTALL-ENTRY-SCRIPT: 'alot==0.9','console_scripts','alot' -__requires__ = 'alot==0.9' +# EASY-INSTALL-ENTRY-SCRIPT: 'alot==0.9.1','console_scripts','alot' +__requires__ = 'alot==0.9.1' import re import sys from pkg_resources import load_entry_point @@ -8,5 +8,5 @@ from pkg_resources import load_entry_point if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit( - load_entry_point('alot==0.9', 'console_scripts', 'alot')() + load_entry_point('alot==0.9.1', 'console_scripts', 'alot')() )