From 01dffd59ac2025e110f1921db3a88445845e37fa Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Wed, 16 Oct 2013 22:00:08 +0300 Subject: [PATCH] [PATCH 1/6] emacs: Sanitize authors and subjects in search and show --- c7/0dfb1d5ac8810f0668c020a701865567762cdc | 152 ++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 c7/0dfb1d5ac8810f0668c020a701865567762cdc diff --git a/c7/0dfb1d5ac8810f0668c020a701865567762cdc b/c7/0dfb1d5ac8810f0668c020a701865567762cdc new file mode 100644 index 000000000..44d4462dd --- /dev/null +++ b/c7/0dfb1d5ac8810f0668c020a701865567762cdc @@ -0,0 +1,152 @@ +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 4881B431FBF + for ; Wed, 16 Oct 2013 12:00:25 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +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 V068ZgqOylfY for ; + Wed, 16 Oct 2013 12:00:19 -0700 (PDT) +Received: from mail-ee0-f52.google.com (mail-ee0-f52.google.com + [74.125.83.52]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + 768A6431FB6 for ; Wed, 16 Oct 2013 12:00:19 -0700 + (PDT) +Received: by mail-ee0-f52.google.com with SMTP id c41so585987eek.11 + for ; Wed, 16 Oct 2013 12:00:18 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references:in-reply-to:references; + bh=T53yQrOXHwZ4CKZLvq8kwsItjeBdoKIAWRNL8vQR/E4=; + b=RXH8dEL6w89EpAevLCAX4cyfHYhKmyawju5NPbrQpx6WkYth5/AeFUuChATje8Rip/ + dYGwj0IhIMs0aJUvyEkauMkvmq8l30DmYtMoHZANRuYPJrh6oqWLh+JFYHzkEzeHJ4Nq + M8N8cCKjatSwY+dlVFisv8tGfbS7huHtcOP+RudVNMDBXoGrbFmnzeU0LkUrVi0KfrJW + tVAP3DoYMr21oz/BqLfp5mOMT3idRQ0l+Ay94LHq7CARNOnCLf4V2URf+lYvcvl6j6mh + DgX0F3JhYqIWgjI060FkqNyAljU5vIcnbdf7RpcQiMln/dpKIoJwZa8tGZqTS76gbfyr + Uewg== +X-Gm-Message-State: + ALoCoQm2Zzi1QUoXVCQRrCO2GsikqoWk+0it3yB80zRoCoFDILzOZTefIr1MkvG2e7zZWkLm/bQU +X-Received: by 10.15.61.73 with SMTP id h49mr6822542eex.57.1381950018350; + Wed, 16 Oct 2013 12:00:18 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. + [88.195.111.91]) + by mx.google.com with ESMTPSA id 48sm21233018eeq.4.1969.12.31.16.00.00 + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Wed, 16 Oct 2013 12:00:17 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH 1/6] emacs: Sanitize authors and subjects in search and show +Date: Wed, 16 Oct 2013 22:00:08 +0300 +Message-Id: + <8a1cf0f31f31b7f7be8a7458a5cbf0cc3ead6ac0.1381948853.git.jani@nikula.org> +X-Mailer: git-send-email 1.8.4.rc3 +In-Reply-To: +References: +In-Reply-To: +References: +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: Wed, 16 Oct 2013 19:00:25 -0000 + +From: Austin Clements + +Authors and subjects can contain embedded, encoded control characters +like "\n" and "\t" that mess up display. Transform control characters +into spaces everywhere we display them in search and show. +--- + emacs/notmuch-lib.el | 6 ++++++ + emacs/notmuch-show.el | 7 ++++--- + emacs/notmuch.el | 6 ++++-- + 3 files changed, 14 insertions(+), 5 deletions(-) + +diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el +index 58f3313..6541282 100644 +--- a/emacs/notmuch-lib.el ++++ b/emacs/notmuch-lib.el +@@ -243,6 +243,12 @@ depending on the value of `notmuch-poll-script'." + "[No Subject]" + subject))) + ++(defun notmuch-sanitize (str) ++ "Sanitize control character in STR. ++ ++This includes newlines, tabs, and other funny characters." ++ (replace-regexp-in-string "[[:cntrl:]\x7f\u2028\u2029]+" " " str)) ++ + (defun notmuch-escape-boolean-term (term) + "Escape a boolean term for use in a query. + +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index 7325792..fa11d98 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -407,7 +407,8 @@ unchanged ADDRESS if parsing fails." + message at DEPTH in the current thread." + (let ((start (point))) + (insert (notmuch-show-spaces-n (* notmuch-show-indent-messages-width depth)) +- (notmuch-show-clean-address (plist-get headers :From)) ++ (notmuch-sanitize ++ (notmuch-show-clean-address (plist-get headers :From))) + " (" + date + ") (" +@@ -417,7 +418,7 @@ message at DEPTH in the current thread." + + (defun notmuch-show-insert-header (header header-value) + "Insert a single header." +- (insert header ": " header-value "\n")) ++ (insert header ": " (notmuch-sanitize header-value) "\n")) + + (defun notmuch-show-insert-headers (headers) + "Insert the headers of the current message." +@@ -1154,7 +1155,7 @@ function is used." + (jit-lock-register #'notmuch-show-buttonise-links) + + ;; Set the header line to the subject of the first message. +- (setq header-line-format (notmuch-show-strip-re (notmuch-show-get-subject))) ++ (setq header-line-format (notmuch-sanitize (notmuch-show-strip-re (notmuch-show-get-subject)))) + + (run-hooks 'notmuch-show-hook)))) + +diff --git a/emacs/notmuch.el b/emacs/notmuch.el +index c47c6b5..44cd2fd 100644 +--- a/emacs/notmuch.el ++++ b/emacs/notmuch.el +@@ -791,11 +791,13 @@ non-authors is found, assume that all of the authors match." + (plist-get result :total))) + 'face 'notmuch-search-count))) + ((string-equal field "subject") +- (insert (propertize (format format-string (plist-get result :subject)) ++ (insert (propertize (format format-string ++ (notmuch-sanitize (plist-get result :subject))) + 'face 'notmuch-search-subject))) + + ((string-equal field "authors") +- (notmuch-search-insert-authors format-string (plist-get result :authors))) ++ (notmuch-search-insert-authors ++ format-string (notmuch-sanitize (plist-get result :authors)))) + + ((string-equal field "tags") + (let ((tags (plist-get result :tags))) +-- +1.8.4.rc3 + -- 2.26.2