Skip to content

Instantly share code, notes, and snippets.

@oskarizu
Created October 29, 2013 11:31
Show Gist options
  • Save oskarizu/7213025 to your computer and use it in GitHub Desktop.
Save oskarizu/7213025 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# based on the clear_hipchat.rb from https://gist.github.com/jhbabon/5894578
# usage = GMAIL_USER='user@company' GMAIL_PASS='secret' ./sweep_the_inbox.rb
require 'net/imap'
username = ENV['GMAIL_USER']
password = ENV['GMAIL_PASS']
connection = Net::IMAP.new('imap.gmail.com', 993, true)
connection.login(username, password)
$stdout.puts " ==> Deleting all mails in the INBOX folder"
connection.select('INBOX')
connection.search(['ALL']).each do |id|
connection.store(id, '+FLAGS', [:Deleted])
end
connection.expunge
$stdout.puts " ==> Deleting all mails in the Starred folder"
connection.select('[GMail]/Starred')
connection.search(['ALL']).each do |id|
connection.store(id, '+FLAGS', [:Deleted])
end
connection.expunge
$stdout.puts " ==> Deleting all mails in the Drafts folder"
connection.select('[Gmail]/Drafts')
connection.search(['ALL']).each do |id|
connection.store(id, '+FLAGS', [:Deleted])
end
connection.expunge
$stdout.puts " ==> Deleting all mails in the Sent-Mail folder"
connection.select('[Gmail]/Sent Mail')
connection.search(['ALL']).each do |id|
connection.store(id, '+FLAGS', [:Deleted])
end
connection.expunge
$stdout.puts " ==> Deleting all mails in the Spam folder"
connection.select('[Gmail]/Spam')
connection.search(['ALL']).each do |id|
connection.store(id, '+FLAGS', [:Deleted])
end
connection.expunge
$stdout.puts " ==> Deleting all mails in the Trash folder"
connection.select('[Gmail]/Trash')
connection.search(['ALL']).each do |id|
connection.store(id, '+FLAGS', [:Deleted])
end
connection.expunge
$stdout.puts " ==> Cleaning the CHAT history "
connection.select('[Gmail]/Chats')
connection.search(['ALL']).each do |id|
connection.store(id, '+FLAGS', [:Deleted])
end
connection.expunge
connection.logout()
connection.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment