First things first, we need to import the sys module so we can accept the path of the mailbox as an argument instead of hardwiring it into the program.
import sysNext, we need to import the mailbox module. The mailbox module enables one to manipulate email messages, representing mailboxes as objects and messages as dictionaries. Unlike poplib and other email-related modules, mailbox is for local use only.
import mailboxIf you want to take a peak at the module documentation that comes with the mailboxmodule, open a Python shell, import the module (as above), and type "help(mailbox)" at the prompt.
Next, we define the main function of our program. Note that, as a matter of good practice, it is worth putting a bang line at the head of the program file, as well as a docstring:
#!/usr/bin/env python
"""Extract and print all email recipients from a user-defined mailbox."""
