refactor email viewer app
This commit is contained in:
22
maildir_gtd/actions/show_message.py
Normal file
22
maildir_gtd/actions/show_message.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from textual.widgets import Static
|
||||
import subprocess
|
||||
|
||||
def show_message(app, message_id: int) -> None:
|
||||
"""Fetch and display the email message by ID."""
|
||||
app.query_one("#main_content", Static).loading = True
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["himalaya", "message", "read", str(message_id)],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
if result.returncode == 0:
|
||||
# Render the email content as Markdown
|
||||
from rich.markdown import Markdown
|
||||
markdown_content = Markdown(result.stdout, justify=True)
|
||||
app.query_one("#main_content", Static).loading = False
|
||||
app.query_one("#main_content", Static).update(markdown_content)
|
||||
else:
|
||||
app.query_one("#main_content", Static).update(f"Failed to fetch message {message_id}.")
|
||||
except Exception as e:
|
||||
app.query_one("#main_content", Static).update(f"Error: {e}")
|
||||
Reference in New Issue
Block a user