upd
This commit is contained in:
27
main.py
27
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)
|
# Get the email filename (array is 0-indexed)
|
||||||
email_filename = emails[email_num - 1]
|
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
|
# Read email content using docker exec
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
['docker', 'exec', 'mailserver', 'cat', email_path],
|
['docker', 'exec', 'mailserver', 'cat', email_path_new],
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
timeout=10
|
timeout=10
|
||||||
)
|
)
|
||||||
@@ -260,6 +260,29 @@ async def read_mail_handler(update: Update, context: ContextTypes.DEFAULT_TYPE,
|
|||||||
h.ignore_emphasis = False
|
h.ignore_emphasis = False
|
||||||
body = h.handle(html_body)
|
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)
|
# Truncate body if too long (Telegram has message length limits)
|
||||||
max_body_length = 3000
|
max_body_length = 3000
|
||||||
if len(body) > max_body_length:
|
if len(body) > max_body_length:
|
||||||
|
|||||||
Reference in New Issue
Block a user