Last active
August 29, 2015 13:57
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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