[PATCH 1/2] vim plugin: Implement show_view_all_mime_parts
Ryan Harper
rharper at shake.ath.cx
Fri Sep 16 19:27:49 PDT 2011
Implement mime attachment viewing in the vim plugin via
notmuch show --format=text parsing for attachment segments.
Extract the part ID, filename, and content-type.
Storing this in a dictionary for use later when implementing
attachment saving.
Signed-off-by: Ryan Harper <rharper at shake.ath.cx>
---
vim/plugin/notmuch.vim | 50 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 49 insertions(+), 1 deletions(-)
diff --git a/vim/plugin/notmuch.vim b/vim/plugin/notmuch.vim
index 21985c7..cbc5b51 100644
--- a/vim/plugin/notmuch.vim
+++ b/vim/plugin/notmuch.vim
@@ -556,7 +556,55 @@ function! s:NM_show_reply()
endfunction
function! s:NM_show_view_all_mime_parts()
- echo 'not implemented'
+ let info = b:nm_raw_info
+ let words = b:nm_search_words
+ let cmd = ['show', '--format=text']
+ let mid = <SID>NM_show_message_id()
+ call add(cmd, <SID>NM_show_message_id())
+ call add(cmd, 'AND')
+ call extend(cmd, <SID>NM_get_search_words())
+ let data = <SID>NM_run(cmd)
+ let lines = split(data, "\n")
+ let attachments = []
+ let bufflines = []
+
+ for line in lines
+ if match(line, g:notmuch_show_attachment_begin_regexp) != -1
+ let m = matchlist(line, 'ID: \(\d\+\), Filename: \(.*\), Content-type: \(\S\+\)')
+ if len(m)
+ " create a attachment dict (id, filename, type, str)
+ " id - message id
+ " filename - filename from MIME attachment
+ " type - Content-type
+ " str - displayable string for the buffer
+ let att = {}
+ let att['id'] = m[1]
+ let att['filename']=m[2]
+ let att['type']=m[3]
+ let att['mid']=mid
+ let id = att['id']
+ let fn = att['filename']
+ let ty = att['type']
+ let att['str']=printf('%d %-60s[%s]', id, fn, ty)
+ call add(attachments, att)
+ call add(bufflines, att['str'])
+ endif
+ endif
+
+ endfor
+ if len(attachments) == 0
+ echo 'No attachments'
+ endif
+
+ let prev_bufnr = bufnr('%')
+ setlocal bufhidden=hide
+ call <SID>NM_newBuffer('', 'show', bufflines)
+ setlocal bufhidden=delete
+ let b:attachments = attachments
+ let b:nm_prev_bufnr = prev_bufnr
+ let b:nm_raw_info = info
+ let b:nm_search_words = words
+ call <SID>NM_set_map('n', g:notmuch_show_maps)
endfunction
function! s:NM_show_view_raw_message()
--
1.7.6
More information about the notmuch
mailing list