MCPcopy Index your code
hub / github.com/ndleah/python-mini-project / readMails

Function readMails

Mail_Checker/mail_checker.py:16–42  ·  view source on GitHub ↗
(address)

Source from the content-addressed store, hash-verified

14
15
16def readMails(address):
17 result, data = mail.search(None, '(FROM '+'"'+address+'")') #If you would like to view mails that are sent to another mail, change FROM into TO
18
19 ids = data[0] # data is a list.
20 id_list = ids.split()
21 latest_email_id = id_list[-1] # gets the latest mail from the particular user
22
23
24 result, data = mail.fetch(latest_email_id, "(RFC822)")
25
26
27 basic_email = data[0][1]
28 # contains all information including payloads and html content
29
30 index_start1 = basic_email.index(b'Subject') #Starting index for your subject
31 index_end1 = index_start1 + 40 # Change the value of 40 into any other value to suit your preferences
32
33
34 subject = basic_email[index_start1:index_end1] #seperating the subject alone from the rest of the basic email
35
36
37
38 subject = subject.strip(b'b\'Subject:') #removing additional unneccessary data from the subject
39 subject_end = subject.index(b'\r')
40
41 print('-------FROM '+address+'-------\n\n') #Printing the emails
42 print("Subject: ", subject[0:subject_end], '\n\n')
43
44
45

Callers 1

mail_checker.pyFile · 0.85

Calls 3

searchMethod · 0.80
splitMethod · 0.80
stripMethod · 0.80

Tested by

no test coverage detected