From: Nick Howell <nlhowell@gmail.com>
To: notmuch@notmuchmail.org
Cc: nlhowell@gmail.com
Subject: [RFC PATCHv2 6/8] vim: show: add multipart/alternative picking
Date: Thu, 13 Oct 2016 14:47:54 -0600 [thread overview]
Message-ID: <1476391676-14542-7-git-send-email-nlhowell@gmail.com> (raw)
In-Reply-To: <1476391676-14542-1-git-send-email-nlhowell@gmail.com>
Instead of just blindly showing every part of multipart/*, add special
handling for multipart/alternative (which is designed for alternative
content-types containing the same message). Two new preferences are
added:
- g:notmuch_multipart_alternative_display
= "best-only" (default)
Display only the favorite content-type.
= "best-sort"
Display all content-types, sorted by preference.
= "verbatim"
Display all content-types in the order they appear.
- g:notmuch_multipart_alternative_preference
Array which orders mimetypes based on preference; note that if a
part has a mimetype which matches none of these, the part will
not be displayed!
e.g. ['text/plain', 'text/*', '*'] (default)
The RFC describing multipart/alternative has some subtleties regarding
ways the sender can influence which content-type is shown; we mostly
ignore these, and give the user the choice.
Note that the defaults break some mail programs (**cough apple**) which,
when attaching images, prefer to embed the image in text/html, but then
list a multipart/alternative of text/plain without attaching the image.
---
vim/notmuch.vim | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/vim/notmuch.vim b/vim/notmuch.vim
index 5cb8d20..795ab26 100644
--- a/vim/notmuch.vim
+++ b/vim/notmuch.vim
@@ -61,6 +61,8 @@ let s:notmuch_sendmail_default = 'sendmail'
let s:notmuch_folders_count_threads_default = 0
let s:notmuch_compose_start_insert_default = 1
let s:notmuch_mailcap_filter_default = "DISPLAY= run-mailcap --action=view %s:-"
+let s:notmuch_multipart_alternative_display_default = "best-only"
+let s:notmuch_multipart_alternative_preference_default = ['text/plain', 'text/*', '*']
function! s:new_file_buffer(type, fname)
exec printf('edit %s', a:fname)
@@ -324,6 +326,8 @@ ruby << EOF
nm_m = Message.new(msg, m)
$messages << nm_m
mailcap = VIM::evaluate('g:notmuch_mailcap_filter')
+ alternative_preference = VIM::evaluate('g:notmuch_multipart_alternative_preference')
+ alternative_display = VIM::evaluate('g:notmuch_multipart_alternative_display')
date_fmt = VIM::evaluate('g:notmuch_datetime_format')
date = Time.at(msg.date).strftime(date_fmt)
nm_m.start = b.count
@@ -337,7 +341,24 @@ ruby << EOF
while parts.any?(&:multipart?)
parts = parts.collect do |part|
if part.multipart?
- part.parts
+ if part.mime_type == "multipart/alternative"
+ case alternative_display
+ when "best-only"
+ alternative_preference.each.collect do |mime_type|
+ part.parts.find { |p| File.fnmatch(mime_type, p.mime_type) }
+ end.first
+ when "best-sort"
+ part.parts.sort_by do |p|
+ alternative_preference.collect.with_index do |mime_type, i|
+ (File.fnmatch(mime_type, p.mime_type) ? 0 : 1) << i
+ end.reduce(:+)
+ end
+ when "verbatim"
+ part.parts
+ end
+ else
+ part.parts
+ end
else
part
end
@@ -417,6 +438,14 @@ endfunction
"" root
function! s:set_defaults()
+ if !exists('g:notmuch_multipart_alternative_display')
+ let g:notmuch_multipart_alternative_display = s:notmuch_multipart_alternative_display_default
+ endif
+
+ if !exists('g:notmuch_multipart_alternative_preference')
+ let g:notmuch_multipart_alternative_preference = s:notmuch_multipart_alternative_preference_default
+ endif
+
if !exists('g:notmuch_mailcap_filter')
let g:notmuch_mailcap_filter = s:notmuch_mailcap_filter_default
endif
--
2.7.3
next prev parent reply other threads:[~2016-10-13 20:48 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-29 15:21 Status of Vim client J. Lewis Muir
2016-09-29 17:52 ` Lucas Hoffmann
2016-09-29 18:52 ` David Bremner
2016-10-08 0:08 ` Nick Howell
2016-10-11 0:39 ` Nick Howell
2016-10-13 17:18 ` David Bremner
2016-10-13 18:19 ` nlhowell
2016-10-13 19:58 ` [RFC PATCH 0/2] vim: add "attach" support to compose Nick Howell
2016-10-13 19:58 ` [RFC PATCH 1/2] vim: compose: support additional Notmuch- filters Nick Howell
2016-10-13 19:58 ` [RFC PATCH 2/2] vim: compose: attachment support Nick Howell
2016-10-13 20:13 ` [RFC PATCH 0/7] vim: add mailcap filtering to show Nick Howell
2016-10-13 20:13 ` [RFC PATCH 1/7] vim: show: add mailcap filtering Nick Howell
2016-10-13 20:13 ` [RFC PATCH 2/7] vim: mailcap: forbid access to display server Nick Howell
2016-10-13 20:13 ` [RFC PATCH 3/7] vim: mailcap: gracefully handle missing mimetype Nick Howell
2016-10-13 20:13 ` [RFC PATCH 4/7] vim: mailcap: don't corrupt the view if filters write to stderr Nick Howell
2016-10-13 20:13 ` [RFC PATCH 5/7] vim: mailcap: redraw after processing Nick Howell
2016-10-13 20:13 ` [RFC PATCH 6/7] vim: mailcap: show all alternatives if none preferred Nick Howell
2016-10-13 20:13 ` [RFC PATCH 7/7] vim: mailcap: handle mailcap failure gracefully Nick Howell
2016-10-13 20:47 ` [RFC PATCHv2 0/8] vim: add mailcap filtering to show Nick Howell
2016-10-13 20:47 ` [RFC PATCHv2 1/8] vim: show: add mailcap filtering Nick Howell
2016-10-13 20:47 ` [RFC PATCHv2 2/8] vim: mailcap: forbid access to display server Nick Howell
2016-10-13 20:47 ` [RFC PATCHv2 3/8] vim: mailcap: gracefully handle missing mimetype Nick Howell
2016-10-13 20:47 ` [RFC PATCHv2 4/8] vim: mailcap: don't corrupt the view if filters write to stderr Nick Howell
2016-10-13 20:47 ` [RFC PATCHv2 5/8] vim: mailcap: redraw after processing Nick Howell
2016-10-13 20:47 ` Nick Howell [this message]
2016-10-13 20:47 ` [RFC PATCHv2 7/8] vim: mailcap: show all alternatives if none preferred Nick Howell
2016-10-13 20:47 ` [RFC PATCHv2 8/8] vim: mailcap: handle mailcap failure gracefully Nick Howell
2016-10-13 20:42 ` Status of Vim client David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1476391676-14542-7-git-send-email-nlhowell@gmail.com \
--to=nlhowell@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).