Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

""" 

@file 

@brief Helper around POP server 

""" 

 

import poplib 

 

from pyquickhelper.loghelper import noLOG 

 

 

def retrieve_mails_pop(user, password, server, begin=0, end=-1, fLOG=noLOG): 

""" 

retrieves all emails using POP service 

 

@param user user 

@param password password 

@param server something like ``pop.domain.ext`` 

@param begin first email to retrieve 

@param end last email to retrieve 

@param fLOG logging function 

@return list of emails 

""" 

M = poplib.POP3(server) 

M.user(user) 

M.pass_(password) 

messageList = M.list() 

numMessages = len(messageList[1]) 

allemails = [] 

stat = M.stat() 

fLOG("[retrieve_mails_pop]", stat) 

end = numMessages if end == -1 else end 

for i in range(begin, end): 

mail = M.retr(i + 1) 

size = mail[2] 

#response = mail[0] 

allemails.append(mail[1]) 

fLOG( 

"retrieve_mails_pop [mail {0}/{1}, size={2}]".format(i, end, size)) 

return allemails