From dbdf6a3486a3456b6a6d4fc4f2c5973113015109 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 8 Jun 2014 12:41:16 -0400 Subject: JSON API for individual messages --- app.rb | 5 +++++ fancy_bear/contextio/message.rb | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app.rb b/app.rb index d59eadc..9db11e2 100644 --- a/app.rb +++ b/app.rb @@ -42,4 +42,9 @@ class App < Sinatra::Base contextio = FancyBear::ContextIO::Message.new('sellevate.hack@gmail.com') json contextio.all end + + get '/messages/:id.json' do + contextio = FancyBear::ContextIO::Message.new('sellevate.hack@gmail.com') + json contextio.get(params[:id]) + end end diff --git a/fancy_bear/contextio/message.rb b/fancy_bear/contextio/message.rb index bae9be4..abf4a09 100644 --- a/fancy_bear/contextio/message.rb +++ b/fancy_bear/contextio/message.rb @@ -25,8 +25,23 @@ module FancyBear messages end - def get + def get(id) + output = {} + message = @account.messages.where(:message_id => id).first + output['from_address'] = message.from['email'] + output['from_name'] = message.from['name'] + output['subject'] = message.subject + output['timestamp'] = message.date + output['labels'] = message.folders + + message.body_parts.each do |p| + if p.content + output['html'] = p.html? + output['content'] = p.content + end + end + output end end -- cgit v1.2.3