Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/env python
- import poplib
- from email import parser
- import email
- import os
- import sys
- import string
- import re
- pop_conn = poplib.POP3_SSL('youpopserver.yourdomain.com')
- pop_conn.user('yourmail@yourdomain.com')
- pop_conn.pass_('youpass')
- #Get messages from server:
- messages = [pop_conn.retr(i) for i in range(1, len(pop_conn.list()[1]) + 1)]
- # Concat message pieces:
- messages = ["\n".join(mssg[1]) for mssg in messages]
- #Parse message intom an email object:
- messages = [parser.Parser().parsestr(mssg) for mssg in messages]
- for message in messages:
- for part in message.walk():
- blockit = 0
- if part.get_content_maintype() == "text" and blockit == 0:
- blockit = 1
- mycontent = part.get_payload()
- mycontent = mycontent.decode("quopri_codec")
- mycontent = re.sub('<[^>]*>', '', mycontent)
- print mycontent
- print
- print message['subject']
- pop_conn.quit()
Add Comment
Please, Sign In to add comment