Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 6C13C6DE0314 for ; Sun, 3 Apr 2016 09:04:53 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.166 X-Spam-Level: X-Spam-Status: No, score=-0.166 tagged_above=-999 required=5 tests=[AWL=-0.099, 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 tItUJHHdabPg for ; Sun, 3 Apr 2016 09:04:45 -0700 (PDT) Received: from mail-lb0-f195.google.com (mail-lb0-f195.google.com [209.85.217.195]) by arlo.cworth.org (Postfix) with ESMTPS id 35A576DE01C2 for ; Sun, 3 Apr 2016 09:04:45 -0700 (PDT) Received: by mail-lb0-f195.google.com with SMTP id bc4so17481049lbc.0 for ; Sun, 03 Apr 2016 09:04:45 -0700 (PDT) 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=efVU9wQRFFod+ey1vTMyZ9KpeBOt+bqbxJAV+a9l+dk=; b=eFQRy4Ryyb+Kaf15mSIWajUzA92rmuXqXQSIa5AgdZxGuwIutn+rFo6ofVVxt9YmzO C/l9444ab4PhUgoodnhZZ0zJSbjdGXdeWDW0YmJ6php1YqEbLB7KhQ2Zm47KfRpm4F8o 1Dg8vdU5Qa+3II48yH/BUvM7fiqPwhuYgGs5cFXucuXRLLYFJ4XurS5AqpmDGfdL32x4 LVsG1U0QKI92JZsryBh7EbM5zxx8DzEHgwsAl8SMXVvldChQK5hzHaNugL6iDgdj5gxt ZB+S9pl6XtVMqfedqEUS7ai7PS9ExM0BdSljz852rc319cltHdw9DcGZA0ks3hbZGa0h GgEw== 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=efVU9wQRFFod+ey1vTMyZ9KpeBOt+bqbxJAV+a9l+dk=; b=lUQNV624W6ERZEWNahOJ5k1Nv+BFJDpgWvm1W4KPXx4hOcXp97mA7iPKDx+gow1bnm EBZOl15tHEZ1ZyQ9PUmZpBwWTEjLA+41cQxPBEfhJIn5+52Y9b2K1aPm40QunrTGlVg0 Kykockbx5n6oXAToC/M6it+LBC6h39oPSWki4fk2pn9hTR60QbY7OwrbCpzBpgJRAlHg CKgDMKqcDNGRE3ggmGjhKVPAkMV9gX5wT6nyzAsmt/30OeTEWDY/OISNeq7teIsUE/Xm hTTZ9/qKtRUOXQN+1G3kyMDMzm8QPFyrULDYZYzbYGHLiBV/k2wfWxCmG5LCj3OlmOR0 VAWQ== X-Gm-Message-State: AD7BkJI0g2FHLqwMnz9fYlClCXqtXEMFWyRk19YdWopPG183YVyPrQrlAJy72RgOrLEHJg== X-Received: by 10.28.126.65 with SMTP id z62mr7945087wmc.42.1459699483568; Sun, 03 Apr 2016 09:04:43 -0700 (PDT) Received: from disaster-area.hh.sledj.net ([2a01:348:1a2:1:ea39:35ff:fe2c:a227]) by smtp.gmail.com with ESMTPSA id gk4sm24351438wjd.7.2016.04.03.09.04.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Apr 2016 09:04:42 -0700 (PDT) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id d5c60808 for ; Sun, 3 Apr 2016 16:04:38 +0000 (UTC) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH v3] emacs: Allow part preferences to depend on message content. Date: Sun, 3 Apr 2016 17:04:38 +0100 Message-Id: <1459699478-21167-2-git-send-email-dme@dme.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1459699478-21167-1-git-send-email-dme@dme.org> References: <1459699478-21167-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: Sun, 03 Apr 2016 16:04:53 -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-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