Created
November 5, 2012 07:43
-
-
Save Altech/4015832 to your computer and use it in GitHub Desktop.
grep like search to gmail.
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
#!/Users/Altech/.rvm/rubies/ruby-1.9.3-p194/bin/ruby | |
# -*- coding: utf-8 -*- | |
require 'gmail' | |
require 'nokogiri' | |
require 'colorize' | |
require 'pry' | |
gmail = Gmail.connect('takeno.sh',PASSWORD) | |
emails = gmail.mailbox('MailMagazine').emails | |
keyword = 'grep' | |
N = 20 | |
emails.each do |email| | |
msg = email.message.body.to_s.encode('utf-8','iso-2022-jp') | |
i = msg.index(keyword) | |
next if i.nil? | |
quotation = msg[i-N..i-1]+msg[i,keyword.size].red+msg[i+keyword.size,N] | |
subject = email.header.fields.detect{|i| i.name == "Subject"}.to_s | |
puts subject.blue + "\t" + "...#{quotation}..." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I ran this program April 4th, 2018 and get this error:
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in 'require': cannot load such file -- gmail (LoadError) from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in 'require' from search_gmail.rb:4:in '<main>'
I can also post on SO, but I figured I should let you know. Not sure if my version of ruby is outdated or what, but might be good to update! I'm excited to be able to search my e-mail with something like
grep
Thanks!