Guest User

Untitled

a guest
May 4th, 2018
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. # gmail.rb
  2. # script to fetch INBOX mails from an account
  3. #
  4. # PROBLEM: I need to find all the EMAIL-ID and Phone number from a Media Agency's Gmail Account (upto certain number)
  5. # Solutions:
  6. # 1. run the script on some high speed internet server if possible
  7. # 2. Filter out relavant content from gmail.txt using shell (grep and vim)
  8. #
  9. # Created by Akshay Gupta on 2010-03-29.
  10. # Total time taken : 2 hours to complete the task
  11.  
  12. USERNAME = "gakshay"
  13. PASSWORD = "password"
  14. FILENAME = "gmail.txt"
  15. SEARCH = 'INBOX'
  16. SEARCH_OPTIONS = ["NOT", "DELETED"]
  17. START_MESSAGE_ID = 1
  18. LAST_MESSAGE_ID = 14555
  19.  
  20. require 'net/imap'
  21. f = File.open(FILENAME, "w")
  22. imap = Net::IMAP.new('imap.gmail.com','993',true)
  23. imap.login(USERNAME,PASSWORD)
  24. imap.select(SEARCH)
  25. imap.search(SEARCH_OPTIONS).each do |message_id|
  26. message_id = message_id + START_MESSAGE_ID
  27. if message_id <= LAST_MESSAGE_ID
  28. temp = imap.fetch(message_id, "RFC822")[0].attr["RFC822"]
  29. f.write(temp+"\n")
  30. puts "Successfully here = " + message_id.to_s
  31. else
  32. break
  33. end
  34. end
  35. imap.logout()
  36. imap.disconnect()
  37. f.close
Add Comment
Please, Sign In to add comment