handle deleted better in sync and tui
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from typing import Set
|
||||||
import msal
|
import msal
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
@@ -63,8 +64,8 @@ def synchronize_maildir(maildir_path, headers):
|
|||||||
f'https://graph.microsoft.com/v1.0/me/messages/{message_id}',
|
f'https://graph.microsoft.com/v1.0/me/messages/{message_id}',
|
||||||
headers=headers
|
headers=headers
|
||||||
)
|
)
|
||||||
if response.status_code != 204: # 204 No Content indicates success
|
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}")
|
os.remove(filepath) # Remove the file from local trash
|
||||||
|
|
||||||
# Find messages moved to ".Archives/**/*" and move them to the "Archive" folder on the server
|
# Find messages moved to ".Archives/**/*" and move them to the "Archive" folder on the server
|
||||||
archive_dir = os.path.join(maildir_path, '.Archives')
|
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')
|
print(f"Processing message: {message.get('subject', 'No Subject')}", end='\r')
|
||||||
save_email_to_maildir(maildir_path, message, attachments_dir)
|
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
|
# Fetch events with pagination and expand recurring events
|
||||||
|
|||||||
@@ -269,11 +269,13 @@ class EmailViewerApp(App):
|
|||||||
def action_delete(self) -> None:
|
def action_delete(self) -> None:
|
||||||
self.all_envelopes.remove(self.all_envelopes[self.current_message_index])
|
self.all_envelopes.remove(self.all_envelopes[self.current_message_index])
|
||||||
self.message_body_cache.pop(self.current_message_id, None)
|
self.message_body_cache.pop(self.current_message_id, None)
|
||||||
|
self.query_one(StatusTitle).total_messages = len(self.all_envelopes)
|
||||||
delete_current(self)
|
delete_current(self)
|
||||||
|
|
||||||
def action_archive(self) -> None:
|
def action_archive(self) -> None:
|
||||||
self.all_envelopes.remove(self.all_envelopes[self.current_message_index])
|
self.all_envelopes.remove(self.all_envelopes[self.current_message_index])
|
||||||
self.message_body_cache.pop(self.current_message_id, None)
|
self.message_body_cache.pop(self.current_message_id, None)
|
||||||
|
self.query_one(StatusTitle).total_messages = len(self.all_envelopes)
|
||||||
archive_current(self)
|
archive_current(self)
|
||||||
|
|
||||||
def action_open(self) -> None:
|
def action_open(self) -> None:
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ EnvelopeHeader {
|
|||||||
dock: top;
|
dock: top;
|
||||||
margin-top: 1;
|
margin-top: 1;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 1;
|
max-height: 2;
|
||||||
tint: $primary 10%;
|
tint: $primary 10%;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,8 +49,11 @@ ListView {
|
|||||||
|
|
||||||
.header_key {
|
.header_key {
|
||||||
tint: gray 20%;
|
tint: gray 20%;
|
||||||
|
min-width: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header_value {
|
.header_value {
|
||||||
padding:0 1 0 0;
|
padding:0 1 0 0;
|
||||||
|
height: auto;
|
||||||
|
width: auto;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,14 @@ class EnvelopeHeader(ScrollableContainer):
|
|||||||
|
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Horizontal(
|
yield Horizontal(
|
||||||
Label("Subject:", classes="header_key"),
|
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("Date:", classes="header_key"),
|
||||||
Label(self.date, classes="header_value", markup=False, id="date"),
|
Label(self.date, classes="header_value", markup=False, id="date"),
|
||||||
)
|
)
|
||||||
# yield Horizontal(
|
# yield Horizontal(
|
||||||
# Label("From:", classes="header_key"),
|
# Label("From:", classes="header_key"),
|
||||||
# Label(self.from_, classes="header_value", markup=False, id="from"),
|
# Label(self.from_, classes="header_value", markup=False, id="from"),
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user