Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 33 / aeaed4d077b08ed3288eba06b10c649d874390
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 17E6F431FD4\r
6         for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 15:05:03 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \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 SNFLBCwqqi1B for <notmuch@notmuchmail.org>;\r
16         Thu, 23 Oct 2014 15:04:59 -0700 (PDT)\r
17 Received: from cmta18.telus.net (cmta18.telus.net [209.171.16.91])\r
18         by olra.theworths.org (Postfix) with ESMTP id 8E0D3431FBD\r
19         for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 15:04:59 -0700 (PDT)\r
20 Received: from ovo.mains.priv ([207.102.88.62]) by cmta18.telus.net with TELUS\r
21         id 6m4x1p00M1LiWEf01m4xok; Thu, 23 Oct 2014 16:04:58 -0600\r
22 X-Authority-Analysis: v=2.0 cv=B+NnJpRM c=1 sm=2\r
23         a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=tsa3CZZnAAAA:8 a=_rKzicO8r5wJqIb2hKcA:9\r
24         a=yj7JwsOxHXLfrXF9:21 a=oO6dRLWuanIZ9Wjs: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, 23 Oct 2014 15:04:51 -0700\r
31 Message-Id: <1414101891-10714-1-git-send-email-imain@stemwinder.org>\r
32 X-Mailer: git-send-email 1.9.3\r
33 In-Reply-To: <1412236132-9624-1-git-send-email-imain@stemwinder.org>\r
34 References: <1412236132-9624-1-git-send-email-imain@stemwinder.org>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.13\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Thu, 23 Oct 2014 22:05:03 -0000\r
48 \r
49 This patch changes how the notmuch vim client supports attachments:\r
50 \r
51 - For each message part a 'Part <number>: <filename>' is added\r
52   to the header.\r
53 - You can then use 'e' to extract the attachment under the cursor\r
54   or use it elsewhere to extract all attachments (the prior behavior)\r
55 - You can use 'v' to 'view' the attachment/part using xdg-open by default.\r
56 - If the message is 'text/html' we include a 'Part:' for the body of the\r
57   message so you can easily view it in a web browser if you so choose.\r
58 \r
59     Ian\r
60 ---\r
61  vim/notmuch.txt |  8 +++++-\r
62  vim/notmuch.vim | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--\r
63  2 files changed, 89 insertions(+), 3 deletions(-)\r
64 \r
65 diff --git a/vim/notmuch.txt b/vim/notmuch.txt\r
66 index 4374102..838a904 100644\r
67 --- a/vim/notmuch.txt\r
68 +++ b/vim/notmuch.txt\r
69 @@ -72,6 +72,9 @@ q     Quit view\r
70  A      Archive (-inbox -unread)\r
71  I      Mark as read (-unread)\r
72  t      Tag (prompted)\r
73 +e       Extract attachment on the current 'Attachment' line or all\r
74 +       attachments if the cursor is elsewhere.\r
75 +v       View attachment on the current 'Attachment' line.\r
76  s      Search\r
77  p      Save patches\r
78  r      Reply\r
79 @@ -148,6 +151,9 @@ You can also configure your externail mail reader and sendemail program:\r
80  >\r
81         let g:notmuch_reader = 'mutt -f %s'\r
82         let g:notmuch_sendmail = 'sendmail'\r
83 -<\r
84 +\r
85 +You can also configure what probram is used to view attachments:\r
86 +\r
87 +       let g:notmuch_view_attachment = 'xdg-open'\r
88  \r
89  vim:tw=78:ts=8:noet:ft=help:\r
90 diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
91 index 331e930..5f73dce 100644\r
92 --- a/vim/notmuch.vim\r
93 +++ b/vim/notmuch.vim\r
94 @@ -35,6 +35,7 @@ let g:notmuch_show_maps = {\r
95         \ 't':          'show_tag("")',\r
96         \ 'o':          'show_open_msg()',\r
97         \ 'e':          'show_extract_msg()',\r
98 +       \ '<Enter>':    'show_view_attachment()',\r
99         \ 's':          'show_save_msg()',\r
100         \ 'p':          'show_save_patches()',\r
101         \ 'r':          'show_reply()',\r
102 @@ -58,6 +59,8 @@ let s:notmuch_date_format_default = '%d.%m.%y'\r
103  let s:notmuch_datetime_format_default = '%d.%m.%y %H:%M:%S'\r
104  let s:notmuch_reader_default = 'mutt -f %s'\r
105  let s:notmuch_sendmail_default = 'sendmail'\r
106 +let s:notmuch_view_attachment_default = 'xdg-open'\r
107 +let s:notmuch_attachment_tmpdir_default = '~/.notmuch/tmp'\r
108  let s:notmuch_folders_count_threads_default = 0\r
109  \r
110  function! s:new_file_buffer(type, fname)\r
111 @@ -147,13 +150,72 @@ function! s:show_info()\r
112         ruby vim_puts get_message.inspect\r
113  endfunction\r
114  \r
115 +function! s:show_view_attachment()\r
116 +       let line = getline(".")\r
117 +ruby << EOF\r
118 +       m = get_message\r
119 +       line = VIM::evaluate('line')\r
120 +\r
121 +       match = line.match(/^Part (\d*):/)\r
122 +       if match and match.length == 2\r
123 +               # Set up the tmpdir\r
124 +               tmpdir = VIM::evaluate('g:notmuch_attachment_tmpdir')\r
125 +               tmpdir = File.expand_path(tmpdir)\r
126 +               Dir.mkdir(tmpdir) unless Dir.exists?(tmpdir)\r
127 +\r
128 +               p = m.mail.parts[match[1].to_i - 1]\r
129 +               if p == nil\r
130 +                       # Not a multipart message, use the message itself.\r
131 +                       p = m.mail\r
132 +               end\r
133 +               if p.filename and p.filename.length > 0\r
134 +                       filename = p.filename\r
135 +               else\r
136 +                       suffix = ''\r
137 +                       if p.mime_type == 'text/html'\r
138 +                               suffix = '.html'\r
139 +                       end\r
140 +                       filename = "part-#{match[1]}#{suffix}"\r
141 +               end\r
142 +\r
143 +               # Sanitize just in case..\r
144 +               filename.gsub!(/[^0-9A-Za-z.\-]/, '_')\r
145 +\r
146 +               fullpath = File.expand_path("#{tmpdir}/#{filename}")\r
147 +               vim_puts "Viewing attachment #{fullpath}"\r
148 +               File.open(fullpath, 'w') do |f|\r
149 +                       f.write p.body.decoded\r
150 +                       cmd = VIM::evaluate('g:notmuch_view_attachment')\r
151 +                       system(cmd, fullpath)\r
152 +               end\r
153 +       else\r
154 +               vim_puts "No attachment on this line."\r
155 +       end\r
156 +EOF\r
157 +endfunction\r
158 +\r
159  function! s:show_extract_msg()\r
160 +       let line = getline(".")\r
161  ruby << EOF\r
162         m = get_message\r
163 -       m.mail.attachments.each do |a|\r
164 +       line = VIM::evaluate('line')\r
165 +\r
166 +       # If the user is on a line that has an 'Part'\r
167 +       # line, we just extract the one attachment.\r
168 +       match = line.match(/^Part (\d*):/)\r
169 +       if match and match.length == 2\r
170 +               a = m.mail.parts[match[1].to_i - 1]\r
171                 File.open(a.filename, 'w') do |f|\r
172                         f.write a.body.decoded\r
173 -                       print "Extracted '#{a.filename}'"\r
174 +                       vim_puts "Extracted #{a.filename}"\r
175 +               end\r
176 +       else\r
177 +               # Extract them all..\r
178 +               m.mail.attachments.each do |a|\r
179 +                       File.open(a.filename, 'w') do |f|\r
180 +                               f.write a.body.decoded\r
181 +                               vim_puts "Extracted #{a.filename}"\r
182 +                       end\r
183                 end\r
184         end\r
185  EOF\r
186 @@ -326,6 +388,16 @@ ruby << EOF\r
187                         b << "To: %s" % msg['to']\r
188                         b << "Cc: %s" % msg['cc']\r
189                         b << "Date: %s" % msg['date']\r
190 +                       cnt = 0\r
191 +                       m.parts.each do |p|\r
192 +                               cnt += 1\r
193 +                               b << "Part %d: %s (%s)" % [cnt, p.mime_type, p.filename]\r
194 +                       end\r
195 +                       # Add a special case for text/html messages.  Here we show the\r
196 +                       # only 'part' so that we can view it in a web browser if we want.\r
197 +                       if m.parts.length == 0 and part.mime_type == 'text/html'\r
198 +                               b << "Part 1: text/html"\r
199 +                       end\r
200                         nm_m.body_start = b.count\r
201                         b << "--- %s ---" % part.mime_type\r
202                         part.convert.each_line do |l|\r
203 @@ -420,6 +492,14 @@ function! s:set_defaults()\r
204                 endif\r
205         endif\r
206  \r
207 +       if !exists('g:notmuch_attachment_tmpdir')\r
208 +               let g:notmuch_attachment_tmpdir = s:notmuch_attachment_tmpdir_default\r
209 +       endif\r
210 +\r
211 +       if !exists('g:notmuch_view_attachment')\r
212 +               let g:notmuch_view_attachment = s:notmuch_view_attachment_default\r
213 +       endif\r
214 +\r
215         if !exists('g:notmuch_folders_count_threads')\r
216                 if exists('g:notmuch_rb_count_threads')\r
217                         let g:notmuch_count_threads = g:notmuch_rb_count_threads\r
218 -- \r
219 1.9.3\r
220 \r