diff options
author | Austin Clements <amdragon@MIT.EDU> | 2013-10-11 09:53:39 -0400 |
---|---|---|
committer | David Bremner <bremner@debian.org> | 2013-10-27 09:31:29 -0300 |
commit | a7964c86d12558396cda0f297ebf8dcc602bab61 (patch) | |
tree | 78ecab23c0e1c44f6b24162c9abf74788876c8a8 /emacs | |
parent | 45444eebe5c618d08ab168c49201bcd3cc235506 (diff) |
emacs: Sanitize authors and subjects in search and show
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.
Diffstat (limited to 'emacs')
-rw-r--r-- | emacs/notmuch-lib.el | 6 | ||||
-rw-r--r-- | emacs/notmuch-show.el | 7 | ||||
-rw-r--r-- | emacs/notmuch.el | 6 |
3 files changed, 14 insertions, 5 deletions
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 58f3313d..65412821 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 81ee87a8..9e8b9c09 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." @@ -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)))) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 60812455..d0cd9061 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -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))) |