3 # This ruby script can be called from mutt to create a branch in vym
4 # with the mail currently visible in mutts pager.
5 # The mail itself will be added as note to a branch, which has the
6 # heading "YYYY-MM-DD Email: $SUBJECT"
8 # vym is notified using DBUS, which usually only is available on Linux
11 # Example entry for .muttrc:
12 # macro pager Y "|/home/uwe/vym/branches/develop/scripts/vym-addmail.rb\n" "Add note to production inst ance of vym"
14 # vym itself needs to be starting using the name option, using "vym -n production"
17 require File.expand_path("../vym-ruby", __FILE__)
22 ARGF.each_line do |line|
27 out = Tempfile.new("temp")
29 mail = Mail.read_from_string(Mail::Utilities.binary_unsafe_to_crlf(mail_in))
30 puts "Mail is multipart: #{mail.multipart?}"
35 out << "Subject: #{mail.subject}\n"
36 out << "From: #{mail.header[:From]}\n"
37 out << "To: #{mail.header[:To]}\n"
38 out << "Cc: #{mail.header[:Cc]}\n"
39 out << "Date: #{mail.date.to_s}\n"
43 if mail.multipart? then
44 puts "Warning: multipart mail detected. Only using first part."
45 text = mail.parts.first.decoded
47 #out << mail.body.raw_source.gsub("\n", "<br/>")
51 if text.include?("<html")
55 text.gsub!("\r\n\r\n", "</p><p>")
56 text.gsub!("\r\n", "")
61 out << "</body></html>"
68 vym_mgr = VymManager.new
70 vym = vym_mgr.find(name)
73 puts "Couldn't find instance named \"#{name}\", please start one:"
74 puts "vym -l -n #{name} -t test/default.vym"
76 puts "Currently running vym instances: #{vym_mgr.show_running}"
80 # Before doing anything, make sure there is a return value available
81 # Otherwise the script might block // FIXME
82 #version = vym.version
84 puts "Found #{vym.mapCount} maps"
86 #puts vym.show_methods
88 n = vym.currentMapID()
89 puts "ID of current map: #{n}"
92 puts "Map title: #{map.getMapTitle}"
93 puts "Map path: #{map.getDestPath}"
94 puts "Map name: #{map.getFileName}"
99 date = mail.date.to_s.gsub!(/T.*$/,"")
100 map.setHeadingPlainText("#{date} Email: #{mail.subject}")
101 map.loadNote(out.path)
102 map.colorBranch("#0000ff")