Skip to content

Instantly share code, notes, and snippets.

@jaspertandy
Created November 27, 2012 11:39
Show Gist options
  • Select an option

  • Save jaspertandy/4153828 to your computer and use it in GitHub Desktop.

Select an option

Save jaspertandy/4153828 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "net/imap"
imap = Net::IMAP.new('imap.googlemail.com', port: 993, ssl: true)
imap.login('EMAIL', 'PASSWORD')
imap.examine('Sites')
results = imap.search(["SINCE" , "1-Jul-2012", "BODY" , "Discounts", "SUBJECT" , "buffalosite:trendygolf:email"])
puts "results: #{results.length}"
results.each do |message_id|
body = imap.fetch(message_id,'BODY[TEXT]')[0].attr['BODY[TEXT]'].to_s.gsub(/=\r\n/ , '')
id = body.match(/tgn[0-9]+/i).to_s
discounts_loc = body.index( '">Discounts' )
tr_loc = body.index( '</tr>' , discounts_loc )
disc = body[discounts_loc...tr_loc].match(/&([^;]+);([0-9\.]+)/).to_a[1..2].join(',')
puts "#{id},#{disc}"
end
imap.disconnect
@jaspertandy

Copy link
Copy Markdown
Author

Quick and very dirty script to extract some information from my GMail so I didn't have to manually search.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment