unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Ryan Harper <rharper@shake.ath.cx>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/2] vim plugin: Implement attachment saving
Date: Fri, 16 Sep 2011 21:27:50 -0500	[thread overview]
Message-ID: <1316226470-30001-3-git-send-email-rharper@shake.ath.cx> (raw)
In-Reply-To: <1316226470-30001-1-git-send-email-rharper@shake.ath.cx>

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@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

  parent reply	other threads:[~2011-09-17  2:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-17  2:27 [PATCH 0/2] vim plugin: implement viewing/saving attachments Ryan Harper
2011-09-17  2:27 ` [PATCH 1/2] vim plugin: Implement show_view_all_mime_parts Ryan Harper
2011-09-17  2:27 ` Ryan Harper [this message]
2012-03-03  3:12   ` [PATCH 2/2] vim plugin: Implement attachment saving Charlie Allom
2011-09-19  0:18 ` [PATCH 0/2] vim plugin: implement viewing/saving attachments Blake Sweeney
2011-09-19 18:15   ` Ryan Harper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1316226470-30001-3-git-send-email-rharper@shake.ath.cx \
    --to=rharper@shake.ath.cx \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).