2015-11-21 23:04:28 +04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'dotenv'
|
|
|
|
require 'gmail'
|
|
|
|
|
|
|
|
Dotenv.load
|
|
|
|
|
|
|
|
GMAIL_USERNAME = ENV['GMAIL_USERNAME']
|
|
|
|
GMAIL_PASSWORD = ENV['GMAIL_PASSWORD']
|
|
|
|
|
2015-11-23 14:35:21 +02:00
|
|
|
gmail = Gmail.connect(GMAIL_USERNAME, GMAIL_PASSWORD)
|
2015-11-21 23:04:28 +04:00
|
|
|
|
|
|
|
KEYWORDS_REGEX = /sorry|help|wrong/i
|
|
|
|
|
|
|
|
gmail.inbox.find(:unread, from: 'kumar.a@example.com').each do |email|
|
|
|
|
if email.body[KEYWORDS_REGEX]
|
|
|
|
# Restore DB and send a reply
|
|
|
|
email.label('Database fixes')
|
2015-11-24 15:17:00 +04:00
|
|
|
reply = create_reply(email.subject)
|
2015-11-21 23:04:28 +04:00
|
|
|
gmail.deliver(reply)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-24 15:17:00 +04:00
|
|
|
def create_reply(subject)
|
2015-11-21 23:04:28 +04:00
|
|
|
gmail.compose do
|
2015-11-24 15:17:00 +04:00
|
|
|
to "kumar.a@example.com"
|
2015-11-21 23:04:28 +04:00
|
|
|
subject "RE: #{subject}"
|
|
|
|
body "No problem. I've fixed it. \n\n Please be careful next time."
|
|
|
|
end
|
|
|
|
end
|