Re: [PATCH WIP] emacs: Sanitize authors and subjects in search and show
authorTomi Ollila <tomi.ollila@iki.fi>
Sun, 20 Oct 2013 17:49:20 +0000 (20:49 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:57:30 +0000 (09:57 -0800)
8b/4c4fbed5b34657b485ee9dbb73c446d5644f12 [new file with mode: 0644]

diff --git a/8b/4c4fbed5b34657b485ee9dbb73c446d5644f12 b/8b/4c4fbed5b34657b485ee9dbb73c446d5644f12
new file mode 100644 (file)
index 0000000..85a400e
--- /dev/null
@@ -0,0 +1,152 @@
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 0BC15431FC2\r
+       for <notmuch@notmuchmail.org>; Sun, 20 Oct 2013 10:49:35 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id fvs0wwYE6ELi for <notmuch@notmuchmail.org>;\r
+       Sun, 20 Oct 2013 10:49:27 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 95738431FC0\r
+       for <notmuch@notmuchmail.org>; Sun, 20 Oct 2013 10:49:26 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+       by guru.guru-group.fi (Postfix) with ESMTP id A7C2710007D;\r
+       Sun, 20 Oct 2013 20:49:20 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH WIP] emacs: Sanitize authors and subjects in search and\r
+       show\r
+In-Reply-To: <1381499619-14219-1-git-send-email-amdragon@mit.edu>\r
+References: <1381499619-14219-1-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.16+112~g46b74be (http://notmuchmail.org) Emacs/24.3.1\r
+       (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Sun, 20 Oct 2013 20:49:20 +0300\r
+Message-ID: <m2ppqzq1cv.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 20 Oct 2013 17:49:35 -0000\r
+\r
+On Fri, Oct 11 2013, Austin Clements <amdragon@MIT.EDU> wrote:\r
+\r
+> Authors and subjects can contain embedded, encoded control characters\r
+> like "\n" and "\t" that mess up display.  Transform control characters\r
+> into spaces everywhere we display them in search and show.\r
+> ---\r
+\r
+LGTM.\r
+\r
+Tomi\r
+\r
+\r
+>\r
+> This could obviously use some tests, but I thought I'd get it out\r
+> there to see what people thought or if the behavior should be tweaked.\r
+>\r
+> Of course, I can't guarantee that this is all of the places we display\r
+> untrusted header text.  I'm really not sure how to make that guarantee\r
+> (suggestions welcome).\r
+>\r
+>  emacs/notmuch-lib.el  | 6 ++++++\r
+>  emacs/notmuch-show.el | 7 ++++---\r
+>  emacs/notmuch.el      | 6 ++++--\r
+>  3 files changed, 14 insertions(+), 5 deletions(-)\r
+>\r
+> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+> index 58f3313..6541282 100644\r
+> --- a/emacs/notmuch-lib.el\r
+> +++ b/emacs/notmuch-lib.el\r
+> @@ -243,6 +243,12 @@ depending on the value of `notmuch-poll-script'."\r
+>      "[No Subject]"\r
+>        subject)))\r
+>  \r
+> +(defun notmuch-sanitize (str)\r
+> +  "Sanitize control character in STR.\r
+> +\r
+> +This includes newlines, tabs, and other funny characters."\r
+> +  (replace-regexp-in-string "[[:cntrl:]\x7f\u2028\u2029]+" " " str))\r
+> +\r
+>  (defun notmuch-escape-boolean-term (term)\r
+>    "Escape a boolean term for use in a query.\r
+>  \r
+> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+> index 7325792..fa11d98 100644\r
+> --- a/emacs/notmuch-show.el\r
+> +++ b/emacs/notmuch-show.el\r
+> @@ -407,7 +407,8 @@ unchanged ADDRESS if parsing fails."\r
+>  message at DEPTH in the current thread."\r
+>    (let ((start (point)))\r
+>      (insert (notmuch-show-spaces-n (* notmuch-show-indent-messages-width depth))\r
+> -        (notmuch-show-clean-address (plist-get headers :From))\r
+> +        (notmuch-sanitize\r
+> +         (notmuch-show-clean-address (plist-get headers :From)))\r
+>          " ("\r
+>          date\r
+>          ") ("\r
+> @@ -417,7 +418,7 @@ message at DEPTH in the current thread."\r
+>  \r
+>  (defun notmuch-show-insert-header (header header-value)\r
+>    "Insert a single header."\r
+> -  (insert header ": " header-value "\n"))\r
+> +  (insert header ": " (notmuch-sanitize header-value) "\n"))\r
+>  \r
+>  (defun notmuch-show-insert-headers (headers)\r
+>    "Insert the headers of the current message."\r
+> @@ -1154,7 +1155,7 @@ function is used."\r
+>        (jit-lock-register #'notmuch-show-buttonise-links)\r
+>  \r
+>        ;; Set the header line to the subject of the first message.\r
+> -      (setq header-line-format (notmuch-show-strip-re (notmuch-show-get-subject)))\r
+> +      (setq header-line-format (notmuch-sanitize (notmuch-show-strip-re (notmuch-show-get-subject))))\r
+>  \r
+>        (run-hooks 'notmuch-show-hook))))\r
+>  \r
+> diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> index c47c6b5..44cd2fd 100644\r
+> --- a/emacs/notmuch.el\r
+> +++ b/emacs/notmuch.el\r
+> @@ -791,11 +791,13 @@ non-authors is found, assume that all of the authors match."\r
+>                                      (plist-get result :total)))\r
+>                      'face 'notmuch-search-count)))\r
+>     ((string-equal field "subject")\r
+> -    (insert (propertize (format format-string (plist-get result :subject))\r
+> +    (insert (propertize (format format-string\r
+> +                            (notmuch-sanitize (plist-get result :subject)))\r
+>                      'face 'notmuch-search-subject)))\r
+>  \r
+>     ((string-equal field "authors")\r
+> -    (notmuch-search-insert-authors format-string (plist-get result :authors)))\r
+> +    (notmuch-search-insert-authors\r
+> +     format-string (notmuch-sanitize (plist-get result :authors))))\r
+>  \r
+>     ((string-equal field "tags")\r
+>      (let ((tags (plist-get result :tags)))\r
+> -- \r
+> 1.8.4.rc3\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r