add new tasks
This commit is contained in:
@@ -7,11 +7,17 @@ import subprocess
|
||||
from src.mail.config import get_config
|
||||
|
||||
|
||||
async def list_envelopes(limit: int = 9999) -> Tuple[List[Dict[str, Any]], bool]:
|
||||
async def list_envelopes(
|
||||
folder: Optional[str] = None,
|
||||
account: Optional[str] = None,
|
||||
limit: int = 9999,
|
||||
) -> Tuple[List[Dict[str, Any]], bool]:
|
||||
"""
|
||||
Retrieve a list of email envelopes using the Himalaya CLI.
|
||||
|
||||
Args:
|
||||
folder: The folder to list envelopes from (defaults to INBOX)
|
||||
account: The account to use (defaults to default account)
|
||||
limit: Maximum number of envelopes to retrieve
|
||||
|
||||
Returns:
|
||||
@@ -20,8 +26,14 @@ async def list_envelopes(limit: int = 9999) -> Tuple[List[Dict[str, Any]], bool]
|
||||
- Success status (True if operation was successful)
|
||||
"""
|
||||
try:
|
||||
cmd = f"himalaya envelope list -o json -s {limit}"
|
||||
if folder:
|
||||
cmd += f" -f '{folder}'"
|
||||
if account:
|
||||
cmd += f" -a '{account}'"
|
||||
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
f"himalaya envelope list -o json -s {limit}",
|
||||
cmd,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
@@ -66,18 +78,27 @@ async def list_accounts() -> Tuple[List[Dict[str, Any]], bool]:
|
||||
return [], False
|
||||
|
||||
|
||||
async def list_folders() -> Tuple[List[Dict[str, Any]], bool]:
|
||||
async def list_folders(
|
||||
account: Optional[str] = None,
|
||||
) -> Tuple[List[Dict[str, Any]], bool]:
|
||||
"""
|
||||
Retrieve a list of folders available in Himalaya.
|
||||
|
||||
Args:
|
||||
account: The account to list folders for (defaults to default account)
|
||||
|
||||
Returns:
|
||||
Tuple containing:
|
||||
- List of folder dictionaries
|
||||
- Success status (True if operation was successful)
|
||||
"""
|
||||
try:
|
||||
cmd = "himalaya folder list -o json"
|
||||
if account:
|
||||
cmd += f" -a '{account}'"
|
||||
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
"himalaya folder list -o json",
|
||||
cmd,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
@@ -94,12 +115,18 @@ async def list_folders() -> Tuple[List[Dict[str, Any]], bool]:
|
||||
return [], False
|
||||
|
||||
|
||||
async def delete_message(message_id: int) -> Tuple[Optional[str], bool]:
|
||||
async def delete_message(
|
||||
message_id: int,
|
||||
folder: Optional[str] = None,
|
||||
account: Optional[str] = None,
|
||||
) -> Tuple[Optional[str], bool]:
|
||||
"""
|
||||
Delete a message by its ID.
|
||||
|
||||
Args:
|
||||
message_id: The ID of the message to delete
|
||||
folder: The folder containing the message
|
||||
account: The account to use
|
||||
|
||||
Returns:
|
||||
Tuple containing:
|
||||
@@ -107,8 +134,14 @@ async def delete_message(message_id: int) -> Tuple[Optional[str], bool]:
|
||||
- Success status (True if deletion was successful)
|
||||
"""
|
||||
try:
|
||||
cmd = f"himalaya message delete {message_id}"
|
||||
if folder:
|
||||
cmd += f" -f '{folder}'"
|
||||
if account:
|
||||
cmd += f" -a '{account}'"
|
||||
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
f"himalaya message delete {message_id}",
|
||||
cmd,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
@@ -149,12 +182,18 @@ async def delete_message(message_id: int) -> Tuple[Optional[str], bool]:
|
||||
# return False
|
||||
|
||||
|
||||
async def archive_messages(message_ids: List[str]) -> Tuple[Optional[str], bool]:
|
||||
async def archive_messages(
|
||||
message_ids: List[str],
|
||||
folder: Optional[str] = None,
|
||||
account: Optional[str] = None,
|
||||
) -> Tuple[Optional[str], bool]:
|
||||
"""
|
||||
Archive multiple messages by their IDs.
|
||||
|
||||
Args:
|
||||
message_ids: A list of message IDs to archive.
|
||||
folder: The source folder containing the messages
|
||||
account: The account to use
|
||||
|
||||
Returns:
|
||||
A tuple containing an optional output string and a boolean indicating success.
|
||||
@@ -164,6 +203,10 @@ async def archive_messages(message_ids: List[str]) -> Tuple[Optional[str], bool]
|
||||
archive_folder = config.mail.archive_folder
|
||||
ids_str = " ".join(message_ids)
|
||||
cmd = f"himalaya message move {archive_folder} {ids_str}"
|
||||
if folder:
|
||||
cmd += f" -f '{folder}'"
|
||||
if account:
|
||||
cmd += f" -a '{account}'"
|
||||
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
cmd,
|
||||
@@ -183,12 +226,18 @@ async def archive_messages(message_ids: List[str]) -> Tuple[Optional[str], bool]
|
||||
return str(e), False
|
||||
|
||||
|
||||
async def get_message_content(message_id: int) -> Tuple[Optional[str], bool]:
|
||||
async def get_message_content(
|
||||
message_id: int,
|
||||
folder: Optional[str] = None,
|
||||
account: Optional[str] = None,
|
||||
) -> Tuple[Optional[str], bool]:
|
||||
"""
|
||||
Retrieve the content of a message by its ID.
|
||||
|
||||
Args:
|
||||
message_id: The ID of the message to retrieve
|
||||
folder: The folder containing the message
|
||||
account: The account to use
|
||||
|
||||
Returns:
|
||||
Tuple containing:
|
||||
@@ -197,6 +246,10 @@ async def get_message_content(message_id: int) -> Tuple[Optional[str], bool]:
|
||||
"""
|
||||
try:
|
||||
cmd = f"himalaya message read {message_id}"
|
||||
if folder:
|
||||
cmd += f" -f '{folder}'"
|
||||
if account:
|
||||
cmd += f" -a '{account}'"
|
||||
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
cmd,
|
||||
@@ -216,12 +269,18 @@ async def get_message_content(message_id: int) -> Tuple[Optional[str], bool]:
|
||||
return None, False
|
||||
|
||||
|
||||
async def mark_as_read(message_id: int) -> Tuple[Optional[str], bool]:
|
||||
async def mark_as_read(
|
||||
message_id: int,
|
||||
folder: Optional[str] = None,
|
||||
account: Optional[str] = None,
|
||||
) -> Tuple[Optional[str], bool]:
|
||||
"""
|
||||
Mark a message as read by adding the 'seen' flag.
|
||||
|
||||
Args:
|
||||
message_id: The ID of the message to mark as read
|
||||
folder: The folder containing the message
|
||||
account: The account to use
|
||||
|
||||
Returns:
|
||||
Tuple containing:
|
||||
@@ -230,6 +289,10 @@ async def mark_as_read(message_id: int) -> Tuple[Optional[str], bool]:
|
||||
"""
|
||||
try:
|
||||
cmd = f"himalaya flag add seen {message_id}"
|
||||
if folder:
|
||||
cmd += f" -f '{folder}'"
|
||||
if account:
|
||||
cmd += f" -a '{account}'"
|
||||
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
cmd,
|
||||
|
||||
Reference in New Issue
Block a user