Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 9a / fad35493acd6b5b6595cb56057ee35666a72de
1 Return-Path: <tomi.ollila@iki.fi>\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 6648A431FC9\r
6         for <notmuch@notmuchmail.org>; Sat, 25 Oct 2014 03:42:08 -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 tests=[none]\r
12         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 hWpbRGPQvaLO for <notmuch@notmuchmail.org>;\r
16         Sat, 25 Oct 2014 03:42:01 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id AE383431FD4\r
19         for <notmuch@notmuchmail.org>; Sat, 25 Oct 2014 03:42:00 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 3672010008C;\r
22         Sat, 25 Oct 2014 13:41:40 +0300 (EEST)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: Ian Main <imain@stemwinder.org>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH v4 1/2] VIM: Add better attachment support\r
26 In-Reply-To: <1414168720-1574-1-git-send-email-imain@stemwinder.org>\r
27 References: <1414168720-1574-1-git-send-email-imain@stemwinder.org>\r
28 User-Agent: Notmuch/0.18.1+130~ga61922f (http://notmuchmail.org) Emacs/24.3.1\r
29         (x86_64-unknown-linux-gnu)\r
30 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
31         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
32         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
33 Date: Sat, 25 Oct 2014 13:41:40 +0300\r
34 Message-ID: <m2vbn8mnx7.fsf@guru.guru-group.fi>\r
35 MIME-Version: 1.0\r
36 Content-Type: text/plain\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.13\r
39 Precedence: list\r
40 List-Id: "Use and development of the notmuch mail system."\r
41         <notmuch.notmuchmail.org>\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
43         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
45 List-Post: <mailto:notmuch@notmuchmail.org>\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
49 X-List-Received-Date: Sat, 25 Oct 2014 10:42:08 -0000\r
50 \r
51 On Fri, Oct 24 2014, Ian Main <imain@stemwinder.org> wrote:\r
52 \r
53 > Change how the notmuch vim client supports attachments:\r
54 >\r
55 > - For each message part a 'Part <number>: <filename>' is added to the\r
56 >   header.\r
57 > - You can then use 'e' to extract the attachment under the cursor or\r
58 >   use it elsewhere to extract all attachments (the prior behavior)\r
59 > - You can use 'v' to 'view' the attachment/part using xdg-open by\r
60 >   default.\r
61 > - If the message is 'text/html' we include a 'Part:' for the body of\r
62 >   the message so you can easily view it in a web browser if you so\r
63 >   choose.\r
64 >\r
65 >     Ian\r
66 > ---\r
67 >\r
68 > - Fixed commit message\r
69 > - Fixed documentation\r
70 >\r
71 >  vim/notmuch.txt |  8 +++++-\r
72 >  vim/notmuch.vim | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--\r
73 >  2 files changed, 89 insertions(+), 3 deletions(-)\r
74 >\r
75 > diff --git a/vim/notmuch.txt b/vim/notmuch.txt\r
76 > index 4374102..d5e1ad2 100644\r
77 > --- a/vim/notmuch.txt\r
78 > +++ b/vim/notmuch.txt\r
79 > @@ -72,6 +72,9 @@ q   Quit view\r
80 >  A    Archive (-inbox -unread)\r
81 >  I    Mark as read (-unread)\r
82 >  t    Tag (prompted)\r
83 > +e       Extract attachment on the current 'Part' line or all\r
84 \r
85 This and the following patch use spaces instead of tab in the line above\r
86 (and following patch few lines below) -- the indentation looked weird and\r
87 that got me to look more.\r
88 \r
89 I was going to look more of this but run out of time. I'll look the\r
90 this through after someone else who uses vim has tested these patched\r
91 and reported their experiences.\r
92 \r
93 Tomi\r
94 \r
95 \r
96 > +     attachments if the cursor is elsewhere.\r
97 > +<enter> View attachment on the current 'Part' line.\r
98 >  s    Search\r
99 >  p    Save patches\r
100 >  r    Reply\r
101 > @@ -148,6 +151,9 @@ You can also configure your externail mail reader and sendemail program:\r
102 >  >\r
103 >       let g:notmuch_reader = 'mutt -f %s'\r
104 >       let g:notmuch_sendmail = 'sendmail'\r
105 > -<\r
106 > +\r
107 > +You can also configure what probram is used to view attachments:\r
108 > +\r
109 > +     let g:notmuch_view_attachment = 'xdg-open'\r
110 >  \r
111 >  vim:tw=78:ts=8:noet:ft=help:\r
112 > diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
113 > index cad9517..1466e50 100644\r
114 > --- a/vim/notmuch.vim\r
115 > +++ b/vim/notmuch.vim\r
116 > @@ -35,6 +35,7 @@ let g:notmuch_show_maps = {\r
117 >       \ 't':          'show_tag("")',\r
118 >       \ 'o':          'show_open_msg()',\r
119 >       \ 'e':          'show_extract_msg()',\r
120 > +     \ '<Enter>':    'show_view_attachment()',\r
121 >       \ 's':          'show_save_msg()',\r
122 >       \ 'p':          'show_save_patches()',\r
123 >       \ 'r':          'show_reply()',\r
124 > @@ -58,6 +59,8 @@ let s:notmuch_date_format_default = '%d.%m.%y'\r
125 >  let s:notmuch_datetime_format_default = '%d.%m.%y %H:%M:%S'\r
126 >  let s:notmuch_reader_default = 'mutt -f %s'\r
127 >  let s:notmuch_sendmail_default = 'sendmail'\r
128 > +let s:notmuch_view_attachment_default = 'xdg-open'\r
129 > +let s:notmuch_attachment_tmpdir_default = '~/.notmuch/tmp'\r
130 >  let s:notmuch_folders_count_threads_default = 0\r
131 >  let s:notmuch_compose_start_insert_default = 1\r
132 >  \r
133 > @@ -152,13 +155,72 @@ function! s:show_info()\r
134 >       ruby vim_puts get_message.inspect\r
135 >  endfunction\r
136 >  \r
137 > +function! s:show_view_attachment()\r
138 > +     let line = getline(".")\r
139 > +ruby << EOF\r
140 > +     m = get_message\r
141 > +     line = VIM::evaluate('line')\r
142 > +\r
143 > +     match = line.match(/^Part (\d*):/)\r
144 > +     if match and match.length == 2\r
145 > +             # Set up the tmpdir\r
146 > +             tmpdir = VIM::evaluate('g:notmuch_attachment_tmpdir')\r
147 > +             tmpdir = File.expand_path(tmpdir)\r
148 > +             Dir.mkdir(tmpdir) unless Dir.exists?(tmpdir)\r
149 > +\r
150 > +             p = m.mail.parts[match[1].to_i - 1]\r
151 > +             if p == nil\r
152 > +                     # Not a multipart message, use the message itself.\r
153 > +                     p = m.mail\r
154 > +             end\r
155 > +             if p.filename and p.filename.length > 0\r
156 > +                     filename = p.filename\r
157 > +             else\r
158 > +                     suffix = ''\r
159 > +                     if p.mime_type == 'text/html'\r
160 > +                             suffix = '.html'\r
161 > +                     end\r
162 > +                     filename = "part-#{match[1]}#{suffix}"\r
163 > +             end\r
164 > +\r
165 > +             # Sanitize just in case..\r
166 > +             filename.gsub!(/[^0-9A-Za-z.\-]/, '_')\r
167 > +\r
168 > +             fullpath = File.expand_path("#{tmpdir}/#{filename}")\r
169 > +             vim_puts "Viewing attachment #{fullpath}"\r
170 > +             File.open(fullpath, 'w') do |f|\r
171 > +                     f.write p.body.decoded\r
172 > +                     cmd = VIM::evaluate('g:notmuch_view_attachment')\r
173 > +                     system(cmd, fullpath)\r
174 > +             end\r
175 > +     else\r
176 > +             vim_puts "No attachment on this line."\r
177 > +     end\r
178 > +EOF\r
179 > +endfunction\r
180 > +\r
181 >  function! s:show_extract_msg()\r
182 > +     let line = getline(".")\r
183 >  ruby << EOF\r
184 >       m = get_message\r
185 > -     m.mail.attachments.each do |a|\r
186 > +     line = VIM::evaluate('line')\r
187 > +\r
188 > +     # If the user is on a line that has an 'Part'\r
189 > +     # line, we just extract the one attachment.\r
190 > +     match = line.match(/^Part (\d*):/)\r
191 > +     if match and match.length == 2\r
192 > +             a = m.mail.parts[match[1].to_i - 1]\r
193 >               File.open(a.filename, 'w') do |f|\r
194 >                       f.write a.body.decoded\r
195 > -                     print "Extracted '#{a.filename}'"\r
196 > +                     vim_puts "Extracted #{a.filename}"\r
197 > +             end\r
198 > +     else\r
199 > +             # Extract them all..\r
200 > +             m.mail.attachments.each do |a|\r
201 > +                     File.open(a.filename, 'w') do |f|\r
202 > +                             f.write a.body.decoded\r
203 > +                             vim_puts "Extracted #{a.filename}"\r
204 > +                     end\r
205 >               end\r
206 >       end\r
207 >  EOF\r
208 > @@ -331,6 +393,16 @@ ruby << EOF\r
209 >                       b << "To: %s" % msg['to']\r
210 >                       b << "Cc: %s" % msg['cc']\r
211 >                       b << "Date: %s" % msg['date']\r
212 > +                     cnt = 0\r
213 > +                     m.parts.each do |p|\r
214 > +                             cnt += 1\r
215 > +                             b << "Part %d: %s (%s)" % [cnt, p.mime_type, p.filename]\r
216 > +                     end\r
217 > +                     # Add a special case for text/html messages.  Here we show the\r
218 > +                     # only 'part' so that we can view it in a web browser if we want.\r
219 > +                     if m.parts.length == 0 and part.mime_type == 'text/html'\r
220 > +                             b << "Part 1: text/html"\r
221 > +                     end\r
222 >                       nm_m.body_start = b.count\r
223 >                       b << "--- %s ---" % part.mime_type\r
224 >                       part.convert.each_line do |l|\r
225 > @@ -425,6 +497,14 @@ function! s:set_defaults()\r
226 >               endif\r
227 >       endif\r
228 >  \r
229 > +     if !exists('g:notmuch_attachment_tmpdir')\r
230 > +             let g:notmuch_attachment_tmpdir = s:notmuch_attachment_tmpdir_default\r
231 > +     endif\r
232 > +\r
233 > +     if !exists('g:notmuch_view_attachment')\r
234 > +             let g:notmuch_view_attachment = s:notmuch_view_attachment_default\r
235 > +     endif\r
236 > +\r
237 >       if !exists('g:notmuch_folders_count_threads')\r
238 >               if exists('g:notmuch_rb_count_threads')\r
239 >                       let g:notmuch_count_threads = g:notmuch_rb_count_threads\r
240 > -- \r
241 > 1.9.3\r
242 >\r
243 > _______________________________________________\r
244 > notmuch mailing list\r
245 > notmuch@notmuchmail.org\r
246 > http://notmuchmail.org/mailman/listinfo/notmuch\r