Add toggle read/unread action with 'u' keybinding in mail app
This commit is contained in:
@@ -312,6 +312,49 @@ async def mark_as_read(
|
||||
return str(e), False
|
||||
|
||||
|
||||
async def mark_as_unread(
|
||||
message_id: int,
|
||||
folder: Optional[str] = None,
|
||||
account: Optional[str] = None,
|
||||
) -> Tuple[Optional[str], bool]:
|
||||
"""
|
||||
Mark a message as unread by removing the 'seen' flag.
|
||||
|
||||
Args:
|
||||
message_id: The ID of the message to mark as unread
|
||||
folder: The folder containing the message
|
||||
account: The account to use
|
||||
|
||||
Returns:
|
||||
Tuple containing:
|
||||
- Result message or error
|
||||
- Success status (True if operation was successful)
|
||||
"""
|
||||
try:
|
||||
cmd = f"himalaya flag remove seen {message_id}"
|
||||
if folder:
|
||||
cmd += f" -f '{folder}'"
|
||||
if account:
|
||||
cmd += f" -a '{account}'"
|
||||
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
cmd,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode == 0:
|
||||
return stdout.decode().strip() or "Marked as unread", True
|
||||
else:
|
||||
error_msg = stderr.decode().strip()
|
||||
logging.error(f"Error marking message as unread: {error_msg}")
|
||||
return error_msg or "Unknown error", False
|
||||
except Exception as e:
|
||||
logging.error(f"Exception during marking message as unread: {e}")
|
||||
return str(e), False
|
||||
|
||||
|
||||
async def search_envelopes(
|
||||
query: str,
|
||||
folder: Optional[str] = None,
|
||||
|
||||
Reference in New Issue
Block a user