Files
luk/maildir_gtd/actions/next.py
2025-04-30 16:47:16 -04:00

37 lines
1.5 KiB
Python

import logging
from typing import Iterable
from textual import on
from textual.app import App, ComposeResult, SystemCommand
from textual.logging import TextualHandler
from textual.screen import Screen
from textual.widgets import Header, Footer, Static, Label, Input, Button
from textual.reactive import Reactive
from textual.binding import Binding
from textual.timer import Timer
from textual.containers import ScrollableContainer, Horizontal, Vertical, Grid
import subprocess
def action_next(app) -> None:
"""Show the next email message by finding the next higher ID from the list of envelope IDs."""
try:
result = subprocess.run(
["himalaya", "envelope", "list", "-o", "json"],
capture_output=True,
text=True
)
if result.returncode == 0:
import json
envelopes = json.loads(result.stdout)
ids = sorted(int(envelope['id']) for envelope in envelopes)
for index, envelope_id in enumerate(ids):
if envelope_id > int(app.current_message_id):
app.show_message(envelope_id)
return
app.show_status("No newer messages found.", severity="warning")
app.show_message(envelopes[-1]['id']) # Automatically show the previous message
else:
app.show_status("Failed to fetch envelope list.", severity="error")
except Exception as e:
app.show_status(f"Error: {e}", severity="error")