diff --git a/fetch_outlook.py b/fetch_outlook.py index 4a2c7e2..a4bed74 100644 --- a/fetch_outlook.py +++ b/fetch_outlook.py @@ -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 diff --git a/maildir_gtd/app.py b/maildir_gtd/app.py index 4063ff1..30f6a31 100644 --- a/maildir_gtd/app.py +++ b/maildir_gtd/app.py @@ -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: diff --git a/maildir_gtd/email_viewer.tcss b/maildir_gtd/email_viewer.tcss index a4333e0..a10954e 100644 --- a/maildir_gtd/email_viewer.tcss +++ b/maildir_gtd/email_viewer.tcss @@ -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; } diff --git a/maildir_gtd/widgets/EnvelopeHeader.py b/maildir_gtd/widgets/EnvelopeHeader.py index 2277b49..f0fdd4d 100644 --- a/maildir_gtd/widgets/EnvelopeHeader.py +++ b/maildir_gtd/widgets/EnvelopeHeader.py @@ -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"), diff --git a/maildir_gtd/widgets/__pycache__/EnvelopeHeader.cpython-311.pyc b/maildir_gtd/widgets/__pycache__/EnvelopeHeader.cpython-311.pyc index d2815e0..e64d9db 100644 Binary files a/maildir_gtd/widgets/__pycache__/EnvelopeHeader.cpython-311.pyc and b/maildir_gtd/widgets/__pycache__/EnvelopeHeader.cpython-311.pyc differ