From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 9DD616DE009A for ; Fri, 29 Jan 2016 09:27:10 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.356 X-Spam-Level: X-Spam-Status: No, score=0.356 tagged_above=-999 required=5 tests=[AWL=0.423, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_NEUTRAL=0.652, UNPARSEABLE_RELAY=0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F4u0oaFlaE61 for ; Fri, 29 Jan 2016 09:27:09 -0800 (PST) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id A14826DE0AF8 for ; Fri, 29 Jan 2016 09:27:08 -0800 (PST) Received: by mail-wm0-f65.google.com with SMTP id 128so8903908wmz.3 for ; Fri, 29 Jan 2016 09:27:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dme-org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=0X/jsVseyH/oTnptr3Ki0Za91lOU+HnuENP3Pi1dtjs=; b=z8FEbvrBxXvJOA73bwx19H5PGvVmPcvkvJTkTthLKQYPUTIY+FanS9m25m0HvCLQdx 9gGKgSoXLy1wP9nFUl8vWJXB61A2pC3aB5wNve+19CwoGO39SYKClnqiJJDPGF+PpouE KAluBt1x6HshPJ8ya5NRl+BXFuDKySAHoQZSFzFDq6MzxGCsfUCjRvvctmods6z7+byt VSxnqIbcwqFfWpXC9h/8tV8k750HwEk5fFvn9UK61qcOqI+DljM/OSmx1hAnG1K/beUx oymh3R4mSUDzrfRjMIcRNB1awldXkkb/chCXWQeidy0LZkVhhWQpPHb7gAXXqq9zCUVU Bxmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=0X/jsVseyH/oTnptr3Ki0Za91lOU+HnuENP3Pi1dtjs=; b=OxJZ0gKOqYVrbCmLS1ZYjCs01Xo278FGE3TGJ7OMT5YMOKEhMeX1m75nF38FqZRrnh AWvu0PIJB1Qw7aDp/RDNTqaGNQ4cNBQDyAyD4cBzRzEBmXGgspsiurkxNrzn3DgUYqk3 7Uk8dJCX2w9F+euWQ4BqpCwhVnvzvvwb1SenKD0QKB0g8PJPwNtskLSJdZiWEc5PvxeT p/puKUMA6z4ZOsysVEe0AneFfDytxd2oZWz8RhayfTG6cHPL8euhPlTTIosRPTf4T93l UPiUGdUxPS/HBfkCwS+ORdT0klpYzULF73KraC5mMVNRHIf4sbjHgzgQgaD/7cQ2Z4X/ 0S2g== X-Gm-Message-State: AG10YOS/WYd08EXI645gtOlGGIRCNsGTA1Iz3ncH9Fz5fTeyxBJWXmOlGitwNDAFIaNRUg== X-Received: by 10.28.131.70 with SMTP id f67mr10682226wmd.66.1454088427238; Fri, 29 Jan 2016 09:27:07 -0800 (PST) Received: from disaster-area.hh.sledj.net ([2a01:348:1a2:1:ea39:35ff:fe2c:a227]) by smtp.gmail.com with ESMTPSA id e9sm16533897wja.25.2016.01.29.09.27.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Jan 2016 09:27:05 -0800 (PST) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 66f89116 for ; Fri, 29 Jan 2016 17:27:02 +0000 (UTC) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH v2] emacs: Allow part preferences to depend on message content. Date: Fri, 29 Jan 2016 17:27:01 +0000 Message-Id: <1454088421-6081-2-git-send-email-dme@dme.org> X-Mailer: git-send-email 2.6.3 In-Reply-To: <1454088421-6081-1-git-send-email-dme@dme.org> References: <1454088421-6081-1-git-send-email-dme@dme.org> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jan 2016 17:27:10 -0000 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-mua.el | 2 +- emacs/notmuch-show.el | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 89c01a5..6b815c2 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-mua.el b/emacs/notmuch-mua.el index 5462f54..8244258 100644 --- a/emacs/notmuch-mua.el +++ b/emacs/notmuch-mua.el @@ -147,7 +147,7 @@ Note that these functions use `mail-citation-hook' if that is non-nil." if (notmuch-match-content-type (plist-get part :content-type) "multipart/alternative") collect (let* ((subparts (plist-get part :content)) (types (mapcar (lambda (part) (plist-get part :content-type)) subparts)) - (chosen-type (car (notmuch-multipart/alternative-choose types)))) + (chosen-type (car (notmuch-multipart/alternative-choose nil types)))) (loop for part in (reverse subparts) if (notmuch-match-content-type (plist-get part :content-type) chosen-type) return part)) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 3345878..2ec30a8 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -612,7 +612,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.6.3