X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=vim%2Fnotmuch.vim;h=331e9300842b1ef62f0cc62baacdaf64da7ffe46;hb=8363c9053152d349022b821a4a343f0ee2ade318;hp=fc9eaa24ecc8526a95bed6bc9a072c95e83b5477;hpb=2c3623703f4bd1dbe1d5ca47c4bf55e208db12b2;p=notmuch diff --git a/vim/notmuch.vim b/vim/notmuch.vim index fc9eaa24..331e9300 100644 --- a/vim/notmuch.vim +++ b/vim/notmuch.vim @@ -65,10 +65,9 @@ function! s:new_file_buffer(type, fname) execute printf('set filetype=notmuch-%s', a:type) execute printf('set syntax=notmuch-%s', a:type) ruby $curbuf.init(VIM::evaluate('a:type')) - ruby $buf_queue.push($curbuf.number) endfunction -function! s:compose_unload() +function! s:on_compose_delete() if b:compose_done return endif @@ -87,17 +86,22 @@ endfunction function! s:compose_send() let b:compose_done = 1 let fname = expand('%') + let lines = getline(5, '$') - " remove headers - 0,4d - write +ruby << EOF + # Generate proper mail to send + text = VIM::evaluate('lines').join("\n") + fname = VIM::evaluate('fname') + transport = Mail.new(text) + transport.message_id = generate_message_id + transport.charset = 'utf-8' + File.write(fname, transport.to_s) +EOF let cmdtxt = g:notmuch_sendmail . ' -t -f ' . s:reply_from . ' < ' . fname let out = system(cmdtxt) let err = v:shell_error if err - undo - write echohl Error echo 'Eeek! unable to send mail' echo out @@ -127,7 +131,7 @@ function! s:show_reply() ruby open_reply get_message.mail let b:compose_done = 0 call s:set_map(g:notmuch_compose_maps) - autocmd BufUnload call s:compose_unload() + autocmd BufDelete call s:on_compose_delete() startinsert! endfunction @@ -135,7 +139,7 @@ function! s:compose() ruby open_compose let b:compose_done = 0 call s:set_map(g:notmuch_compose_maps) - autocmd BufUnload call s:compose_unload() + autocmd BufDelete call s:on_compose_delete() startinsert! endfunction @@ -268,13 +272,8 @@ endfunction function! s:kill_this_buffer() ruby << EOF - if $buf_queue.size > 1 - $curbuf.close - VIM::command("bdelete!") - $buf_queue.pop - b = $buf_queue.last - VIM::command("buffer #{b}") if b - end + $curbuf.close + VIM::command("bdelete!") EOF endfunction @@ -293,7 +292,6 @@ function! s:new_buffer(type) execute printf('set filetype=notmuch-%s', a:type) execute printf('set syntax=notmuch-%s', a:type) ruby $curbuf.init(VIM::evaluate('a:type')) - ruby $buf_queue.push($curbuf.number) endfunction function! s:set_menu_buffer() @@ -471,7 +469,6 @@ ruby << EOF $db_name = nil $email = $email_name = $email_address = nil $searches = [] - $buf_queue = [] $threads = [] $messages = [] $config = {} @@ -580,9 +577,7 @@ ruby << EOF end m.cc = orig[:cc] m.from = $email - m.message_id = generate_message_id m.charset = 'utf-8' - m.content_transfer_encoding = '7bit' end lines = [] @@ -608,7 +603,7 @@ ruby << EOF reply.body = body_lines.join("\n") - lines += reply.to_s.lines.map { |e| e.chomp } + lines += reply.present.lines.map { |e| e.chomp } lines << "" cur = lines.count - 1 @@ -619,18 +614,13 @@ ruby << EOF def open_compose() lines = [] - lines << "Date: #{Time.now().strftime('%a, %-d %b %Y %T %z')}" lines << "From: #{$email}" lines << "To: " cur = lines.count lines << "Cc: " lines << "Bcc: " - lines << "Message-Id: #{generate_message_id}" lines << "Subject: " - lines << "Mime-Version: 1.0" - lines << "Content-Type: text/plain; charset=utf-8" - lines << "Content-Transfer-Encoding: 7bit" lines << "" lines << "" lines << "" @@ -641,7 +631,7 @@ ruby << EOF def folders_render() $curbuf.render do |b| folders = VIM::evaluate('g:notmuch_folders') - count_threads = VIM::evaluate('g:notmuch_folders_count_threads') + count_threads = VIM::evaluate('g:notmuch_folders_count_threads') == 1 $searches.clear folders.each do |name, search| q = $curbuf.query(search) @@ -927,7 +917,8 @@ ruby << EOF if mime_type != "text/html" text = decoded else - IO.popen("elinks --dump", "w+") do |pipe| + IO.popen(VIM::evaluate('exists("g:notmuch_html_converter") ? ' + + 'g:notmuch_html_converter : "elinks --dump"'), "w+") do |pipe| pipe.write(decode_body) pipe.close_write text = pipe.read @@ -935,6 +926,16 @@ ruby << EOF end text end + + def present + buffer = '' + header.fields.each do |f| + buffer << "%s: %s\r\n" % [f.name, f.to_s] + end + buffer << "\r\n" + buffer << body.to_s + buffer + end end end