To download the messages, we first need to retrieve how many there
are. To do this, we use Python's built-in len()
conjunction with the list()
method of the Mailbox class.
messageCount = len(Mailbox.list())
Then we simply set up a loop that counts the messages and retrieves each message in sequence
until the end of the box is reached.
for i in range(messageCount):
for j in Mailbox.retr(i+1):
This merely prints the messages to the screen. Naturally, if you have
more than a couple messages on the server, you will not get to see
them all in one go. It is best, therefore, to either pipe
to a text file or rewrite the code to write it to a file
named after the server address input by the user.