Skip to content

Instantly share code, notes, and snippets.

@rjp
Created February 22, 2011 23:44
Show Gist options
  • Save rjp/839674 to your computer and use it in GitHub Desktop.
Save rjp/839674 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'json'
require 'open-uri'
$base = ENV['UA_BASE'] || 'http://localhost:3000'
$user = ENV['UA_USER'] || 'user'
$pass = ENV['UA_PASS'] || 'pass'
# {"folder":"test2","to":"rjp","id":2035015,"body":"FLANGES","inReplyTo":2034051,"subject":"Ainsley","epoch":1298383425,"read":false,"annotations":[{"body":"*mutter*","epoch":1298384919,"from":"rjp"}],"from":"rjp","inReplyToHierarchy":[{"folder":"test1","id":2034051,"from":"rjp"}],"replyToBy":[{"folder":"test1","id":2035371,"from":"rjp"}]}
def get_message(id)
json = open("#{$base}/message/#{id}",
:http_basic_authentication=>[$user, $pass]).read
return JSON.load(json)
end
def show_message(id)
h = get_message(id)
bd = h['body']
t = Time.at(h['epoch'].to_i).strftime('%H:%M:%S, %a %d/%m')
puts "Message: #{h['folder']}/#{h['id']} at #{t}"
print "From: #{h['from']}"
if h['to'] then
print " to #{h['to']}"
end
puts
puts "Subject: #{h['subject']}"
if h['inReplyToHierarchy'].to_a.size > 0 then
parents = h['inReplyToHierarchy'].map { |i|
i['id'].to_s + ((not i['folder'].nil? and i['folder'] != h['folder']) ? " (in #{i['folder']})" : "")
}
list = parents[0..2].join(', ')
if parents.size > 3 then
list = list + "... (#{parents.size-3} more)"
end
puts "In-Reply-To: #{list}"
end
puts
puts bd
anno = h['annotations']
anno.to_a.sort_by{|i| i['epoch']}.each do |an|
t = Time.at(an['epoch'].to_i).strftime('%H:%M:%S, %a %d/%m')
puts "--"
puts "Annotated-By: #{an['from']} (#{t})"
puts an['body']
end
if h['replyToBy'].to_a.size > 0 then
puts "--"
h['replyToBy'].each do |rep|
if (not rep['folder'].nil? and rep['folder'] != h['folder']) then f=" in #{rep['folder']}"; end
puts "Replied-to-by: #{rep['from']} (#{rep['id']}#{f})"
end
end
end
ARGV.each do |m|
show_message(m)
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment