-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple.py
More file actions
170 lines (143 loc) · 4.76 KB
/
Copy pathsimple.py
File metadata and controls
170 lines (143 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import socket, ssl, base64, getpass, os, platform
#--------------------------------------
mailserver = ('imap.gmail.com', 993)
#--------------------------------------
sslSocket = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM),
ssl_version = ssl.PROTOCOL_SSLv23)
sslSocket.connect(mailserver)
recv = sslSocket.recv(1024)
print recv
#--------------------------------------
#PROMPT USER FOR USERNAME
def getuser():
user = raw_input('Enter username (gmail): ')
return user
#MENU DISPLAY
def menu(user, passwd):
if platform.system() == 'Windows': #CLEARS TERMINAL/COMMAND PROMPT FOR A MORE VISUALLY FRIENDLY UI
os.system('cls')
else:
os.system('clear')
print '--------------------------------------------------------------------------'
print 'Welcome, ' + user + '. Please select an option from the list below: '
print '--------------------------------------------------------------------------'
print ' 1) LIST \n 2) SEARCH \n 3) FETCH \n 4) EXAMINE \n 5) CREATE \n 6) DELETE \n 7) UID'
print '--------------------------------------------------------------------------'
print '--------------------------------------------------------------------------'
choice = raw_input('-> ')
if choice == '1':
list(user, passwd)
if choice == '2':
search(user, passwd)
if choice == '3':
fetch(user, passwd)
if choice == '4':
examine(user, passwd)
if choice == '5':
create(user, passwd)
if choice == '6':
delete(user, passwd)
if choice == '7':
uid(user, passwd)
else:
print choice + 'is not a valid option. Please try again: '
menu(user, passwd)
return
#LOOP MENU
def loopmenu(user, passwd):
choice = raw_input('Back to menu? ')
if choice.lower() in ['y', 'yes']:
menu(user, passwd)
if choice.lower() in ['n', 'no']:
print 'END'
else:
print 'Please enter YES or NO'
loopmenu(user,passwd)
#LOGIN
def login(user, passwd):
sslSocket.send('A001 LOGIN ' + user + ' ' + passwd + '\r\n')
recv = sslSocket.recv(1024)
print recv
return
#LIST MAILBOXES
def list(user, passwd):
mailbox = raw_input('Mailbox to list, ("/" to list root mailbox): ')
sslSocket.send('A002 LIST "'+ mailbox +'" *\r\n')
recv = sslSocket.recv(1024)
print recv
loopmenu(user, passwd)
return
#SEARCH MAILBOX FOR MAIL CONTAINING SERCH TERMS
def search(user, passwd):
mailbox = raw_input('Enter the name of the mailbox you wish to search: ')
sslSocket.send('A003 EXAMINE ' + mailbox + '\r\n') #EXAMINE THIS MAILBOX FOR SEARCH
recv = sslSocket.recv(1024)
print recv
search = raw_input('Enter search terms: ')
sslSocket.send('A004 SEARCH ' + search + '\r\n') #SEARCH EXAMINED MAILBOX CONTAINING SEARCH TERMS
recv = sslSocket.recv(1024)
print recv
loopmenu(user, passwd)
return
#FETCH FUNCTION FIRST EXAMINES MAILBOX TO FETCH FROM, THEN FETCHES HEADER + BODY
def fetch(user, passwd):
mailbox = raw_input('Enter the name of the mailbox from which you wish to fetch: ')
sslSocket.send('A005 EXAMINE ' + mailbox + '\r\n')
recv = sslSocket.recv(1024)
print recv
email = raw_input ('Enter email to fetch: ')
sslSocket.send('A006 FETCH ' + email + ' BODY[0]\r\n') #FETCH HEADER
recv = sslSocket.recv(1024)
print recv
print '\n\n'
sslSocket.send('A007 FETCH ' + email + ' BODY[1]\r\n') #FETCH BODY
recv = sslSocket.recv(1024)
print recv
loopmenu(user, passwd)
return
#EXAMINE FUNCTION
def examine(user, passwd):
mailbox = raw_input('Enter name of mailbox to examine: ')
sslSocket.send('A008 EXAMINE ' + mailbox + '\r\n')
recv = sslSocket.recv(1024)
print recv
loopmenu(user, passwd)
return
#CREATE FUNCTION
def create(user, passwd):
folder = raw_input('Enter the name of the folder you wish to create: ')
sslSocket.send('A009 CREATE ' + folder + '\r\n')
recv = sslSocket.recv(1024)
print recv
loopmenu(user, passwd)
return
#DELETE FUNCTION
def delete(user, passwd):
folder = raw_input('Enter the name of the folder you wish to delete: ')
sslSocket.send('A010 DELETE ' + folder + '\r\n')
recv = sslSocket.recv(1024)
print recv
loopmenu(user, passwd)
return
#GET UID FUNCTION
def uid(user, passwd):
mailbox = raw_input('Mailbox for UID search/fetch: ')
sslSocket.send('A011 EXAMINE ' + mailbox + '\r\n') #EXAMINE THIS MAILBOX
recv = sslSocket.recv(1024)
print recv
search = raw_input('Enter FLAG (e.g. TEXT, FROM, etc.) and search term (UID will be returned): ')
sslSocket.send('A012 UID SEARCH ' + search + '\r\n') #SEARCH THIS MAILBOX WITH SEARCH TERMS
recv = sslSocket.recv(1024)
print recv
uid = raw_input('Enter UID to fetch email: ')
sslSocket.send('A013 UID FETCH ' + uid + '\r\n') #RETURN UID OF EMAIL CONTAINING SEARCH TERMS
recv = sslSocket.recv(1024)
print recv
loopmenu(user, passwd)
return
#MAIN
if __name__ == '__main__':
user = getuser()
passwd = getpass.getpass() #HIDES USER PASSWORD
login(user, passwd)
menu(user, passwd)