Add folder message counts to mail app sidebar
This commit is contained in:
@@ -115,6 +115,47 @@ async def list_folders(
|
||||
return [], False
|
||||
|
||||
|
||||
async def get_folder_count(
|
||||
folder: str,
|
||||
account: Optional[str] = None,
|
||||
) -> Tuple[int, bool]:
|
||||
"""
|
||||
Get the count of messages in a folder.
|
||||
|
||||
Args:
|
||||
folder: The folder to count messages in
|
||||
account: The account to use (defaults to default account)
|
||||
|
||||
Returns:
|
||||
Tuple containing:
|
||||
- Message count
|
||||
- Success status (True if operation was successful)
|
||||
"""
|
||||
try:
|
||||
# Use a high limit to get all messages, then count them
|
||||
# This is the most reliable way with himalaya
|
||||
cmd = f"himalaya envelope list -o json -s 9999 -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:
|
||||
envelopes = json.loads(stdout.decode())
|
||||
return len(envelopes), True
|
||||
else:
|
||||
logging.error(f"Error getting folder count: {stderr.decode()}")
|
||||
return 0, False
|
||||
except Exception as e:
|
||||
logging.error(f"Exception during folder count: {e}")
|
||||
return 0, False
|
||||
|
||||
|
||||
async def delete_message(
|
||||
message_id: int,
|
||||
folder: Optional[str] = None,
|
||||
|
||||
Reference in New Issue
Block a user