diff --git a/kumar_asshole.rb b/kumar_asshole.rb index ca5b9f6..fc6a2f0 100755 --- a/kumar_asshole.rb +++ b/kumar_asshole.rb @@ -14,8 +14,16 @@ kumars_email = 'kumar.a@example.com' DB_NAME_REGEX = /\S+_staging/ KEYWORDS_REGEX = /sorry|help|wrong/i +def create_reply(subject) + gmail.compose do + to kumars_email + subject "RE: #{subject}" + body "No problem. I've fixed it. \n\n Please be careful next time." + end +end + gmail.inbox.find(:unread, from: kumars_email).each do |email| - if email.body[KEYWORDS_REGEX] && (db_name = email.body[DB_NAME_REGEX]) + if email.body.raw_source[KEYWORDS_REGEX] && (db_name = email.body.raw_source[DB_NAME_REGEX]) backup_file = "/home/backups/databases/#{db_name}-" + (Date.today - 1).strftime('%Y%m%d') + '.gz' abort 'ERROR: Backup file not found' unless File.exist?(backup_file) @@ -29,11 +37,3 @@ gmail.inbox.find(:unread, from: kumars_email).each do |email| gmail.deliver(reply) end end - -def create_reply(subject) - gmail.compose do - to kumars_email - subject "RE: #{subject}" - body "No problem. I've fixed it. \n\n Please be careful next time." - end -end