lib/vmail.vim in vmail-0.0.5 vs lib/vmail.vim in vmail-0.0.6
- old
+ new
@@ -1,7 +1,8 @@
let s:mailbox = $VMAIL_MAILBOX
let s:query = $VMAIL_QUERY
+let s:append_file = ''
let s:drb_uri = $DRB_URI
let s:client_script = "vmail_client " . s:drb_uri . " "
let s:set_window_width_command = s:client_script . "window_width= "
@@ -11,10 +12,11 @@
let s:fetch_headers_command = s:client_script . "fetch_headers "
let s:select_mailbox_command = s:client_script . "select_mailbox "
let s:search_command = s:client_script . "search "
let s:more_messages_command = s:client_script . "more_messages "
let s:flag_command = s:client_script . "flag "
+let s:append_to_file_command = s:client_script . "append_to_file "
let s:move_to_command = s:client_script . "move_to "
let s:new_message_template_command = s:client_script . "new_message_template "
let s:reply_template_command = s:client_script . "reply_template "
let s:forward_template_command = s:client_script . "forward_template "
let s:deliver_command = s:client_script . "deliver "
@@ -178,10 +180,11 @@
if match(res, '^\d\+') != -1
setlocal modifiable
let line = line('$')
$put =res
setlocal nomodifiable
+ write
let num = len(split(res, '\n', ''))
redraw
call cursor(line + 1, 0)
normal z.
redraw
@@ -219,10 +222,11 @@
let res = system(command)
setlocal modifiable
exec a:firstline . "," . a:lastline . "delete"
exec (a:firstline - 1). "put =res"
setlocal nomodifiable
+ write
" if more than 2 lines change, vim forces us to look at a message.
" dismiss it.
if len(split(res, "\n")) > 2
call feedkeys("\<cr>")
endif
@@ -244,18 +248,40 @@
echo command
let res = system(command)
setlocal modifiable
exec a:firstline . "," . a:lastline . "delete"
setlocal nomodifiable
+ write
" if more than 2 lines change, vim forces us to look at a message.
" dismiss it.
if len(uids) > 2
call feedkeys("\<cr>")
endif
endfunc
" --------------------------------------------------------------------------------
+" append text bodies of a set of messages to a file
+func! s:append_messages_to_file() range
+ let lnum = a:firstline
+ let n = 0
+ let uids = []
+ while lnum <= a:lastline
+ let line = getline(lnum)
+ let message_uid = matchstr(line, '^\d\+')
+ call add(uids, message_uid)
+ let lnum = lnum + 1
+ endwhile
+ let uid_set = join(uids, ",")
+ let s:append_file = input("print messages to file: ", s:append_file)
+ let command = s:append_to_file_command . s:append_file . ' ' . uid_set
+ echo "appending " . len(uids) . " message" . (len(uids) == 1 ? '' : 's') . " to " s:append_file
+ let res = system(command)
+ echo res
+ redraw
+endfunc
+
+" --------------------------------------------------------------------------------
" move to another mailbox
function! s:move_to_mailbox() range
let lnum = a:firstline
let n = 0
let uids = []
@@ -463,21 +489,19 @@
normal }
normal o
endfunction
function! s:compose_message()
- write
let command = s:new_message_template_command
call s:open_compose_window(command)
" position cursor after to:
call search("^to:")
normal $
call feedkeys("a")
endfunction
function! s:compose_forward()
- write
let command = s:forward_template_command . s:current_uid
call s:open_compose_window(command)
call search("^to:")
normal $
call feedkeys("a")
@@ -485,14 +509,16 @@
func! s:open_compose_window(command)
redraw
echo a:command
let res = system(a:command)
- split ComposeMessage
- wincmd p
- close
+ split compose-message
+ setlocal buftype=nofile
+ setlocal noswapfile
setlocal modifiable
+ wincmd p
+ close!
1,$delete
put! =res
normal 1G
call s:compose_window_mappings()
set completefunc=CompleteContact
@@ -524,27 +550,26 @@
wincmd p
close!
endfunction
function! s:send_message()
- write
let mail = join(getline(1,'$'), "\n")
- exec ":!" . s:deliver_command . " < ComposeMessage"
+ echo "sending message"
+ call system(s:deliver_command, mail)
redraw
- call s:focus_list_window()
- wincmd p
- close!
+ echo "sent! press q to go back to message list"
endfunction
func! s:save_draft()
- write
let mail = join(getline(1,'$'), "\n")
- exec ":!" . s:save_draft_command . " < ComposeMessage"
+ echo "saving draft"
+ call system(s:save_draft_command, mail)
redraw
call s:focus_list_window()
wincmd p
close!
+ echo "draft saved"
endfunc
" --------------------------------------------------------------------------------
" call from inside message window with <Leader>h
@@ -614,9 +639,10 @@
" command -buffer -range VmailDelete call s:toggle_star("Deleted")
" command -buffer -range VmailStar call s:toggle_star("Flagged")
noremap <silent> <buffer> <leader>! :call <SID>delete_messages("[Gmail]/Spam")<CR>
"open a link browser (os x)
"autocmd CursorMoved <buffer> call <SID>show_message()
+ noremap <silent> <buffer> <leader>vp :call <SID>append_messages_to_file()<CR>
noremap <silent> <buffer> u :call <SID>update()<CR>
noremap <silent> <buffer> <Leader>s :call <SID>search_query()<CR>
noremap <silent> <buffer> <Leader>m :call <SID>mailbox_window()<CR>
noremap <silent> <buffer> <Leader>v :call <SID>move_to_mailbox()<CR>
noremap <silent> <buffer> <Leader>c :call <SID>compose_message()<CR>