Commit 514a4dbd authored by matthew.seaman's avatar matthew.seaman

Networking assigment

parents
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
SGV5IHh48J+Slg0K
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
WW91IGFscmlnaHQNCg0KX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18NCkZyb206IE1B
VFRIRVcgU0VBTUFODQpTZW50OiAyNyBOb3ZlbWJlciAyMDE3IDEwOjIxOjA4DQpUbzogbWF0dGhl
dy5zZWFtYW5AZWx3b29kLnlvcmtkYy5uZXQNClN1YmplY3Q6DQoNCkhleSB4ePCfkpYNCg==
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Yo yo yo
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Test for offline mode
from __future__ import unicode_literals
from imapclient import IMAPClient
import email
import socket
try:
print "checking internet connection.."
host = socket.gethostbyname("www.google.com")
s = socket.create_connection((host, 80), 2)
s.close()
print 'internet on.'
connection = True
except Exception,e:
print e
print "internet off."
connection = False
if connection == True:
HOST = 'elwood.yorkdc.net'
USERNAME = raw_input ("Please enter your username \n") #'matthew.seaman'
PASSWORD = raw_input ("Password \n")#'AE8LLUAD'
ssl = False
server = IMAPClient(HOST, use_uid=True, ssl=ssl)
server.login(USERNAME, PASSWORD)
select_info = server.select_folder('INBOX')
print('%d messages in INBOX' % select_info['EXISTS'])
messages = server.search(['NOT', 'DELETED'])
print("%d messages that aren't deleted" % len(messages))
print()
print("Messages:")
response = server.fetch(messages, ['FLAGS', 'RFC822.SIZE'])
for msgid, data in response.iteritems():
print(' ID %d: %d bytes, flags=%s' % (msgid,data[b'RFC822.SIZE'],data[b'FLAGS']))
while True:
userChoice = raw_input ("Weclome to the webmail client \n Please choose an option below \n 1:List \n 2:Create \n 3:Delete \n 4:Select \n 5:Examine \n 6:Status \n 7:Fetch \n 8:Logout\n")
if userChoice == '1':
list = server.list_folders(directory=u'', pattern=u'*')
print(list)
if userChoice == '2':
create = raw_input ("Enter a name for the folder you wish to create \n")
server.create_folder(create)
print(create + 'Has been created')
if userChoice == '3':
delete = raw_input ("Enter the folders name you wish to delete \n")
server.delete_folder(delete)
print(delete + 'Has been deleted')
if userChoice == '4':
select = raw_input ("Enter the folders name you wish to select \n")
server.select_folder(select,readonly=False)
print(select + 'Has been selected \n')
copySearch = raw_input ("Please select if you would like to 1:copy or 2:search \n")
if copySearch == '1':
copy = raw_input ("Enter the folders name which you wish to copy to \n")
server.copy(messages, copy)
print ("messages have been copied to" + copy)
if copySearch =='2':
print server.search(criteria=u'ALL',charset=None)
if userChoice == '5':
select = raw_input ("Enter the folders name you wish to examine \n")
server.select_folder(select,readonly=True)
print(select + 'Has been examined \n')
if userChoice == '6':
status = raw_input ("Enter the folders name you wish to see the status off \n")
print server.folder_status(status, what=None)
if userChoice == '7':
file = open ("Emails.txt","w")
fetch = server.fetch(messages, ['RFC822' , 'BODY[TEXT]'])
for msgid, data in fetch.iteritems():
msg = email.message_from_string(data['RFC822'])
a = msg.get_payload(0).as_string()
file.write(a)
print a
file.close()
if userChoice == '8':
print(USERNAME + "Has logged out")
server.logout
break
else:
if connection == False:
print ("You require internet connection to recive new emails")
print("Here are the ofline messges")
txt = open("Emails.txt","r")
for offlineEmail in txt:
print offlineEmail
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