This commit is contained in:
friedemann.blume 2024-07-19 13:41:51 +02:00
parent 18f4b4e1e0
commit c3065028a3
1 changed files with 51 additions and 41 deletions

View File

@ -37,6 +37,8 @@ def format_date(date_str):
return 'NoDate'
def save_email_as_markdown(email, index, output_subdir):
logger.info(f"Starting to process email {index + 1}")
try:
subject = email.get('subject', 'No Subject')
date = email.get('date', 'No Date')
sender = email.get('from', 'Unknown Sender')
@ -70,8 +72,11 @@ def save_email_as_markdown(email, index, output_subdir):
file.write(body_markdown)
logger.info(f"Saved email {index + 1} as Markdown: {filename}")
except Exception as e:
logger.error(f"Error processing email {index + 1}: {e}")
def convert_mbox_to_markdown(mbox_file):
try:
# Create a subdirectory in the output directory with the name of the .mbox file
base_name = os.path.basename(mbox_file)
subdir_name = os.path.splitext(base_name)[0] # Remove the .mbox extension
@ -86,8 +91,13 @@ def convert_mbox_to_markdown(mbox_file):
logger.info(f"Total emails to process: {total_emails}")
for i, email in tqdm(enumerate(mbox), total=total_emails, desc='Converting emails'):
logger.info(f"Processing email {i + 1}/{total_emails}")
save_email_as_markdown(email, i, output_subdir)
logger.info(f"Completed processing {mbox_file}")
except Exception as e:
logger.error(f"Error processing mbox file {mbox_file}: {e}")
class MboxFileHandler(FileSystemEventHandler):
def on_created(self, event):
if event.is_directory: