* mu4e: some better escaping for queries with backslashes

This commit is contained in:
djcb
2012-11-02 09:26:12 +02:00
parent aaec71634e
commit 8dfcb2d909
2 changed files with 9 additions and 4 deletions

View File

@ -444,7 +444,7 @@ after the end of the search results."
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-S-u") 'mu4e-update-mail-and-index)
(define-key map "s" 'mu4e-headers-search)
(define-key map "S" 'mu4e-headers-search-edit)
@ -805,7 +805,6 @@ non-nill, don't raise an error when the docid is not found."
(unless ignore-missing
(mu4e-error "Cannot find message with docid %S" docid)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun mu4e~headers-search-execute (expr ignore-history)
"Search in the mu database for EXPR, and switch to the output
buffer for the results. If IGNORE-HISTORY is true, do *not* update
@ -829,7 +828,7 @@ the query history stack."
'face 'mu4e-title-face)))
(switch-to-buffer buf)
(mu4e~proc-find
(replace-regexp-in-string "\"" "\\\\\"" expr) ;; escape "\"
expr
mu4e-headers-show-threads
mu4e-headers-sortfield
mu4e-headers-sort-revert

View File

@ -312,6 +312,12 @@ The results are reporter through either (:update ... ) or (:error)
sexp, which are handled my `mu4e-error-func', respectively."
(mu4e~proc-send-command "remove docid:%d" docid))
(defun mu4e~proc-escape-query (query)
"Escape the query QUERY for transport, in particular, backslashes
and double-quotes."
(let ((esc (replace-regexp-in-string "\\\\" "\\\\\\\\" query)))
(replace-regexp-in-string "\"" "\\\\\"" esc)))
(defun mu4e~proc-find (query threads sortfield revert maxnum)
"Start a database query for QUERY. If THREADS is non-nil, show
results in threaded fasion, SORTFIELD is a symbol describing the
@ -323,7 +329,7 @@ result. The variables `mu4e-error-func' contain the function that
will be called for, resp., a message (header row) or an error."
(mu4e~proc-send-command
"find query:\"%s\" threads:%s sortfield:%s reverse:%s maxnum:%d"
query
(mu4e~proc-escape-query query)
(if threads "true" "false")
;; sortfield is e.g. ':subject'; this removes the ':'
(if (null sortfield) "nil" (substring (symbol-name sortfield) 1))