bug fix display and load
This commit is contained in:
@@ -4,6 +4,8 @@ import json
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
from src.maildir_gtd.config import get_config
|
||||
|
||||
|
||||
async def list_envelopes(limit: int = 9999) -> Tuple[List[Dict[str, Any]], bool]:
|
||||
"""
|
||||
@@ -92,7 +94,7 @@ async def list_folders() -> Tuple[List[Dict[str, Any]], bool]:
|
||||
return [], False
|
||||
|
||||
|
||||
async def delete_message(message_id: int) -> bool:
|
||||
async def delete_message(message_id: int) -> Tuple[Optional[str], bool]:
|
||||
"""
|
||||
Delete a message by its ID.
|
||||
|
||||
@@ -100,7 +102,9 @@ async def delete_message(message_id: int) -> bool:
|
||||
message_id: The ID of the message to delete
|
||||
|
||||
Returns:
|
||||
True if deletion was successful, False otherwise
|
||||
Tuple containing:
|
||||
- Result message or error
|
||||
- Success status (True if deletion was successful)
|
||||
"""
|
||||
try:
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
@@ -110,10 +114,15 @@ async def delete_message(message_id: int) -> bool:
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
return process.returncode == 0
|
||||
if process.returncode == 0:
|
||||
return stdout.decode().strip() or "Deleted successfully", True
|
||||
else:
|
||||
error_msg = stderr.decode().strip()
|
||||
logging.error(f"Error deleting message: {error_msg}")
|
||||
return error_msg or "Unknown error", False
|
||||
except Exception as e:
|
||||
logging.error(f"Exception during message deletion: {e}")
|
||||
return False
|
||||
return str(e), False
|
||||
|
||||
|
||||
# async def archive_message(message_id: int) -> [str, bool]:
|
||||
@@ -151,8 +160,10 @@ async def archive_messages(message_ids: List[str]) -> Tuple[Optional[str], bool]
|
||||
A tuple containing an optional output string and a boolean indicating success.
|
||||
"""
|
||||
try:
|
||||
config = get_config()
|
||||
archive_folder = config.mail.archive_folder
|
||||
ids_str = " ".join(message_ids)
|
||||
cmd = f"himalaya message move Archives {ids_str}"
|
||||
cmd = f"himalaya message move {archive_folder} {ids_str}"
|
||||
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
cmd,
|
||||
@@ -162,13 +173,14 @@ async def archive_messages(message_ids: List[str]) -> Tuple[Optional[str], bool]
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode == 0:
|
||||
return stdout.decode(), True
|
||||
return stdout.decode().strip() or "Archived successfully", True
|
||||
else:
|
||||
logging.error(f"Error archiving messages: {stderr.decode()}")
|
||||
return None, False
|
||||
error_msg = stderr.decode().strip()
|
||||
logging.error(f"Error archiving messages: {error_msg}")
|
||||
return error_msg or "Unknown error", False
|
||||
except Exception as e:
|
||||
logging.error(f"Exception during message archiving: {e}")
|
||||
return None, False
|
||||
return str(e), False
|
||||
|
||||
|
||||
async def get_message_content(message_id: int) -> Tuple[Optional[str], bool]:
|
||||
|
||||
Reference in New Issue
Block a user