Using the dictionary of attachments in a message we can implement saving the attachment. Select the current attachment under the cursor request a new name, but default to the extracted name.
Currently saves to the current working directory. Signed-off-by: Ryan Harper <rharper at shake.ath.cx> --- vim/plugin/notmuch.vim | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 50 insertions(+), 0 deletions(-) diff --git a/vim/plugin/notmuch.vim b/vim/plugin/notmuch.vim index cbc5b51..efa6fca 100644 --- a/vim/plugin/notmuch.vim +++ b/vim/plugin/notmuch.vim @@ -158,6 +158,7 @@ let g:notmuch_show_maps = { \ 'd': ':call <SID>NM_show_delete_message()<CR>', \ 'N': ':call <SID>NM_show_mark_read_then_next_open_message()<CR>', \ 'v': ':call <SID>NM_show_view_all_mime_parts()<CR>', + \ 'S': ':call <SID>NM_show_save_mime_parts()<CR>', \ '+': ':call <SID>NM_show_add_tag()<CR>', \ '-': ':call <SID>NM_show_remove_tag()<CR>', \ '<Space>': ':call <SID>NM_show_advance_marking_read_and_archiving()<CR>', @@ -607,6 +608,55 @@ function! s:NM_show_view_all_mime_parts() call <SID>NM_set_map('n', g:notmuch_show_maps) endfunction +function! s:NM_show_save_mime_part() + let attachments = b:attachments + let info = b:nm_raw_info + let words = b:nm_search_words + let lnum = line('.') + let curline = getline(lnum) + let curatt = {} + + " need to extract the id from the current line to + " use to find which attachment from the list we're + " attempting to save + let m = matchlist(curline, '\(\d\+\)') + if len(m) + let id = m[1] + for a in attachments + if a['id'] == id + let curatt = a + break + endif + endfor + endif + + + let fn = curatt['filename'] + let prompt = printf('Save: %s', fn) + let outfile = input(prompt) + if strlen(outfile) + echo outfile + else + let outfile = fn + endif + + "build save command: + " notmuch show --part=<part num> <msg_id> AND <search terms> >$filename < /dev/null + let cmd = ["show"] + call add(cmd, printf("--part=%s", curatt['id'])) + call add(cmd, curatt['mid']) + call add(cmd, 'AND') + call extend(cmd, <SID>NM_get_search_words()) + call add(cmd, printf('>%s', outfile)) + + "invoke notmuch via shell + let nmcmd = g:notmuch_cmd . ' ' . join(cmd) . '< /dev/null' + let out = system(nmcmd) + let err = v:shell_error + " TODO: error handling + +endfunction + function! s:NM_show_view_raw_message() echo 'not implemented' endfunction -- 1.7.6