Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import imaplib
  2. import email
  3. import re
  4.  
  5. def get_message_count(connection):
  6. _, n = connection.select("INBOX")
  7. return int(n[0])
  8.  
  9. def extract_email(from_header):
  10. for match in re.findall(r"<(.+)>", str(message["from"])):
  11. return match
  12. return None
  13.  
  14. def delete_first_message(connection):
  15. connection.store("1", "+FLAGS", r"(\Deleted)")
  16. connection.expunge()
  17.  
  18. if __name__ == '__main__':
  19. connection = imaplib.IMAP4_SSL("imap.poczta.onet.pl")
  20. connection.login("janko.muzykant666@onet.pl", "abcdeF1@")
  21. while get_message_count(connection) > 0:
  22. _, data = connection.fetch("1", "(RFC822)")
  23. for response in data:
  24. if isinstance(response, tuple):
  25. message = email.message_from_bytes(response[1])
  26. from_email = extract_email(message["from"])
  27. delete_first_message(connection)
  28. connection.logout()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement