]> git.notmuchmail.org Git - notmuch/commitdiff
emacs: Sanitize authors and subjects in search and show
authorAustin Clements <amdragon@MIT.EDU>
Fri, 11 Oct 2013 13:53:39 +0000 (09:53 -0400)
committerDavid Bremner <bremner@debian.org>
Sun, 27 Oct 2013 12:31:29 +0000 (09:31 -0300)
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
emacs/notmuch-show.el
emacs/notmuch.el

index 58f3313d0bb92102bb1841fa3320ead9e68f36d7..65412821251dfa189e16e8f5274f3755bb4a9111 100644 (file)
@@ -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.
 
index 81ee87a8b8e8cd8b27d0eba312c8b5abe55065ba..9e8b9c09d699f706663e8a5a5ba818f9b1050520 100644 (file)
@@ -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."
@@ -1156,7 +1157,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))))
 
index 6081245560134446ea362b686b1dec17bafec481..d0cd9061ac338ff563f78059d1c8466765fe0ed3 100644 (file)
@@ -811,11 +811,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)))