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 992F4431FC0 for ; Fri, 10 Oct 2014 02:57:32 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, 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 V6bSIO5lbZ8n for ; Fri, 10 Oct 2014 02:57:27 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com [209.85.217.172]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 54ABA431FBC for ; Fri, 10 Oct 2014 02:57:27 -0700 (PDT) Received: by mail-lb0-f172.google.com with SMTP id b6so2770935lbj.31 for ; Fri, 10 Oct 2014 02:57:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:message-id:from:to:subject:in-reply-to:references:mime-version :content-type:content-disposition:content-transfer-encoding; bh=xsEj9F7mlTZYd099w6I26QdRxXI6GHupvt4ER3j4Hpg=; b=Xy/Qbbo+KilA0XtzBzpMUcpoQoBq1Se6N15J39MKbZtPNMW7KKak/IGo7asaPvEoK9 JegiDQxqFltsupWA74drkc0dL+NAFQSLUiNa0fBz6+EbxPwuoZKOszLQO7YbshKSDR2e kHvipIbQIU9Pm+ncD4HTW6iAH0GTv+5Rc1d2xvrJlC3Z2KoFZ9GINAJamn/0PPpN2sTT TYjIFUOA733cAIhp2kuv8b4FBD1C94ScZpQEep+P0IHtvgcGPIaQNnqx1fYzeBaF+2MH mz7GEZBfPVHAYsHO18kZOUmWlGj16AosyLOPLYW9QSIwHOQo7TxbOEmHxO28ybUjeOR8 Olng== X-Received: by 10.152.115.229 with SMTP id jr5mr3612680lab.7.1412935041371; Fri, 10 Oct 2014 02:57:21 -0700 (PDT) Received: from localhost ([91.0.201.230]) by mx.google.com with ESMTPSA id ju20sm1687807lab.14.2014.10.10.02.57.19 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 10 Oct 2014 02:57:20 -0700 (PDT) Date: Fri, 10 Oct 2014 11:57:17 +0200 Message-ID: <20141010115717.GI28601@TP_L520.localdomain> From: Franz Fellner To: notmuch@notmuchmail.org Subject: Re: [PATCH] VIM: Add better attachment support In-Reply-To: <1412236132-9624-1-git-send-email-imain@stemwinder.org> References: <1412236132-9624-1-git-send-email-imain@stemwinder.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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: Fri, 10 Oct 2014 09:57:32 -0000 It works as described. But IMHO it would be better to prompt the user to enter the location where he wants to save the attachment(s). This path could be taken if s:notmuch_attachment_tmpdir_default is set to empty. Or implement a different function for "save to". On Thu, 2 Oct 2014 00:48:52 -0700, Ian Main wrote: > This patch changes how the notmuch vim client supports attachments: > > - For each attachment an 'Attachment : ' is added > to the header > - You can then use 'e' to extract the attachment under the cursor > or use it elsewhere to extract all attachments (the prior behavior) > - You can use 'v' to 'view' the attachment using xdg-open by default. > > Ian > --- > vim/notmuch.txt | 8 +++++++- > vim/notmuch.vim | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- > 2 files changed, 65 insertions(+), 3 deletions(-) > > diff --git a/vim/notmuch.txt b/vim/notmuch.txt > index 4374102..838a904 100644 > --- a/vim/notmuch.txt > +++ b/vim/notmuch.txt > @@ -72,6 +72,9 @@ q Quit view > A Archive (-inbox -unread) > I Mark as read (-unread) > t Tag (prompted) > +e Extract attachment on the current 'Attachment' line or all > + attachments if the cursor is elsewhere. > +v View attachment on the current 'Attachment' line. > s Search > p Save patches > r Reply > @@ -148,6 +151,9 @@ You can also configure your externail mail reader and sendemail program: > > > let g:notmuch_reader = 'mutt -f %s' > let g:notmuch_sendmail = 'sendmail' > -< > + > +You can also configure what probram is used to view attachments: > + > + let g:notmuch_view_attachment = 'xdg-open' > > vim:tw=78:ts=8:noet:ft=help: > diff --git a/vim/notmuch.vim b/vim/notmuch.vim > index 331e930..a5830b5 100644 > --- a/vim/notmuch.vim > +++ b/vim/notmuch.vim > @@ -35,6 +35,7 @@ let g:notmuch_show_maps = { > \ 't': 'show_tag("")', > \ 'o': 'show_open_msg()', > \ 'e': 'show_extract_msg()', > + \ 'v': 'show_view_attachment()', > \ 's': 'show_save_msg()', > \ 'p': 'show_save_patches()', > \ 'r': 'show_reply()', > @@ -58,6 +59,8 @@ let s:notmuch_date_format_default = '%d.%m.%y' > 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_view_attachment_default = 'xdg-open' > +let s:notmuch_attachment_tmpdir_default = '~/.notmuch/tmp' > let s:notmuch_folders_count_threads_default = 0 > > function! s:new_file_buffer(type, fname) > @@ -147,13 +150,53 @@ function! s:show_info() > ruby vim_puts get_message.inspect > endfunction > > +function! s:show_view_attachment() > + let line = getline(".") > +ruby << EOF > + m = get_message > + line = VIM::evaluate('line') > + > + match = line.match(/^Attachment (\d*):/) > + if match and match.length == 2 > + a = m.mail.attachments[match[1].to_i - 1] > + tmpdir = VIM::evaluate('g:notmuch_attachment_tmpdir') > + tmpdir = File.expand_path(tmpdir) > + Dir.mkdir(tmpdir) unless Dir.exists?(tmpdir) > + filename = File.expand_path("#{tmpdir}/#{a.filename}") > + vim_puts "Viewing attachment #{filename}" > + File.open(filename, 'w') do |f| > + f.write a.body.decoded > + cmd = VIM::evaluate('g:notmuch_view_attachment') > + system(cmd, filename) > + end > + else > + vim_puts "No attachment on this line." > + end > +EOF > +endfunction > + > function! s:show_extract_msg() > + let line = getline(".") > ruby << EOF > m = get_message > - m.mail.attachments.each do |a| > + line = VIM::evaluate('line') > + > + # If the user is on a line that has an 'Attachment' > + # line, we just extract the one attachment. > + match = line.match(/^Attachment (\d*):/) > + if match and match.length == 2 > + a = m.mail.attachments[match[1].to_i - 1] > File.open(a.filename, 'w') do |f| > f.write a.body.decoded > - print "Extracted '#{a.filename}'" > + vim_puts "Extracted #{a.filename}" > + end > + else > + # Extract them all.. > + m.mail.attachments.each do |a| > + File.open(a.filename, 'w') do |f| > + f.write a.body.decoded > + vim_puts "Extracted #{a.filename}" > + end > end > end > EOF > @@ -326,6 +369,11 @@ ruby << EOF > b << "To: %s" % msg['to'] > b << "Cc: %s" % msg['cc'] > b << "Date: %s" % msg['date'] > + cnt = 0 > + nm_m.mail.attachments.each do |a| > + cnt += 1 > + b << "Attachment %d: %s" % [cnt, a.filename] > + end > nm_m.body_start = b.count > b << "--- %s ---" % part.mime_type > part.convert.each_line do |l| > @@ -420,6 +468,14 @@ function! s:set_defaults() > endif > endif > > + if !exists('g:notmuch_attachment_tmpdir') > + let g:notmuch_attachment_tmpdir = s:notmuch_attachment_tmpdir_default > + endif > + > + if !exists('g:notmuch_view_attachment') > + let g:notmuch_view_attachment = s:notmuch_view_attachment_default > + endif > + > if !exists('g:notmuch_folders_count_threads') > if exists('g:notmuch_rb_count_threads') > let g:notmuch_count_threads = g:notmuch_rb_count_threads > -- > 1.9.3 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch