Skip to content

Instantly share code, notes, and snippets.

@island205
Last active December 18, 2015 12:09
Show Gist options
  • Save island205/5780781 to your computer and use it in GitHub Desktop.
Save island205/5780781 to your computer and use it in GitHub Desktop.
require 'mail'
require 'gmail'
require 'base64'
gmail = Gmail.connect('[email protected]', 'password')
emailComeFromSomeone = gmail.inbox.find(:before => Date.parse("2012-10-01"), :after => Date.parse("2012-09-01"), :from => '[email protected]')
emailComeFromSomeone.each do |mail|
begin
puts "## #{Mail::Encodings.value_decode(mail.subject)}"
puts "\n"
puts "*#{Date.parse(mail.date).strftime('%Y-%m-%d')}*"
puts "\n"
body = mail.body.decoded.split(/--[0-9a-z]{28}/)[1...-1][0]
lines = body.split("\n")
lines = lines[4...-1]
lines = "=?GB2312?B?#{lines.join('')}?="
puts "\n"
puts Mail::Encodings.value_decode(lines)
puts "\n"
puts "\n"
rescue => err
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment