handle deleted better in sync and tui

This commit is contained in:
Tim Bendt
2025-05-02 12:18:31 -04:00
parent 615aeda3b9
commit 08eb4ee0cf
5 changed files with 27 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import os
import re
from typing import Set
import msal
import requests
import json
@@ -63,8 +64,8 @@ def synchronize_maildir(maildir_path, headers):
f'https://graph.microsoft.com/v1.0/me/messages/{message_id}',
headers=headers
)
if response.status_code != 204: # 204 No Content indicates success
print(f"Failed to move message to trash: {message_id}, {response.status_code}, {response.text}")
if response.status_code == 204: # 204 No Content indicates success
os.remove(filepath) # Remove the file from local trash
# Find messages moved to ".Archives/**/*" and move them to the "Archive" folder on the server
archive_dir = os.path.join(maildir_path, '.Archives')
@@ -301,7 +302,19 @@ for message in messages:
print(f"Processing message: {message.get('subject', 'No Subject')}", end='\r')
save_email_to_maildir(maildir_path, message, attachments_dir)
print(f"\nFinished processing {len(messages)} messages.")
print(f"\nFinished saving {len(messages)} messages.")
inbox_msg_ids = set(message['id'] for message in messages)
new_dir = os.path.join(maildir_path, 'new')
cur_dir = os.path.join(maildir_path, 'cur')
new_files = set(glob.glob(os.path.join(new_dir, '*.eml')))
cur_files = set(glob.glob(os.path.join(cur_dir, '*.eml')))
for filename in Set.union(cur_files, new_files):
message_id = filename.split('.')[0] # Extract the Message-ID from the filename
if (message_id not in inbox_msg_ids):
print(f"Deleting {filename} from inbox")
os.remove(filename)
# Fetch events with pagination and expand recurring events