require 'gmail'
APPLICATION = '/Applications/Google\ Chrome.app'
ACCOUNT = 'your_gmail_account@gmail.com'
PASSWORD = 'password'
MAIL_FROM = 'your_mobile_phone@exmple.com'
gmail = Gmail.connect ACCOUNT, PASSWORD
gmail.inbox.emails(:unread, from: MAIL_FROM).map do |mail|
text = mail.body
uri = /http:\/\/t\.co\/\w+/.match text.to_s
mail.delete! if system "open -a #{APPLICATION} #{uri}"
sleep 5
end
gmail.logout