forked from Charlkie/PyMail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_mail.py
79 lines (62 loc) · 1.95 KB
/
test_mail.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""Example use of the pythonMail
This files tests the runtimes of each function within the mail module
aswell as logging the output to the ./logs directory.
"""
from PyMail import Gmail
from timeit import default_timer as timer
from MailLogging import debug
Gmail = Gmail()
def __main__():
""" Runs all initialization code
Returns:
Dictionary: Contains all email information
"""
# Gets users total number of messages in all mailboxes
msgTotal = Gmail.getUserInfo()['messagesTotal']
start = timer()
# Get list of `messageTotal` messages
messages = Gmail.GetMessages().list(msgTotal)
end = timer()
print("Time to get ID's from Google:", end - start)
start = timer()
# Get list of raw messages
rawMessage = Gmail.getMessageData(messages, format='raw', log=True)
end = timer()
start = timer()
# Gets message data
messageData = Gmail.getMessageData(messages, log=True)
end = timer()
print("Time to met message data from ID's:", end - start)
start = timer()
# Get payload of message data
payloads = Gmail.getPayload(messageData, log=True)
end = timer()
print('Time to get payload from message data:', end - start)
return payloads
def testMockData(payloads):
"""Logs headers and body from payload
writes data as an object to a json file located in ./logs, also logs
all html/plain bodies as seperate .txt/.html files within the
./logs/bodies directory.
Args:
payloads (dict): return of getPayload function
"""
start = timer()
messageBodies = Gmail.unpackPayload(payloads, log=True)
end = timer()
print('Time to get message bodies:', end - start)
def testSend():
"""Sends email based of user input"""
mailData = [ input('Name: '), input('Recipient: '),
input('Subject: '), input('content: ') ]
start = timer()
Gmail.sendMessage(*mailData)
end = timer()
print('Time to send an email:', end - start)
def testAll():
"""Tests all functions"""
payloads = __main__()
testMockData(payloads)
testSend()
if __name__ == '__main__':
testAll()