Counting Messages in IMAP Folders in Python

Continuing on my last post (), I wanted to show a snippet of Python code that will list a set of IMAP folders and count the number of messages in them. You give it a starting folder and it lists that folder plus all/any sub-folders and their message counts. At the very end it prints a total message count.