Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 9290F431E64 for ; Mon, 21 Apr 2014 11:38:22 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OCDgO+ODL92l for ; Mon, 21 Apr 2014 11:38:17 -0700 (PDT) Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu [18.7.68.37]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id EB895431FC9 for ; Mon, 21 Apr 2014 11:38:03 -0700 (PDT) X-AuditID: 12074425-f79906d000000cf9-27-5355658a88d8 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) (using TLS with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id D9.F3.03321.A8565535; Mon, 21 Apr 2014 14:38:02 -0400 (EDT) Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s3LIc18g018353; Mon, 21 Apr 2014 14:38:01 -0400 Received: from drake.dyndns.org (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [216.15.114.40]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s3LIbshb029728 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Mon, 21 Apr 2014 14:38:00 -0400 Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1WcJ6I-0003lL-I6; Mon, 21 Apr 2014 14:37:54 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 11/11] emacs: Support cid: references with shr renderer Date: Mon, 21 Apr 2014 14:37:48 -0400 Message-Id: <1398105468-14317-12-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1398105468-14317-1-git-send-email-amdragon@mit.edu> References: <1398105468-14317-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrMIsWRmVeSWpSXmKPExsUixCmqrduVGhpssLrByuL6zZnMDowez1bd Yg5gjOKySUnNySxLLdK3S+DKeHD9KGPBDLGKzrd/mBsY/wh2MXJySAiYSOxoPMICYYtJXLi3 nq2LkYtDSGA2k8Syn/OZIZyNjBJfXh1jhXDuMEk8XLecBcKZyyjxas8GRpB+NgENiW37l4PZ IgLSEjvvzgbq4OBgFlCT+NOlAhIWFnCXaLm0hRnEZhFQlTh8+TgTiM0r4CixZ/ZUNogz5CRO HpvMCmJzAsXbVr9kB7GFBBwkNuxdwzSBkX8BI8MqRtmU3Crd3MTMnOLUZN3i5MS8vNQiXQu9 3MwSvdSU0k2MoLBhd1HdwTjhkNIhRgEORiUe3gKj0GAh1sSy4srcQ4ySHExKoryvooBCfEn5 KZUZicUZ8UWlOanFhxglOJiVRHjXawLleFMSK6tSi/JhUtIcLErivG+trYKFBNITS1KzU1ML UotgsjIcHEoSvGkpQI2CRanpqRVpmTklCGkmDk6Q4TxAw6NAaniLCxJzizPTIfKnGBWlxHnb QBICIImM0jy4Xlhcv2IUB3pFmNcdpIoHmBLgul8BDWYCGvxkSwjI4JJEhJRUA+M8CwVHhy+N +fMmLPM+LsjKneiu++qLeZiCUlHbJ7+nbKXrDKRe9OWUCmQzruLYGB+0m1Eu2Smv6vrBwuvq CvzTTnQcWfqieZnkrX3OMt5FWmG1365Vu7RamLqYy0w8m7GkaI1vwMlPmyKkviVmqB6Weyx/ rSyjqe7Igildx7f+Y1ucHPu9WYmlOCPRUIu5qDgRACHRn1/GAgAA X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Mon, 21 Apr 2014 18:38:23 -0000 shr has really nice support for inline image rendering, but previously we only had the hooks for w3m cid: references. --- emacs/notmuch-show.el | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index f758091..a489279 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -745,14 +745,39 @@ (defun notmuch-show-get-mime-type-of-application/octet-stream (part) nil)))) (defun notmuch-show-insert-part-text/html (msg part content-type nth depth button) - ;; text/html handler to work around bugs in renderers and our - ;; invisibile parts code. In particular w3m sets up a keymap which - ;; "leaks" outside the invisible region and causes strange effects - ;; in notmuch. We set mm-inline-text-html-with-w3m-keymap to nil to - ;; tell w3m not to set a keymap (so the normal notmuch-show-mode-map - ;; remains). - (let ((mm-inline-text-html-with-w3m-keymap nil)) - (notmuch-show-insert-part-*/* msg part content-type nth depth button))) + (if (eq mm-text-html-renderer 'shr) + ;; It's easier to drive shr ourselves than to work around the + ;; goofy things `mm-shr' does (like irreversibly taking over + ;; content ID handling). + (notmuch-show--insert-part-text/html-shr msg part) + ;; Otherwise, let message-mode do the heavy lifting + ;; + ;; w3m sets up a keymap which "leaks" outside the invisible region + ;; and causes strange effects in notmuch. We set + ;; mm-inline-text-html-with-w3m-keymap to nil to tell w3m not to + ;; set a keymap (so the normal notmuch-show-mode-map remains). + (let ((mm-inline-text-html-with-w3m-keymap nil)) + (notmuch-show-insert-part-*/* msg part content-type nth depth button)))) + +(defun notmuch-show--insert-part-text/html-shr (msg part) + ;; Make sure shr is loaded before we start let-binding its globals + (require 'shr) + (let ((dom (let (process-crypto notmuch-show-process-crypto) + (with-temp-buffer + (insert (notmuch-get-bodypart-text msg part process-crypto)) + (libxml-parse-html-region (point-min) (point-max))))) + (shr-content-function + (lambda (url) + ;; shr strips the "cid:" part of URL, but doesn't + ;; URL-decode it (see RFC 2392). + (let ((cid (url-unhex-string url))) + (first (notmuch-show--get-cid-content cid))))) + ;; Block all external images to prevent privacy leaks and + ;; potential attacks. FIXME: If we block an image, offer a + ;; button to load external images. + (shr-blocked-images ".")) + (shr-insert-document dom) + t)) (defun notmuch-show-insert-part-*/* (msg part content-type nth depth button) ;; This handler _must_ succeed - it is the handler of last resort. -- 1.9.1