Skip to content

Instantly share code, notes, and snippets.

@julianeon
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julianeon/9374464 to your computer and use it in GitHub Desktop.
Save julianeon/9374464 to your computer and use it in GitHub Desktop.
To save the incident number from a gmail email, in partial pseudocode form.
require 'gmail'
require 'base64'
require 'nokogiri'
require 'date'
require 'redis'
redis=Redis.new
#credentials to login
login="change_this"
encrypted="change_this"
#credentials entered and inbox fetched
#username=Base64::decode64(login)
#password=Base64::decode64(encrypted)
username=login
password=encrypted
gmail=Gmail.new(username,password)
boa=gmail.inbox.emails(:from => "email_address_to_check@yourserver.com")
value="none"
boa.each do |email|
subject_line= email.subject
if subject_line.match(/substitute_your_regex/)
plain_part = email.multipart? ? (email.text_part ? email.text_part.body.decoded : nil) : email.body.decoded
#with Nokogiri, assuming first value is in strong tag - a demonstration case to be replaced
#you'll need to get the incident number too
doc=Nokogiri::HTML(plain_part)
value = doc.css("strong")[0].text
end
end
gmail.logout
message_line = "Value is " + value
local_filename="incident.txt"
File.open(local_filename, 'w') {|f| f.write(message_line) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment