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 89648431FAE for ; Sat, 24 Jan 2015 13:17:22 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.138 X-Spam-Level: X-Spam-Status: No, score=0.138 tagged_above=-999 required=5 tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_MED=-2.3] 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 rynoQqTPLqnR for ; Sat, 24 Jan 2015 13:17:19 -0800 (PST) Received: from dmz-mailsec-scanner-2.mit.edu (dmz-mailsec-scanner-2.mit.edu [18.9.25.13]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 82735431FD4 for ; Sat, 24 Jan 2015 13:17:13 -0800 (PST) X-AuditID: 1209190d-f79006d000000cfe-3b-54c40bd60e82 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP id 5D.F2.03326.7DB04C45; Sat, 24 Jan 2015 16:17:11 -0500 (EST) Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id t0OLH9xU001792; Sat, 24 Jan 2015 16:17:09 -0500 Received: from drake (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 t0OLH63l007464 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Sat, 24 Jan 2015 16:17:07 -0500 Received: from amthrax by drake with local (Exim 4.84) (envelope-from ) id 1YF84n-0005Rr-NP; Sat, 24 Jan 2015 16:17:05 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v2 8/8] emacs: Support cid: references with shr renderer Date: Sat, 24 Jan 2015 16:17:03 -0500 Message-Id: <1422134223-20739-9-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1422134223-20739-1-git-send-email-amdragon@mit.edu> References: <1422134223-20739-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrFIsWRmVeSWpSXmKPExsUixCmqrHud+0iIwYmX7BY3WrsZLfbd2cJk sXouj8X1mzOZLd6snMfqwOqx6/lfJo+ds+6yexz+upDF49mqW8weWw69Zw5gjeKySUnNySxL LdK3S+DK+HPyGlvBefGKOa+OMDUwLhTuYuTkkBAwkfj0cxoThC0mceHeerYuRi4OIYHFTBK9 S+cyQjgbGSUuTl7BBOFcZJL4+uMBK4QziVHi28vFLCD9bAIaEr9vLQabJSIgLbHz7mxWEJtZ oE7i75zzjCC2sICHxIVT35hBbBYBVYnO+61gcV4BB4nW+duBejmA7pCT2LrOGyTMKeAocWPD LrDxQkAl3Z8b2SYw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiXl1qka6SXm1mil5pSuokRHISS vDsY3x1UOsQowMGoxMP749+hECHWxLLiytxDjJIcTEqivKt+HQ4R4kvKT6nMSCzOiC8qzUkt PsQowcGsJMJ7YQNQjjclsbIqtSgfJiXNwaIkzrvpB1+IkEB6YklqdmpqQWoRTFaGg0NJgncx 15EQIcGi1PTUirTMnBKENBMHJ8hwHqDh3SA1vMUFibnFmekQ+VOMilLivOtBEgIgiYzSPLhe WJJ4xSgO9Iowbz1IFQ8wwcB1vwIazAQ0uGD7AZDBJYkIKakGxi6W0Fdim78vqBXN3Zmd9Ltt kpfAio8TE5TVY/PnCITbvr/F+NjwQvUcscUMSj9FuPdETJXx2y/W800x+ZTdvRoH/9rren9F jPOm7LZ80XLOwf/G3c/dV1kKIuVm1rNJl6fUBy6tuSPyMPrgzsW9qk+vZyy50nt38v78qa8c nk//tP0656eyo0osxRmJhlrMRcWJAExwTiLtAgAA Cc: tomi.ollila@iki.fi 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: Sat, 24 Jan 2015 21:17:22 -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 | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 34dcedd..66350d4 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -767,14 +767,43 @@ (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)))) + +;; These functions are used by notmuch-show--insert-part-text/html-shr +(declare-function libxml-parse-html-region "xml.c") +(declare-function shr-insert-document "shr") + +(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. -- 2.1.3