daily pastebin goal
18%
SHARE
TWEET

Untitled

a guest Dec 12th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/env python
  2.  
  3. import poplib
  4. from email import parser
  5. import email
  6. import os
  7. import sys
  8. import string
  9. import re
  10.  
  11. pop_conn = poplib.POP3_SSL('youpopserver.yourdomain.com')
  12. pop_conn.user('yourmail@yourdomain.com')
  13. pop_conn.pass_('youpass')
  14.  
  15. #Get messages from server:
  16. messages = [pop_conn.retr(i) for i in range(1, len(pop_conn.list()[1]) + 1)]
  17. # Concat message pieces:
  18. messages = ["\n".join(mssg[1]) for mssg in messages]
  19. #Parse message intom an email object:
  20. messages = [parser.Parser().parsestr(mssg) for mssg in messages]
  21. for message in messages:
  22.     for part in message.walk():
  23.         blockit = 0
  24.  
  25.         if part.get_content_maintype() == "text" and blockit == 0:
  26.             blockit = 1
  27.             mycontent = part.get_payload()
  28.             mycontent = mycontent.decode("quopri_codec")
  29.             mycontent = re.sub('<[^>]*>', '', mycontent)
  30.             print mycontent
  31.             print
  32.             print message['subject']
  33.  
  34. pop_conn.quit()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top