I had a number of items in my GMail inbox that hadn’t been read. These were not likely to be read, but I wanted to keep them for posterity.
I pondered putting together some kind of an automated solution to mark all of these items as read, but didn’t give it much thought.
This morning, I happened upon a handy gem for GMail.
I installed the gem using the following command:
gem install ruby-gmail
The only problem I had seemed to be a common one. When attempting to run my first trial script, the require for the gmail gem failed. Based on sage advice from a message-board, I edited gmail/message.rb, commenting out require ‘mime/message’. This fixed the problem.
The script I built is as follows:
# Copyright ©2012 by James K. Lawless # See full MIT / X11 license at # http://www.mailsend-online.com/license2012.php # Mark all emails in my Gmail inbox as read. require 'gmail' if ARGV.length < 2 puts "Syntax:\tallread.rb gmail-id gmail-password" exit 1 end gmail=Gmail.new(ARGV,ARGV) count = 0 gmail.inbox.emails(:unread).each do |msg| msg.mark(:read) count = count + 1 puts count end
To run the script, enter the following command, supplying your GMail credentials:
allread.rb gmail-id gmail-password
After running the script, I closed and reopened my GMail tab to refresh the “unread” stats … which are now non-existent. 😉