Use str.strip for compatibility with Python 3.
Support both configparser and ConfigParser for compatibility with Python 3.
Leverage IMAP search to identify the messages to delete.

Instead of going through the whole folder, which can easily be _huge_,
leverage the ability to search for all messages sent before a given
date to fetch everything from maxage+1 days ago and earlier.

This makes it possible to fetch much less data than before, especially
when doing the cleanup daily.
Use BODY.PEEK to avoid having to store/restore the \Seen flag.
Fetch and process all messages right after the search.

Thanks to IMAP4's search and peek capabilities, it's easier to just
iterate over all the messages found once, rather than having a number
of iterations over the same data.
Use email.message_from_string instead of reimplementing it.
Pre-format the trash folder name.
Pre-calculate what action to print, to reduce the branching.
Execute archive/delete actions only once per label.

When archiving, there is no copy happening; when deleting, it's not
necessary to remove the label (actually, it can be worse, as then the
label is no longer visible in the Trash folder on the webmail).

Since only one of the two action has to be executed, it's possible to
apply a batch operation on the messages, archiving or deleting them at
once. It was not possible when doing copy and flag setting, as then
the second operation would get a different input set from the first.
Add a rewritten script in Perl.

While trying to make the script work with Python 3 and improving its
performance, I ended up porting the same logic over to Perl. The new
script is twice the speed as the Python version, and supports GMail's
extensions to identify the Trash folder.
Update documentation with a MarkDown README.
Fix link syntax.
pl: use the XLIST method to find the trash folder.

While this method is deprecated on the protocol level,
Mail::IMAPClient implements it directly, faster than our parsing here.
pl: add support for wildcard-matching of labels.

This also avoids trying to enter folders that are not selectable (for
example because they do not exist), and is needed if you have
structured folders without a top-level entry.
Ran it through reindent.py

reindent.py is available on pythontrunk/Tools/scripts/reindent.py
Python3 fixes

I ran the script with --pretend on Py2.6,2.7,3.2 and 3.3
Fixed missing newline in python3
Moved the message header fetching inside the verbose flow

just like in the perl script
also, fixed the small unneeded ugliness of len(range(data))//2
Global variables are icky, and they're not even needed here

also, fixed a possible problem when accessing the config's labels multiple times
also, removed unused imports
Fix error checking

config.read doesn't raise exceptions on missing/unreadable files
but instead returns a list of successfully read filenames