Files
luk/maildir_gtd/actions/archive.py
Tim Bendt 615aeda3b9 excellent
2025-05-02 01:16:13 -04:00

37 lines
1.2 KiB
Python

import asyncio
import logging
from textual import work
from textual.logging import TextualHandler
from textual.widgets import ListView
logging.basicConfig(
level="NOTSET",
handlers=[TextualHandler()],
)
@work(exclusive=False)
async def archive_current(app) -> None:
"""Archive the current email message."""
try:
index = app.current_message_index
logging.info("Archiving message ID: " + str(app.current_message_id))
process = await asyncio.create_subprocess_shell(
f"himalaya message move Archives {app.current_message_id}",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
# app.reload_needed = True
app.show_status(f"{stdout.decode()}", "info")
logging.info(stdout.decode())
if process.returncode == 0:
await app.query_one(ListView).pop(index)
app.query_one(ListView).index = index + 1
app.action_next() # Automatically show the next message
else:
app.show_status(f"Error archiving message: {stderr.decode()}", "error")
except Exception as e:
app.show_status(f"Error: {e}", "error")