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

View File

@@ -269,11 +269,13 @@ class EmailViewerApp(App):
def action_delete(self) -> None:
self.all_envelopes.remove(self.all_envelopes[self.current_message_index])
self.message_body_cache.pop(self.current_message_id, None)
self.query_one(StatusTitle).total_messages = len(self.all_envelopes)
delete_current(self)
def action_archive(self) -> None:
self.all_envelopes.remove(self.all_envelopes[self.current_message_index])
self.message_body_cache.pop(self.current_message_id, None)
self.query_one(StatusTitle).total_messages = len(self.all_envelopes)
archive_current(self)
def action_open(self) -> None:

View File

@@ -27,7 +27,7 @@ EnvelopeHeader {
dock: top;
margin-top: 1;
width: 100%;
height: 1;
max-height: 2;
tint: $primary 10%;
}
@@ -49,8 +49,11 @@ ListView {
.header_key {
tint: gray 20%;
min-width: 10;
}
.header_value {
padding:0 1 0 0;
height: auto;
width: auto;
}

View File

@@ -18,12 +18,14 @@ class EnvelopeHeader(ScrollableContainer):
def compose(self) -> ComposeResult:
yield Horizontal(
yield Horizontal(
Label("Subject:", classes="header_key"),
Label(self.subject, classes="header_value", markup=False, id="subject"),
Label(self.subject, classes="header_value", markup=False, id="subject")
)
yield Horizontal(
Label("Date:", classes="header_key"),
Label(self.date, classes="header_value", markup=False, id="date"),
)
)
# yield Horizontal(
# Label("From:", classes="header_key"),
# Label(self.from_, classes="header_value", markup=False, id="from"),