refactor email viewer app
This commit is contained in:
26
maildir_gtd/actions/previous.py
Normal file
26
maildir_gtd/actions/previous.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from textual.widgets import Static
|
||||
import subprocess
|
||||
|
||||
def action_previous(app) -> None:
|
||||
"""Show the previous email message by finding the next lower 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), reverse=True)
|
||||
for envelope_id in ids:
|
||||
if envelope_id < app.current_message_id:
|
||||
app.current_message_id = envelope_id
|
||||
app.show_message(app.current_message_id)
|
||||
app.show_status(f"Showing previous message: {app.current_message_id}")
|
||||
return
|
||||
app.show_status("No older messages found.", severity="warning")
|
||||
else:
|
||||
app.show_status("Failed to fetch envelope list.", severity="error")
|
||||
except Exception as e:
|
||||
app.show_status(f"Error: {e}", severity="error")
|
||||
Reference in New Issue
Block a user