Skip to content

Instantly share code, notes, and snippets.

@kshep
Created August 2, 2011 02:02
Show Gist options
  • Save kshep/1119441 to your computer and use it in GitHub Desktop.
Save kshep/1119441 to your computer and use it in GitHub Desktop.
Ruby script to pull all "From:" addresses from every message in your "All Mail" Gmail folder
#!/usr/bin/env ruby
require 'net/imap'
imap = Net::IMAP.new('imap.gmail.com',993,true)
imap.login('USERNAME', 'PASSWORD')
imap.select('[Gmail]/All Mail')
imap.search(['ALL']).each do |message_id|
msg = imap.fetch(message_id,'ENVELOPE')[0].attr['ENVELOPE']
from = msg.from[0]
if from.name
puts "'#{from.name}' <#{from.mailbox}@#{from.host}>"
else
puts "#{from.mailbox}@#{from.host}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment