Re: [PATCH v4 08/16] reorganize indexing of multipart/signed and multipart/encrypted
[notmuch-archives.git] / 7d / 73af1b65028aa367f1e4f880638dc5504987aa
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 D9D43431FBD\r
6         for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 09:39:06 -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 jg1djzJ+HXxA for <notmuch@notmuchmail.org>;\r
16         Fri, 24 Oct 2014 09:38:59 -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 915BF431FC9\r
19         for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 09:38:59 -0700 (PDT)\r
20 Received: from ovo.mains.priv ([207.102.88.62]) by cmta3.telus.net with TELUS\r
21         id 74es1p00k1LiWEf014ezkY; Fri, 24 Oct 2014 10:38:59 -0600\r
22 X-Authority-Analysis: v=2.0 cv=GePJa3rL c=1 sm=2\r
23         a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=tsa3CZZnAAAA:8 a=r_jncFobP5VkJRuen9wA:9\r
24         a=ba93nok9ugSu9a0E:21 a=27csIzTaovQh-TYg: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 2/2] VIM: Add URI handling\r
30 Date: Fri, 24 Oct 2014 09:38:40 -0700\r
31 Message-Id: <1414168720-1574-2-git-send-email-imain@stemwinder.org>\r
32 X-Mailer: git-send-email 1.9.3\r
33 In-Reply-To: <1414168720-1574-1-git-send-email-imain@stemwinder.org>\r
34 References: <1414168720-1574-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: Fri, 24 Oct 2014 16:39:07 -0000\r
48 \r
49 Add URI handling to the vim client.  You can now press 'enter' by\r
50 default and the client will parse the current line and find any 'Part's\r
51 or URIs available for opening.  If there are more than one it opens the\r
52 one under the cursor or else it opens the only one available.  It also\r
53 supports mailto: URI's and will compose a new message when activated.\r
54 \r
55 By default xdg-open is used for everything but mailto: which generally\r
56 does the right thing afaict.\r
57 \r
58 Note that this is now dependant on the attachment patch in order to\r
59 make the nice 'enter' behavior work for both.\r
60 \r
61     Ian\r
62 \r
63 ---\r
64 Fixed commit message.\r
65 \r
66  vim/notmuch.txt |  3 ++-\r
67  vim/notmuch.vim | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++------\r
68  2 files changed, 70 insertions(+), 9 deletions(-)\r
69 \r
70 diff --git a/vim/notmuch.txt b/vim/notmuch.txt\r
71 index d5e1ad2..f51b20f 100644\r
72 --- a/vim/notmuch.txt\r
73 +++ b/vim/notmuch.txt\r
74 @@ -74,7 +74,8 @@ I     Mark as read (-unread)\r
75  t      Tag (prompted)\r
76  e       Extract attachment on the current 'Part' line or all\r
77         attachments if the cursor is elsewhere.\r
78 -<enter> View attachment on the current 'Part' line.\r
79 +<enter> View email part on the current 'Part' line, or open URI under cursor\r
80 +        or on line.\r
81  s      Search\r
82  p      Save patches\r
83  r      Reply\r
84 diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
85 index 1466e50..2f76f55 100644\r
86 --- a/vim/notmuch.vim\r
87 +++ b/vim/notmuch.vim\r
88 @@ -12,7 +12,7 @@ let g:notmuch_folders_maps = {\r
89         \ '<Enter>':    'folders_show_search()',\r
90         \ 's':          'folders_search_prompt()',\r
91         \ '=':          'folders_refresh()',\r
92 -       \ 'c':          'compose()',\r
93 +       \ 'c':          'compose("")',\r
94         \ }\r
95  \r
96  let g:notmuch_search_maps = {\r
97 @@ -25,7 +25,7 @@ let g:notmuch_search_maps = {\r
98         \ 's':          'search_search_prompt()',\r
99         \ '=':          'search_refresh()',\r
100         \ '?':          'search_info()',\r
101 -       \ 'c':          'compose()',\r
102 +       \ 'c':          'compose("")',\r
103         \ }\r
104  \r
105  let g:notmuch_show_maps = {\r
106 @@ -35,13 +35,13 @@ let g:notmuch_show_maps = {\r
107         \ 't':          'show_tag("")',\r
108         \ 'o':          'show_open_msg()',\r
109         \ 'e':          'show_extract_msg()',\r
110 -       \ '<Enter>':    'show_view_attachment()',\r
111 +       \ '<Enter>':    'show_view_magic()',\r
112         \ 's':          'show_save_msg()',\r
113         \ 'p':          'show_save_patches()',\r
114         \ 'r':          'show_reply()',\r
115         \ '?':          'show_info()',\r
116         \ '<Tab>':      'show_next_msg()',\r
117 -       \ 'c':          'compose()',\r
118 +       \ 'c':          'compose("")',\r
119         \ }\r
120  \r
121  let g:notmuch_compose_maps = {\r
122 @@ -63,6 +63,7 @@ let s:notmuch_view_attachment_default = 'xdg-open'\r
123  let s:notmuch_attachment_tmpdir_default = '~/.notmuch/tmp'\r
124  let s:notmuch_folders_count_threads_default = 0\r
125  let s:notmuch_compose_start_insert_default = 1\r
126 +let s:notmuch_open_uri_default = 'xdg-open'\r
127  \r
128  function! s:new_file_buffer(type, fname)\r
129         exec printf('edit %s', a:fname)\r
130 @@ -141,8 +142,8 @@ function! s:show_reply()\r
131         end\r
132  endfunction\r
133  \r
134 -function! s:compose()\r
135 -       ruby open_compose\r
136 +function! s:compose(to_email)\r
137 +       ruby open_compose(VIM::evaluate('a:to_email'))\r
138         let b:compose_done = 0\r
139         call s:set_map(g:notmuch_compose_maps)\r
140         autocmd BufDelete <buffer> call s:on_compose_delete()\r
141 @@ -155,6 +156,22 @@ function! s:show_info()\r
142         ruby vim_puts get_message.inspect\r
143  endfunction\r
144  \r
145 +function! s:show_view_magic()\r
146 +       let line = getline(".")\r
147 +\r
148 +ruby << EOF\r
149 +       line = VIM::evaluate('line')\r
150 +\r
151 +       # Easiest to check for 'Part' types first..\r
152 +       match = line.match(/^Part (\d*):/)\r
153 +       if match and match.length == 2\r
154 +               VIM::command('call s:show_view_attachment()')\r
155 +       else\r
156 +               VIM::command('call s:show_open_uri()')\r
157 +       end\r
158 +EOF\r
159 +endfunction\r
160 +\r
161  function! s:show_view_attachment()\r
162         let line = getline(".")\r
163  ruby << EOF\r
164 @@ -226,6 +243,45 @@ ruby << EOF\r
165  EOF\r
166  endfunction\r
167  \r
168 +function! s:show_open_uri()\r
169 +       let line = getline(".")\r
170 +       let pos = getpos(".")\r
171 +       let col = pos[2]\r
172 +ruby << EOF\r
173 +       m = get_message\r
174 +       line = VIM::evaluate('line')\r
175 +       col = VIM::evaluate('col') - 1\r
176 +       uris = URI.extract(line)\r
177 +       wanted_uri = nil\r
178 +       if uris.length == 1\r
179 +               wanted_uri = uris[0]\r
180 +       else\r
181 +               uris.each do |uri|\r
182 +                       # Check to see the URI is at the present cursor location\r
183 +                       idx = line.index(uri)\r
184 +                       if col >= idx and col <= idx + uri.length\r
185 +                               wanted_uri = uri\r
186 +                               break\r
187 +                       end\r
188 +               end\r
189 +       end\r
190 +\r
191 +       if wanted_uri\r
192 +               uri = URI.parse(wanted_uri)\r
193 +               if uri.class == URI::MailTo\r
194 +                       vim_puts("Composing new email to #{uri.to}.")\r
195 +                       VIM::command("call s:compose('#{uri.to}')")\r
196 +               else\r
197 +                       vim_puts("Opening #{uri.to_s}.")\r
198 +                       cmd = VIM::evaluate('g:notmuch_open_uri')\r
199 +                       system(cmd, uri.to_s)\r
200 +               end\r
201 +       else\r
202 +               vim_puts('URI not found.')\r
203 +       end\r
204 +EOF\r
205 +endfunction\r
206 +\r
207  function! s:show_open_msg()\r
208  ruby << EOF\r
209         m = get_message\r
210 @@ -481,6 +537,10 @@ function! s:set_defaults()\r
211                 endif\r
212         endif\r
213  \r
214 +       if !exists('g:notmuch_open_uri')\r
215 +               let g:notmuch_open_uri = s:notmuch_open_uri_default\r
216 +       endif\r
217 +\r
218         if !exists('g:notmuch_reader')\r
219                 if exists('g:notmuch_rb_reader')\r
220                         let g:notmuch_reader = g:notmuch_rb_reader\r
221 @@ -693,11 +753,11 @@ ruby << EOF\r
222                 open_compose_helper(lines, cur)\r
223         end\r
224  \r
225 -       def open_compose()\r
226 +       def open_compose(to_email)\r
227                 lines = []\r
228  \r
229                 lines << "From: #{$email}"\r
230 -               lines << "To: "\r
231 +               lines << "To: #{to_email}"\r
232                 cur = lines.count\r
233  \r
234                 lines << "Cc: "\r
235 -- \r
236 1.9.3\r
237 \r