views:

1148

answers:

3

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?

+1  A: 

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.

Marplesoft
because it's not as fun? To be clear, I'm aiming to use the Imap interface, but I'm trying to learn a new trick on the way. I don't want to install a mail client on my computer, when technically this should be possible without one.
Eric
Ah ok, I didn't realize that fun was a top priority in this project ;)
Marplesoft
+1  A: 

Just go to the Gmail web interface, do an advanced search by date, then select all and mark as read.

Ben Alpert
Doesn't work. 1000s of messages, and Gmail only lets me select 20 at a time...
Eric
For me, it'll pop up a little message that says "All 20 conversations on this page are selected. Select all conversations that match this search" and you can select all of your messages.
Ben Alpert
+4  A: 
typ, data = M.search(None, 'BEFORE 01/01/2009')
for num in data[0].split():
   M.store(num, '+FLAGS', '\\Seen')

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. I haven't actually run the code so there may be some issues, most likely with the date format. This should get you started.

Philip T.
Thanks! This is exactly what I was looking for!
Eric