#!/usr/bin/env macruby
#create a bug ticket from the current email
#tweaked CGI::escape
def escape(string)
  string.gsub(/([^ a-zA-Z0-9_.-]+)/) do
    $1.nil? ? nil : ('%' + $1.unpack('H2' * $1.bytesize).
      compact.join('%').upcase)
  end.tr(' ','+')
end

framework 'ScriptingBridge'
mail = SBApplication.applicationWithBundleIdentifier(
  'com.apple.mail')
mail.selection.each do |msg|
  params=[[:summary,msg.subject.chomp],
    [:description,msg.content.get.chomp]]
  url= "https://trac.company.com/newticket?"+
    (params.collect{ |n,v| "#{n}=#{escape(v)}"}.join('&'))
  NSWorkspace.new.openURL(NSURL.URLWithString(url))
end
#thanks to @lrz for help here

#!/usr/bin/env macruby
#create a bug ticket from the current email
#tweaked CGI::escape
def escape(string)
  string.gsub(/([^ a-zA-Z0-9_.-]+)/) do
    $1.nil? ? nil : ('%' + $1.unpack('H2' * $1.bytesize).
      compact.join('%').upcase)
  end.tr(' ','+')
end

framework 'ScriptingBridge'
mail = SBApplication.applicationWithBundleIdentifier(
  'com.apple.mail')
mail.selection.each do |msg|
  params=[[:summary,msg.subject.chomp],
    [:description,msg.content.get.chomp]]
  url= "https://trac.company.com/newticket?"+
    (params.collect{ |n,v| "#{n}=#{escape(v)}"}.join('&'))
  NSWorkspace.new.openURL(NSURL.URLWithString(url))
end
#thanks to @lrz for help here