]> git.sven.stormbind.net Git - sven/vym.git/blob - scripts/vym-addmail.rb
0a97d99116942471a103929ab1daabddfbb68172
[sven/vym.git] / scripts / vym-addmail.rb
1 #!/usr/bin/ruby
2
3 load File.expand_path("../vym-ruby.rb", __FILE__)
4 require 'tempfile'
5 require 'mail'
6
7 mail_in = Tempfile.new("mail")
8 begin
9   mail_in.write(ARGF.read)
10   mail_in.rewind
11   out = Tempfile.new("temp")
12   begin
13     mail = Mail.read(mail_in.path)
14
15     out <<  "Subject: #{mail.subject}\n"
16     out <<  "From: #{mail.header[:From]}\n"
17     out <<  "To: #{mail.header[:To]}\n"
18     out <<  "Cc: #{mail.header[:Cc]}\n"
19     out <<  "Date: #{mail.date.to_s}\n"
20     out <<  "\n"
21     out <<  mail.decoded
22
23     out.rewind
24
25     vym_mgr = VymManager.new
26     vym = vym_mgr.find('production') 
27
28     vym.addBranch 
29     vym.selectLastBranch 
30     vym.setHeading(mail.subject)
31     vym.loadNote(out.path)
32   ensure
33     out.close
34     out.unlink
35   end
36
37 ensure
38   mail_in.close
39   mail_in.unlink
40 end