diff --git a/main.py b/main.py index aa57f5b..13ad9d5 100644 --- a/main.py +++ b/main.py @@ -203,11 +203,11 @@ async def read_mail_handler(update: Update, context: ContextTypes.DEFAULT_TYPE, # Get the email filename (array is 0-indexed) email_filename = emails[email_num - 1] - email_path = f"/var/mail/fymio.us/me/new/{email_filename}" + email_path_new = f"/var/mail/fymio.us/me/new/{email_filename}" # Read email content using docker exec result = subprocess.run( - ['docker', 'exec', 'mailserver', 'cat', email_path], + ['docker', 'exec', 'mailserver', 'cat', email_path_new], capture_output=True, timeout=10 ) @@ -260,6 +260,29 @@ async def read_mail_handler(update: Update, context: ContextTypes.DEFAULT_TYPE, h.ignore_emphasis = False body = h.handle(html_body) + # Move email from new/ to cur/ (mark as read) + # In Maildir format, files in cur/ should have :2, suffix with flags + email_filename_cur = email_filename.replace(',S=', ':2,S') # Add :2, flag + if ':2,' not in email_filename_cur: + # If filename doesn't have standard format, just add :2, + email_filename_cur = email_filename + ':2,' + + email_path_cur = f"/var/mail/fymio.us/me/cur/{email_filename_cur}" + + # Move the file + move_result = subprocess.run( + ['docker', 'exec', 'mailserver', 'mv', email_path_new, email_path_cur], + capture_output=True, + timeout=5 + ) + + if move_result.returncode == 0: + logger.info(f"Moved email from new/ to cur/: {email_filename}") + # Remove this email from the context so it won't show up in the list anymore + context.user_data['emails'].pop(email_num - 1) + else: + logger.warning(f"Failed to move email to cur/: {move_result.stderr.decode()}") + # Truncate body if too long (Telegram has message length limits) max_body_length = 3000 if len(body) > max_body_length: