-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmail_client.py
executable file
·59 lines (50 loc) · 1.51 KB
/
mail_client.py
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
import poplib
def connect_server():
mailServer = 'pop.gmail.com'
server_connection = poplib.POP3_SSL(mailServer)
return server_connection
def do_login(server_connection):
email = 'xmaquinaxmaquina@gmail.com'
emailPass = 'x1maquina2'
server_connection.user(email)
server_connection.pass_(emailPass)
def read_mail_body(connection_loged, mail_id):
mail_body = connection_loged.retr(mail_id)[1][76]
return mail_body
def delete (connection_loged, mail_id):
connection_loged.retr(mail_id)[1][13]
def check_mail_box(connection_loged):
message_count, mailbox_size = connection_loged.stat()
return message_count
def read_first_mail():
connection = connect_server()
do_login(connection)
message_count = check_mail_box(connection)
if(message_count != 0):
mail_body = read_mail_body(connection, 1)
delete(connection, 1)
connection.quit()
else:
mail_body = None
return mail_body
def read_all_mails():
cont_mail = 0
while(True):
mail = read_first_mail()
if(mail != None):
file_name = str(cont_mail+1) + ".gcode"
file = open(file_name, "w")
try:
file.write(mail.decode())
except AttributeError:
file.write(mail)
file.close()
cont_mail = cont_mail + 1
else:
break
return cont_mail
def main():
read_emails = read_all_mails()
print (read_emails)
if __name__ == "__main__":
main()