* [PATCH v3] Allow content preference based on message content.
@ 2016-04-03 16:04 David Edmondson
2016-04-03 16:04 ` [PATCH v3] emacs: Allow part preferences to depend " David Edmondson
[not found] ` <m1oa5fuv9v.fsf@YELP-CHARLIE.i-did-not-set--mail-host-address--so-tickle-me>
0 siblings, 2 replies; 4+ messages in thread
From: David Edmondson @ 2016-04-03 16:04 UTC (permalink / raw)
To: notmuch
Allow content preference based on message content.
An example configuration might be:
(defun dme:determine-discouraged (msg)
(let* ((headers (plist-get msg :headers))
(from (or (plist-get headers :From) "")))
(cond
((string-match "9195404@capita-intouch.co.uk" from)
'("text/plain"))
(t
'("text/html" "multipart/related")))))
(setq notmuch-multipart/alternative-discouraged
'dme:determine-discouraged)
This would discourage text/html and multipart/related generally, but
discourage text/plain should the message be sent from
9195404@capita-intouch.co.uk.
v2:
- Remove the simple evaluation variant based on feedback.
v3:
- Merge forward.
- Update the example to allow for a nil msg (which should no longer
happen, but it's good to be safe).
David Edmondson (1):
emacs: Allow part preferences to depend on message content.
emacs/notmuch-lib.el | 20 ++++++++++++++++----
emacs/notmuch-show.el | 2 +-
2 files changed, 17 insertions(+), 5 deletions(-)
--
2.1.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3] emacs: Allow part preferences to depend on message content.
2016-04-03 16:04 [PATCH v3] Allow content preference based on message content David Edmondson
@ 2016-04-03 16:04 ` David Edmondson
2016-04-09 19:19 ` David Bremner
[not found] ` <m1oa5fuv9v.fsf@YELP-CHARLIE.i-did-not-set--mail-host-address--so-tickle-me>
1 sibling, 1 reply; 4+ messages in thread
From: David Edmondson @ 2016-04-03 16:04 UTC (permalink / raw)
To: notmuch
Currently the preference for which sub-part of a multipart/alternative
part is shown is global. Allow to the user to override the settings on a
per-message basis by providing the ability to call a function that has
access to the message to return the discouraged type list.
The original approach is retained as the default.
---
emacs/notmuch-lib.el | 20 ++++++++++++++++----
emacs/notmuch-show.el | 2 +-
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 75a3706..eca837d 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -520,11 +520,23 @@ This replaces spaces, percents, and double quotes in STR with
"multipart/related"
))
-(defun notmuch-multipart/alternative-choose (types)
- "Return a list of preferred types from the given list of types"
+(defun notmuch-multipart/alternative-determine-discouraged (msg)
+ "Return the discouraged alternatives for the specified message."
+ ;; If a function, return the result of calling it.
+ (if (functionp notmuch-multipart/alternative-discouraged)
+ (funcall notmuch-multipart/alternative-discouraged msg)
+ ;; Otherwise simply return the value of the variable, which is
+ ;; assumed to be a list of discouraged alternatives. This is the
+ ;; default behaviour.
+ notmuch-multipart/alternative-discouraged))
+
+(defun notmuch-multipart/alternative-choose (msg types)
+ "Return a list of preferred types from the given list of types
+for this message, if present."
;; Based on `mm-preferred-alternative-precedence'.
- (let ((seq types))
- (dolist (pref (reverse notmuch-multipart/alternative-discouraged))
+ (let ((discouraged (notmuch-multipart/alternative-determine-discouraged msg))
+ (seq types))
+ (dolist (pref (reverse discouraged))
(dolist (elem (copy-sequence seq))
(when (string-match pref elem)
(setq seq (nconc (delete elem seq) (list elem))))))
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7c34449..f6a21e4 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -607,7 +607,7 @@ will return nil if the CID is unknown or cannot be retrieved."
(plist-get part :content)))
(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth button)
- (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))
+ (let ((chosen-type (car (notmuch-multipart/alternative-choose msg (notmuch-show-multipart/*-to-list part))))
(inner-parts (plist-get part :content))
(start (point)))
;; This inserts all parts of the chosen type rather than just one,
--
2.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] emacs: Allow part preferences to depend on message content.
2016-04-03 16:04 ` [PATCH v3] emacs: Allow part preferences to depend " David Edmondson
@ 2016-04-09 19:19 ` David Bremner
0 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2016-04-09 19:19 UTC (permalink / raw)
To: David Edmondson, notmuch
David Edmondson <dme@dme.org> writes:
> Currently the preference for which sub-part of a multipart/alternative
> part is shown is global. Allow to the user to override the settings on a
> per-message basis by providing the ability to call a function that has
> access to the message to return the discouraged type list.
>
> The original approach is retained as the default.
pushed,
d
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] Allow content preference based on message content.
[not found] ` <m1oa5fuv9v.fsf@YELP-CHARLIE.i-did-not-set--mail-host-address--so-tickle-me>
@ 2016-07-30 14:12 ` David Edmondson
0 siblings, 0 replies; 4+ messages in thread
From: David Edmondson @ 2016-07-30 14:12 UTC (permalink / raw)
To: Charlie Allom, notmuch
On Sat, Jul 30 2016, Charlie Allom wrote:
> Do you have an example for the elisp-challenged, on how to match more
> than one email address? I'm just starting out with emacs but this patch
> is just what I need :)
There are many ways. This is what I am using:
(defun dme:determine-discouraged (msg)
(let* ((headers (plist-get msg :headers))
(from (or (plist-get headers :From) "")))
(cond
((string-match (regexp-opt
'(
;; Parmiter's parent mail: text/plain with HTML content.
"9195404@capita-intouch.co.uk"
;; Oracle mobile reports: text/plain with useless content.
"TEMA Alerts"
;; Charles Stanley: HTML only emails.
"info@charles-stanley-direct.co.uk"
;; HackerNews: nicer in HTML.
"kale@hackernewsletter.com"
;; MasterCard: no content in the text.
"CustomerService@information.mbna.co.uk"
))
from)
'("text/plain"))
(t
'("text/html" "multipart/related" "text/x-beehive-notification")))))
> Regards,
> Charlie.
>
> On Sun, Apr 03 2016 at 05:04:37 pm, David Edmondson <dme@dme.org> wrote:
>
>> Allow content preference based on message content.
>>
>> An example configuration might be:
>>
>> (defun dme:determine-discouraged (msg)
>> (let* ((headers (plist-get msg :headers))
>> (from (or (plist-get headers :From) "")))
>> (cond
>> ((string-match "9195404@capita-intouch.co.uk" from)
>> '("text/plain"))
>> (t
>> '("text/html" "multipart/related")))))
>>
>> (setq notmuch-multipart/alternative-discouraged
>> 'dme:determine-discouraged)
>>
>> This would discourage text/html and multipart/related generally, but
>> discourage text/plain should the message be sent from
>> 9195404@capita-intouch.co.uk.
>>
>> v2:
>> - Remove the simple evaluation variant based on feedback.
>>
>> v3:
>> - Merge forward.
>> - Update the example to allow for a nil msg (which should no longer
>> happen, but it's good to be safe).
>>
>>
>> David Edmondson (1):
>> emacs: Allow part preferences to depend on message content.
>>
>> emacs/notmuch-lib.el | 20 ++++++++++++++++----
>> emacs/notmuch-show.el | 2 +-
>> 2 files changed, 17 insertions(+), 5 deletions(-)
>
> --
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-07-30 14:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-03 16:04 [PATCH v3] Allow content preference based on message content David Edmondson
2016-04-03 16:04 ` [PATCH v3] emacs: Allow part preferences to depend " David Edmondson
2016-04-09 19:19 ` David Bremner
[not found] ` <m1oa5fuv9v.fsf@YELP-CHARLIE.i-did-not-set--mail-host-address--so-tickle-me>
2016-07-30 14:12 ` [PATCH v3] Allow content preference based " David Edmondson
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).