v1.1
This commit is contained in:
parent
18f4b4e1e0
commit
c3065028a3
|
@ -37,6 +37,8 @@ def format_date(date_str):
|
||||||
return 'NoDate'
|
return 'NoDate'
|
||||||
|
|
||||||
def save_email_as_markdown(email, index, output_subdir):
|
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')
|
subject = email.get('subject', 'No Subject')
|
||||||
date = email.get('date', 'No Date')
|
date = email.get('date', 'No Date')
|
||||||
sender = email.get('from', 'Unknown Sender')
|
sender = email.get('from', 'Unknown Sender')
|
||||||
|
@ -70,8 +72,11 @@ def save_email_as_markdown(email, index, output_subdir):
|
||||||
file.write(body_markdown)
|
file.write(body_markdown)
|
||||||
|
|
||||||
logger.info(f"Saved email {index + 1} as Markdown: {filename}")
|
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):
|
def convert_mbox_to_markdown(mbox_file):
|
||||||
|
try:
|
||||||
# Create a subdirectory in the output directory with the name of the .mbox file
|
# Create a subdirectory in the output directory with the name of the .mbox file
|
||||||
base_name = os.path.basename(mbox_file)
|
base_name = os.path.basename(mbox_file)
|
||||||
subdir_name = os.path.splitext(base_name)[0] # Remove the .mbox extension
|
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}")
|
logger.info(f"Total emails to process: {total_emails}")
|
||||||
|
|
||||||
for i, email in tqdm(enumerate(mbox), total=total_emails, desc='Converting 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)
|
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):
|
class MboxFileHandler(FileSystemEventHandler):
|
||||||
def on_created(self, event):
|
def on_created(self, event):
|
||||||
if event.is_directory:
|
if event.is_directory:
|
||||||
|
|
Loading…
Reference in New Issue