Created
March 29, 2010 10:21
-
-
Save gakshay/347709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gmail.rb | |
# script to fetch INBOX mails from an account | |
# | |
# PROBLEM: I need to find all the EMAIL-ID and Phone number from a Media Agency's Gmail Account (upto certain number) | |
# Solutions: | |
# 1. run the script on some high speed internet server if possible | |
# 2. Filter out relavant content from gmail.txt using shell (grep and vim) | |
# | |
# Created by Akshay Gupta on 2010-03-29. | |
# Total time taken : 2 hours to complete the task | |
USERNAME = "gakshay" | |
PASSWORD = "password" | |
FILENAME = "gmail.txt" | |
SEARCH = 'INBOX' | |
SEARCH_OPTIONS = ["NOT", "DELETED"] | |
START_MESSAGE_ID = 1 | |
LAST_MESSAGE_ID = 14555 | |
require 'net/imap' | |
f = File.open(FILENAME, "w") | |
imap = Net::IMAP.new('imap.gmail.com','993',true) | |
imap.login(USERNAME,PASSWORD) | |
imap.select(SEARCH) | |
imap.search(SEARCH_OPTIONS).each do |message_id| | |
message_id = message_id + START_MESSAGE_ID | |
if message_id <= LAST_MESSAGE_ID | |
temp = imap.fetch(message_id, "RFC822")[0].attr["RFC822"] | |
f.write(temp+"\n") | |
puts "Successfully here = " + message_id.to_s | |
else | |
break | |
end | |
end | |
imap.logout() | |
imap.disconnect() | |
f.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment