X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=scripts%2Fvym-addmail.rb;h=7931f41b2e6b228dd1f285d3438ba004bac79bd3;hb=d483bd8e6523c23c6f1d8908a2e0611c2bc9ff4f;hp=0a97d99116942471a103929ab1daabddfbb68172;hpb=7dfa3fe589d1722d49681f42cdb0bf1e6efb5223;p=sven%2Fvym.git diff --git a/scripts/vym-addmail.rb b/scripts/vym-addmail.rb index 0a97d99..7931f41 100755 --- a/scripts/vym-addmail.rb +++ b/scripts/vym-addmail.rb @@ -1,40 +1,108 @@ #!/usr/bin/ruby -load File.expand_path("../vym-ruby.rb", __FILE__) +# This ruby script can be called from mutt to create a branch in vym +# with the mail currently visible in mutts pager. +# The mail itself will be added as note to a branch, which has the +# heading "YYYY-MM-DD Email: $SUBJECT" +# +# vym is notified using DBUS, which usually only is available on Linux +# systems +# +# Example entry for .muttrc: +# macro pager Y "|/home/uwe/vym/branches/develop/scripts/vym-addmail.rb\n" "Add note to production inst ance of vym" +# +# vym itself needs to be starting using the name option, using "vym -n production" +# + +require File.expand_path("../vym-ruby", __FILE__) require 'tempfile' require 'mail' -mail_in = Tempfile.new("mail") +mail_in = "" +ARGF.each_line do |line| + mail_in << line +end + begin - mail_in.write(ARGF.read) - mail_in.rewind out = Tempfile.new("temp") begin - mail = Mail.read(mail_in.path) + mail = Mail.read_from_string(Mail::Utilities.binary_unsafe_to_crlf(mail_in)) + puts "Mail is multipart: #{mail.multipart?}" + + # Write header + out << "" + out << "
"
+    out << "Subject: #{mail.subject}\n"
+    out << "From: #{mail.header[:From]}\n"
+    out << "To: #{mail.header[:To]}\n"
+    out << "Cc: #{mail.header[:Cc]}\n"
+    out << "Date: #{mail.date.to_s}\n"
+    out << "
" - out << "Subject: #{mail.subject}\n" - out << "From: #{mail.header[:From]}\n" - out << "To: #{mail.header[:To]}\n" - out << "Cc: #{mail.header[:Cc]}\n" - out << "Date: #{mail.date.to_s}\n" - out << "\n" - out << mail.decoded + text = "" + if mail.multipart? then + puts "Warning: multipart mail detected. Only using first part." + text = mail.parts.first.decoded + else + #out << mail.body.raw_source.gsub("\n", "
") + text = mail.decoded + end + + if text.include?("" + text.gsub!("\r\n\r\n", "

") + text.gsub!("\r\n", "") + out << text + out << "

" + end + + out << "" out.rewind + name = "production" + #name = "test" + vym_mgr = VymManager.new - vym = vym_mgr.find('production') + vym_mgr.show_running + vym = vym_mgr.find(name) + + if !vym + puts "Couldn't find instance named \"#{name}\", please start one:" + puts "vym -l -n #{name} -t test/default.vym" + + puts "Currently running vym instances: #{vym_mgr.show_running}" + exit + end + + # Before doing anything, make sure there is a return value available + # Otherwise the script might block // FIXME + #version = vym.version + + puts "Found #{vym.mapCount} maps" + + #puts vym.show_methods + + n = vym.currentMapID() + puts "ID of current map: #{n}" + + map = vym.map (n) + puts "Map title: #{map.getMapTitle}" + puts "Map path: #{map.getDestPath}" + puts "Map name: #{map.getFileName}" + + map.addBranch() + map.selectLatestAdded - vym.addBranch - vym.selectLastBranch - vym.setHeading(mail.subject) - vym.loadNote(out.path) + date = mail.date.to_s.gsub!(/T.*$/,"") + map.setHeadingPlainText("#{date} Email: #{mail.subject}") + map.loadNote(out.path) + map.colorBranch("#0000ff") ensure out.close out.unlink end -ensure - mail_in.close - mail_in.unlink end