Long story short, I created a new gmail account, and linked several other accounts to it (each with 1000s of messages), which I am importing. All imported messages arrive as unread, but I need them to appear as read.
I have a little experience with python, but I've only used mail and imaplib modules for sending mail, not processing accounts.
Is there a way to bulk process all items in an inbox, and simply mark messages older than a specified date as read?
Based on Philip T.'s answer above and RFC 3501 and RFC 2822, I built some lines of code to mark mails older than 10 days as read. A static list is used for the abbreviated month names. This is not particularly elegant, but Python's %b format string is locale dependent, which could give unpleasant surprises. All IMAP commands are UID based.
By the way: I do not know, why "-" had to be used as a date delimiter in the search string in my case (dovecot IMAP server). To me that seems to contradict RFC 2822. However, dates with simple whitespace as delimiter only returned IMAP errors.
This is a slight modification of the code in the imaplib doc page for the store method. I found the search criteria to use from RFC 3501. This should get you started.
Rather than try to parse our HTML why not just use the IMAP interface? Hook it up to a standard mail client and then just sort by date and mark whichever ones you want as read.
Just go to the Gmail web interface, do an advanced search by date, then select all and mark as read.