basic email tui working
This commit is contained in:
@@ -31,7 +31,6 @@ def save_sync_timestamp():
|
||||
with open(sync_timestamp_file, 'w') as f:
|
||||
json.dump({'last_sync': time.time()}, f)
|
||||
|
||||
# Function to synchronize maildir with the server
|
||||
def synchronize_maildir(maildir_path, headers):
|
||||
last_sync = load_last_sync_timestamp()
|
||||
current_time = time.time()
|
||||
@@ -67,6 +66,37 @@ def synchronize_maildir(maildir_path, 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}")
|
||||
|
||||
# Find messages moved to ".Archives/**/*" and move them to the "Archive" folder on the server
|
||||
archive_dir = os.path.join(maildir_path, '.Archives')
|
||||
archive_files = glob.glob(os.path.join(archive_dir, '**', '*.eml'), recursive=True)
|
||||
|
||||
# Fetch the list of folders to find the "Archive" folder ID
|
||||
print("Fetching server folders to locate 'Archive' folder...")
|
||||
folder_response = requests.get('https://graph.microsoft.com/v1.0/me/mailFolders', headers=headers)
|
||||
if folder_response.status_code != 200:
|
||||
raise Exception(f"Failed to fetch mail folders: {folder_response.status_code}, {folder_response.text}")
|
||||
|
||||
folders = folder_response.json().get('value', [])
|
||||
archive_folder_id = None
|
||||
for folder in folders:
|
||||
if folder.get('displayName', '').lower() == 'archive':
|
||||
archive_folder_id = folder.get('id')
|
||||
break
|
||||
|
||||
if not archive_folder_id:
|
||||
raise Exception("No folder named 'Archive' found on the server.")
|
||||
|
||||
for filepath in archive_files:
|
||||
message_id = os.path.basename(filepath).split('.')[0] # Extract the Message-ID from the filename
|
||||
print(f"Moving message to 'Archive' folder: {message_id}")
|
||||
response = requests.post(
|
||||
f'https://graph.microsoft.com/v1.0/me/messages/{message_id}/move',
|
||||
headers=headers,
|
||||
json={'destinationId': archive_folder_id}
|
||||
)
|
||||
if response.status_code != 201: # 201 Created indicates success
|
||||
print(f"Failed to move message to 'Archive': {message_id}, {response.status_code}, {response.text}")
|
||||
|
||||
# Save the current sync timestamp
|
||||
save_sync_timestamp()
|
||||
|
||||
@@ -115,7 +145,7 @@ def save_email_to_maildir(maildir_path, email_data, attachments_dir):
|
||||
if email_data.get('body', {}).get('contentType', '').lower() == 'html':
|
||||
markdown_converter = html2text.HTML2Text()
|
||||
markdown_converter.ignore_images = True
|
||||
markdown_converter.ignore_links = False
|
||||
markdown_converter.ignore_links = True
|
||||
body_markdown = markdown_converter.handle(body_html)
|
||||
else:
|
||||
body_markdown = body_html
|
||||
|
||||
Reference in New Issue
Block a user