basically refactored the email viewer
This commit is contained in:
@@ -5,6 +5,7 @@ import os
|
||||
import json
|
||||
import time
|
||||
from datetime import datetime
|
||||
import email.utils
|
||||
|
||||
def truncate_id(message_id, length=8):
|
||||
"""
|
||||
@@ -67,6 +68,24 @@ def format_datetime(dt_str, format_string="%m/%d %I:%M %p"):
|
||||
except (ValueError, AttributeError):
|
||||
return dt_str
|
||||
|
||||
def format_mime_date(dt_str):
|
||||
"""
|
||||
Format a datetime string from ISO format to RFC 5322 format for MIME Date headers.
|
||||
|
||||
Args:
|
||||
dt_str (str): ISO format datetime string.
|
||||
|
||||
Returns:
|
||||
str: Formatted datetime string in RFC 5322 format.
|
||||
"""
|
||||
if not dt_str:
|
||||
return ""
|
||||
try:
|
||||
dt = datetime.fromisoformat(dt_str.replace('Z', '+00:00'))
|
||||
return email.utils.format_datetime(dt)
|
||||
except (ValueError, AttributeError):
|
||||
return dt_str
|
||||
|
||||
def safe_filename(filename):
|
||||
"""
|
||||
Convert a string to a safe filename.
|
||||
|
||||
@@ -13,7 +13,7 @@ import aiohttp
|
||||
import re
|
||||
|
||||
from utils.calendar_utils import truncate_id
|
||||
from utils.mail_utils.helpers import safe_filename, ensure_directory_exists, format_datetime
|
||||
from utils.mail_utils.helpers import safe_filename, ensure_directory_exists, format_datetime, format_mime_date
|
||||
|
||||
async def save_mime_to_maildir_async(maildir_path, message, attachments_dir, headers, progress, dry_run=False, download_attachments=False):
|
||||
"""
|
||||
@@ -92,10 +92,10 @@ async def create_mime_message_async(message, headers, attachments_dir, progress,
|
||||
cc_list = [f"{r.get('emailAddress', {}).get('name', '')} <{r.get('emailAddress', {}).get('address', '')}>".strip() for r in cc_recipients]
|
||||
mime_msg['Cc'] = ', '.join(cc_list)
|
||||
|
||||
# Date
|
||||
# Date - using the new format_mime_date function to ensure RFC 5322 compliance
|
||||
received_datetime = message.get('receivedDateTime', '')
|
||||
if received_datetime:
|
||||
mime_msg['Date'] = received_datetime
|
||||
mime_msg['Date'] = format_mime_date(received_datetime)
|
||||
|
||||
# First try the direct body content approach
|
||||
message_id = message.get('id', '')
|
||||
|
||||
Reference in New Issue
Block a user