X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=vim%2Fnotmuch.vim;h=ad8b7c800cd5cca1b9b4c23fe226d57c4e414191;hp=25a16e9a4ec5b230d2879e3c5f27f69ee77a756d;hb=410b96080ceec15ced70e684115f604380c5b4f6;hpb=2fee62fd1fcaed5c9ec46daa4f24b33a2f310e83 diff --git a/vim/notmuch.vim b/vim/notmuch.vim index 25a16e9a..ad8b7c80 100644 --- a/vim/notmuch.vim +++ b/vim/notmuch.vim @@ -59,6 +59,7 @@ let s:notmuch_datetime_format_default = '%d.%m.%y %H:%M:%S' let s:notmuch_reader_default = 'mutt -f %s' let s:notmuch_sendmail_default = 'sendmail' let s:notmuch_folders_count_threads_default = 0 +let s:notmuch_compose_start_insert_default = 1 function! s:new_file_buffer(type, fname) exec printf('edit %s', a:fname) @@ -86,17 +87,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 +133,9 @@ function! s:show_reply() let b:compose_done = 0 call s:set_map(g:notmuch_compose_maps) autocmd BufDelete call s:on_compose_delete() - startinsert! + if g:notmuch_compose_start_insert + startinsert! + end endfunction function! s:compose() @@ -135,7 +143,9 @@ function! s:compose() let b:compose_done = 0 call s:set_map(g:notmuch_compose_maps) autocmd BufDelete call s:on_compose_delete() - startinsert! + if g:notmuch_compose_start_insert + startinsert! + end endfunction function! s:show_info() @@ -423,6 +433,10 @@ function! s:set_defaults() endif endif + if !exists('g:notmuch_compose_start_insert') + let g:notmuch_compose_start_insert = s:notmuch_compose_start_insert_default + endif + if !exists('g:notmuch_custom_search_maps') && exists('g:notmuch_rb_custom_search_maps') let g:notmuch_custom_search_maps = g:notmuch_rb_custom_search_maps endif @@ -463,32 +477,28 @@ ruby << EOF $db_name = nil $email = $email_name = $email_address = nil + $exclude_tags = [] $searches = [] $threads = [] $messages = [] - $config = {} $mail_installed = defined?(Mail) - def get_config - group = nil - config = ENV['NOTMUCH_CONFIG'] || '~/.notmuch-config' - File.open(File.expand_path(config)).each do |l| - l.chomp! - case l - when /^\[(.*)\]$/ - group = $1 - when '' - when /^(.*)=(.*)$/ - key = "%s.%s" % [group, $1] - value = $2 - $config[key] = value - end - end + def get_config_item(item) + result = '' + IO.popen(['notmuch', 'config', 'get', item]) { |out| + result = out.read + } + return result.rstrip + end - $db_name = $config['database.path'] - $email_name = $config['user.name'] - $email_address = $config['user.primary_email'] + def get_config + $db_name = get_config_item('database.path') + $email_name = get_config_item('user.name') + $email_address = get_config_item('user.primary_email') + $email_name = get_config_item('user.name') $email = "%s <%s>" % [$email_name, $email_address] + ignore_tags = get_config_item('search.exclude_tags') + $exclude_tags = ignore_tags.split("\n") end def vim_puts(s) @@ -572,9 +582,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 = [] @@ -600,7 +608,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 @@ -611,18 +619,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 << "" @@ -637,8 +640,11 @@ ruby << EOF $searches.clear folders.each do |name, search| q = $curbuf.query(search) + $exclude_tags.each { |t| + q.add_tag_exclude(t) + } $searches << search - count = count_threads ? q.search_threads.count : q.search_messages.count + count = count_threads ? q.count_threads : q.count_messages b << "%9d %-20s (%s)" % [count, name, search] end end @@ -648,6 +654,9 @@ ruby << EOF date_fmt = VIM::evaluate('g:notmuch_date_format') q = $curbuf.query(search) q.sort = Notmuch::SORT_NEWEST_FIRST + $exclude_tags.each { |t| + q.add_tag_exclude(t) + } $threads.clear t = q.search_threads @@ -919,7 +928,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 @@ -927,6 +937,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