29 lines
795 B
Python
29 lines
795 B
Python
#!/usr/bin/env python3
|
|
"""Move specific email to trash"""
|
|
import imaplib
|
|
import email
|
|
|
|
# Connect
|
|
mail = imaplib.IMAP4_SSL('imap.migadu.com', 993)
|
|
mail.login('youlu@luyanxin.com', 'kDkNau2r7m.hV!uk*D4Yr8mC7Dyjx9T')
|
|
mail.select('INBOX')
|
|
|
|
# Search for the email with "10% off" in subject
|
|
_, search_data = mail.search(None, 'SUBJECT', '"10% off"')
|
|
email_ids = search_data[0].split()
|
|
|
|
print(f"Found {len(email_ids)} emails with '10% off' in subject")
|
|
|
|
for email_id in email_ids:
|
|
# Copy to Trash
|
|
result = mail.copy(email_id, 'Trash')
|
|
if result[0] == 'OK':
|
|
mail.store(email_id, '+FLAGS', '\\Deleted')
|
|
print(f"✅ Moved email {email_id.decode()} to Trash")
|
|
else:
|
|
print(f"❌ Failed to move email {email_id.decode()}")
|
|
|
|
mail.expunge()
|
|
mail.logout()
|
|
print("Done!")
|