To download the messages, we first need to retrieve how many there
are. To do this, we use Python's built-in
len() function in
conjunction with the
list() method of the Mailbox class.
messageCount = len(Mailbox.list()[1])
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)[1]:
print j
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 the output
to a text file or rewrite the code to
write it to a file, perhaps
named after the server address input by the user.