1 Return-Path: <imain@stemwinder.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 20F0A431FBF
\r
6 for <notmuch@notmuchmail.org>; Thu, 2 Oct 2014 00:49:01 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id Tj7hTktUFtV6 for <notmuch@notmuchmail.org>;
\r
16 Thu, 2 Oct 2014 00:48:57 -0700 (PDT)
\r
17 Received: from cmta19.telus.net (cmta19.telus.net [209.171.16.92])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 908C5431FB6
\r
19 for <notmuch@notmuchmail.org>; Thu, 2 Oct 2014 00:48:57 -0700 (PDT)
\r
20 Received: from ovo.mains.priv ([207.102.88.62]) by cmta19.telus.net with TELUS
\r
21 id y7ov1o00C1LiWEf017ovXG; Thu, 02 Oct 2014 01:48:56 -0600
\r
22 X-Authority-Analysis: v=2.0 cv=fJznK+me c=1 sm=2
\r
23 a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=S-IsBHyFrF4A:10 a=tsa3CZZnAAAA:8
\r
24 a=PXyy0HJUExuPwyU1dx8A:9 a=_B2XMe8CDISQxbFx:21 a=rFUpJbjW55cqXcdj:21
\r
25 a=EcQDfIwDZEqJA1f7rVUV8Q==:117
\r
26 X-Telus-Outbound-IP: 207.102.88.62
\r
27 From: Ian Main <imain@stemwinder.org>
\r
28 To: notmuch@notmuchmail.org
\r
29 Subject: [PATCH] VIM: Add better attachment support
\r
30 Date: Thu, 2 Oct 2014 00:48:52 -0700
\r
31 Message-Id: <1412236132-9624-1-git-send-email-imain@stemwinder.org>
\r
32 X-Mailer: git-send-email 1.9.3
\r
33 X-BeenThere: notmuch@notmuchmail.org
\r
34 X-Mailman-Version: 2.1.13
\r
36 List-Id: "Use and development of the notmuch mail system."
\r
37 <notmuch.notmuchmail.org>
\r
38 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
39 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
41 List-Post: <mailto:notmuch@notmuchmail.org>
\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
43 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
45 X-List-Received-Date: Thu, 02 Oct 2014 07:49:01 -0000
\r
47 This patch changes how the notmuch vim client supports attachments:
\r
49 - For each attachment an 'Attachment <number>: <filename>' is added
\r
51 - You can then use 'e' to extract the attachment under the cursor
\r
52 or use it elsewhere to extract all attachments (the prior behavior)
\r
53 - You can use 'v' to 'view' the attachment using xdg-open by default.
\r
57 vim/notmuch.txt | 8 +++++++-
\r
58 vim/notmuch.vim | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
\r
59 2 files changed, 65 insertions(+), 3 deletions(-)
\r
61 diff --git a/vim/notmuch.txt b/vim/notmuch.txt
\r
62 index 4374102..838a904 100644
\r
63 --- a/vim/notmuch.txt
\r
64 +++ b/vim/notmuch.txt
\r
65 @@ -72,6 +72,9 @@ q Quit view
\r
66 A Archive (-inbox -unread)
\r
67 I Mark as read (-unread)
\r
69 +e Extract attachment on the current 'Attachment' line or all
\r
70 + attachments if the cursor is elsewhere.
\r
71 +v View attachment on the current 'Attachment' line.
\r
75 @@ -148,6 +151,9 @@ You can also configure your externail mail reader and sendemail program:
\r
77 let g:notmuch_reader = 'mutt -f %s'
\r
78 let g:notmuch_sendmail = 'sendmail'
\r
81 +You can also configure what probram is used to view attachments:
\r
83 + let g:notmuch_view_attachment = 'xdg-open'
\r
85 vim:tw=78:ts=8:noet:ft=help:
\r
86 diff --git a/vim/notmuch.vim b/vim/notmuch.vim
\r
87 index 331e930..a5830b5 100644
\r
88 --- a/vim/notmuch.vim
\r
89 +++ b/vim/notmuch.vim
\r
90 @@ -35,6 +35,7 @@ let g:notmuch_show_maps = {
\r
91 \ 't': 'show_tag("")',
\r
92 \ 'o': 'show_open_msg()',
\r
93 \ 'e': 'show_extract_msg()',
\r
94 + \ 'v': 'show_view_attachment()',
\r
95 \ 's': 'show_save_msg()',
\r
96 \ 'p': 'show_save_patches()',
\r
97 \ 'r': 'show_reply()',
\r
98 @@ -58,6 +59,8 @@ let s:notmuch_date_format_default = '%d.%m.%y'
\r
99 let s:notmuch_datetime_format_default = '%d.%m.%y %H:%M:%S'
\r
100 let s:notmuch_reader_default = 'mutt -f %s'
\r
101 let s:notmuch_sendmail_default = 'sendmail'
\r
102 +let s:notmuch_view_attachment_default = 'xdg-open'
\r
103 +let s:notmuch_attachment_tmpdir_default = '~/.notmuch/tmp'
\r
104 let s:notmuch_folders_count_threads_default = 0
\r
106 function! s:new_file_buffer(type, fname)
\r
107 @@ -147,13 +150,53 @@ function! s:show_info()
\r
108 ruby vim_puts get_message.inspect
\r
111 +function! s:show_view_attachment()
\r
112 + let line = getline(".")
\r
115 + line = VIM::evaluate('line')
\r
117 + match = line.match(/^Attachment (\d*):/)
\r
118 + if match and match.length == 2
\r
119 + a = m.mail.attachments[match[1].to_i - 1]
\r
120 + tmpdir = VIM::evaluate('g:notmuch_attachment_tmpdir')
\r
121 + tmpdir = File.expand_path(tmpdir)
\r
122 + Dir.mkdir(tmpdir) unless Dir.exists?(tmpdir)
\r
123 + filename = File.expand_path("#{tmpdir}/#{a.filename}")
\r
124 + vim_puts "Viewing attachment #{filename}"
\r
125 + File.open(filename, 'w') do |f|
\r
126 + f.write a.body.decoded
\r
127 + cmd = VIM::evaluate('g:notmuch_view_attachment')
\r
128 + system(cmd, filename)
\r
131 + vim_puts "No attachment on this line."
\r
136 function! s:show_extract_msg()
\r
137 + let line = getline(".")
\r
140 - m.mail.attachments.each do |a|
\r
141 + line = VIM::evaluate('line')
\r
143 + # If the user is on a line that has an 'Attachment'
\r
144 + # line, we just extract the one attachment.
\r
145 + match = line.match(/^Attachment (\d*):/)
\r
146 + if match and match.length == 2
\r
147 + a = m.mail.attachments[match[1].to_i - 1]
\r
148 File.open(a.filename, 'w') do |f|
\r
149 f.write a.body.decoded
\r
150 - print "Extracted '#{a.filename}'"
\r
151 + vim_puts "Extracted #{a.filename}"
\r
154 + # Extract them all..
\r
155 + m.mail.attachments.each do |a|
\r
156 + File.open(a.filename, 'w') do |f|
\r
157 + f.write a.body.decoded
\r
158 + vim_puts "Extracted #{a.filename}"
\r
163 @@ -326,6 +369,11 @@ ruby << EOF
\r
164 b << "To: %s" % msg['to']
\r
165 b << "Cc: %s" % msg['cc']
\r
166 b << "Date: %s" % msg['date']
\r
168 + nm_m.mail.attachments.each do |a|
\r
170 + b << "Attachment %d: %s" % [cnt, a.filename]
\r
172 nm_m.body_start = b.count
\r
173 b << "--- %s ---" % part.mime_type
\r
174 part.convert.each_line do |l|
\r
175 @@ -420,6 +468,14 @@ function! s:set_defaults()
\r
179 + if !exists('g:notmuch_attachment_tmpdir')
\r
180 + let g:notmuch_attachment_tmpdir = s:notmuch_attachment_tmpdir_default
\r
183 + if !exists('g:notmuch_view_attachment')
\r
184 + let g:notmuch_view_attachment = s:notmuch_view_attachment_default
\r
187 if !exists('g:notmuch_folders_count_threads')
\r
188 if exists('g:notmuch_rb_count_threads')
\r
189 let g:notmuch_count_threads = g:notmuch_rb_count_threads
\r