Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 07292429E32 for ; Fri, 16 Sep 2011 19:28:20 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vMLxywY6VlFi for ; Fri, 16 Sep 2011 19:28:18 -0700 (PDT) Received: from mail-gy0-f181.google.com (mail-gy0-f181.google.com [209.85.160.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 57029429E30 for ; Fri, 16 Sep 2011 19:28:17 -0700 (PDT) Received: by gyd10 with SMTP id 10so4341553gyd.26 for ; Fri, 16 Sep 2011 19:28:16 -0700 (PDT) Received: by 10.100.165.5 with SMTP id n5mr74664ane.45.1316226496554; Fri, 16 Sep 2011 19:28:16 -0700 (PDT) Received: from localhost.localdomain (r74-193-78-30.pfvlcmta01.grtntx.tl.dh.suddenlink.net [74.193.78.30]) by mx.google.com with ESMTPS id u13sm27862929anf.14.2011.09.16.19.28.15 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 16 Sep 2011 19:28:15 -0700 (PDT) From: Ryan Harper To: notmuch@notmuchmail.org Subject: [PATCH 2/2] vim plugin: Implement attachment saving Date: Fri, 16 Sep 2011 21:27:50 -0500 Message-Id: <1316226470-30001-3-git-send-email-rharper@shake.ath.cx> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1316226470-30001-1-git-send-email-rharper@shake.ath.cx> References: <1316226470-30001-1-git-send-email-rharper@shake.ath.cx> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Sep 2011 02:28:20 -0000 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 --- 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 NM_show_delete_message()', \ 'N': ':call NM_show_mark_read_then_next_open_message()', \ 'v': ':call NM_show_view_all_mime_parts()', + \ 'S': ':call NM_show_save_mime_parts()', \ '+': ':call NM_show_add_tag()', \ '-': ':call NM_show_remove_tag()', \ '': ':call NM_show_advance_marking_read_and_archiving()', @@ -607,6 +608,55 @@ function! s:NM_show_view_all_mime_parts() call 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= AND >$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, 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