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