parser.BytesFeedParser().Close() return empty list in Python's email.parser

Viewed 27

I'm trying to parse all emails from my mail-server.But when I try to process the data with using close() from Python's email.parser.BytesFeedParser,I get empty list error:

IndexError: pop from empty list 

The code like belows:

client = poplib.POP3(host=theServer)
client.user(user=user)
client.pass_(pswd=password)

oriData = [client.retr(i)[1] for i in range(1, len(client.list()[1]) + 1)]

a = parser.BytesFeedParser()
for eleList in oriData:
    for ele in eleList:
        print(ele)
        a.feed(ele)
        print(a)
    test = a.close()

In the python's related docs,it said:

close() Complete the parsing of all previously fed data and return the root message object. It is undefined what happens if feed() is called after this method has been called.

That makes me confused.I construe it as when I apply the close(),it will return the EmailMessage object.I'm sure that the feeded data is not null but it finally return an empty list.I have searched this problem with many search-engines but get no answers so I push this question in stackoverflow. Can someone help me and explain why I make this mistake?

0 Answers
Related