Guest User

Untitled

a guest
Oct 19th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. def removeFromInbox(self, criteria):
  2. imap = imaplib.IMAP4_SSL(host=self.host)
  3. imap.login(user=self.user, password=self.password)
  4. imap.select(mailbox="INBOX", readonly=True)
  5.  
  6. #Get uniq id
  7. result, data = imap.uid("search", None, "ALL")
  8. uids = data[0].split()
  9.  
  10. for uid in uids:
  11. res, dat = imap.uid("fetch", uid, "(RFC822)")
  12. message = email.message_from_bytes(dat[0][1])
  13.  
  14. if criteria(message):
  15.  
  16. print(imap.uid('store', uid, '+FLAGS', '(Deleted)'))
  17. print("Deleting message " + message["Subject"])
  18. print(imap.expunge())
Add Comment
Please, Sign In to add comment