Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import imaplib
- import email
- import re
- def get_message_count(connection):
- _, n = connection.select("INBOX")
- return int(n[0])
- def extract_email(from_header):
- for match in re.findall(r"<(.+)>", str(message["from"])):
- return match
- return None
- def delete_first_message(connection):
- connection.store("1", "+FLAGS", r"(\Deleted)")
- connection.expunge()
- if __name__ == '__main__':
- connection = imaplib.IMAP4_SSL("imap.poczta.onet.pl")
- connection.login("janko.muzykant666@onet.pl", "abcdeF1@")
- while get_message_count(connection) > 0:
- _, data = connection.fetch("1", "(RFC822)")
- for response in data:
- if isinstance(response, tuple):
- message = email.message_from_bytes(response[1])
- from_email = extract_email(message["from"])
- delete_first_message(connection)
- connection.logout()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement