Commit 2e708d22 authored by gregory.swedeen's avatar gregory.swedeen

First commit for project ImapClient

parents
from imapclient import IMAPClient
import email
from email.utils import parseaddr
server = None
USERNAME = None
Password = None
def login():
global server
global USERNAME
global PASSWORD
HOST = 'elwood.yorkdc.net'
ssl = False
USERNAME = "gregory.swedeen"
PASSWORD = "RS85X7WR"
server = IMAPClient(HOST, use_uid = True, ssl=ssl)
server.login(USERNAME, PASSWORD)
def showInbox():
global server
select_info = server.select_folder('INBOX')
print('%d messages in INBOX' % select_info[b'EXISTS'])
messages = server.search(['NOT', 'DELETED'])
print()
print("Inbox: ")
print("| ID | Subject | Sender | Date |")
for msgid, data in server.fetch(messages, ['ENVELOPE']).items():
envelope = data[b'ENVELOPE']
name = str(envelope.sender)
sender = name.split("'")
print('| %d | %s |%s | %s |' % (msgid, envelope.subject.decode(), sender[1],envelope.date))
print ("Type the number that corresponds to the email you wish to view, or type 0 for the menu.")
viewOption = raw_input("-->")
if viewOption == "menu":
menuScreen()
else:
fullmsg = server.fetch(viewOption, ['RFC822', 'BODY[TEXT]'])
for msgid, data in fullmsg.iteritems():
parsedEmail = email.message_from_string(data['RFC822'])
body = email.message_from_string(data['BODY[TEXT]'])
parsedBody = parsedEmail.get_payload(0)
print parsedBody
print("Return to menu? (Yes, No)")
temp = raw_input("-->")
if temp == "Yes" or "yes":
menuScreen()
elif temp == "No" or "no":
showInbox()
else:
server.logout()
def errhandler():
print("Enter a number that corresponds to an action.")
menuScreen()
def menuScreen():
print("Type the corresponding number to the action you wish to perform.")
print("1 : Inbox")
print("2 : Logout")
choice = input("-->")
if choice == 1:
showInbox()
elif choice == 2:
server.logout()
else:
errhandler()
login()
menuScreen()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment