Created
November 27, 2012 11:39
-
-
Save jaspertandy/4153828 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick and very dirty script to extract some information from my GMail so I didn't have to manually search.