* small cleanup of the retagging support

This commit is contained in:
djcb 2012-12-09 15:07:21 +02:00
parent cd138a17dc
commit 0e204fece4
4 changed files with 37 additions and 29 deletions

View File

@ -407,7 +407,8 @@ cmd_add (ServerContext *ctx, GSList *args, GError **err)
msg = mu_store_get_msg (ctx->store, docid, err);
if (msg) {
sexp = mu_msg_to_sexp (msg, docid, NULL, MU_MSG_OPTION_VERIFY);
sexp = mu_msg_to_sexp (msg, docid, NULL,
MU_MSG_OPTION_VERIFY);
print_expr ("(:update %s :move nil)", sexp);
mu_msg_unref(msg);

View File

@ -189,24 +189,24 @@ store your org-contacts."
"Change tags of a message. Example: +tag \"+long tag\" -oldtag
adds 'tag' and 'long tag', and removes oldtag."
(let* ((retag (read-string "Tags: "))
(path (mu4e-message-field msg :path))
(maildir (mu4e-message-field msg :maildir))
(oldtags (mu4e-message-field msg :tags))
(header mu4e-action-tags-header)
(sep (cond ((string= header "Keywords") " ")
((string= header "X-Label") " ")
((string= header "X-Keywords") ", ")
(t ", ")))
(taglist (if oldtags (copy-sequence oldtags) '()))
tagstr)
(path (mu4e-message-field msg :path))
(maildir (mu4e-message-field msg :maildir))
(oldtags (mu4e-message-field msg :tags))
(header mu4e-action-tags-header)
(sep (cond ((string= header "Keywords") " ")
((string= header "X-Label") " ")
((string= header "X-Keywords") ", ")
(t ", ")))
(taglist (if oldtags (copy-sequence oldtags) '()))
tagstr)
(dolist (tag (split-string-and-unquote retag) taglist)
(cond ((string-match "\\+\\(.+\\)" tag)
(setq taglist (push (match-string 1 tag) taglist)))
((string-match "\\-\\(.+\\)" tag)
(setq taglist (delete (match-string 1 tag) taglist)))
(t
(setq taglist (push tag taglist)))))
(cond ((string-match "\\+\\(.+\\)" tag)
(setq taglist (push (match-string 1 tag) taglist)))
((string-match "\\-\\(.+\\)" tag)
(setq taglist (delete (match-string 1 tag) taglist)))
(t
(setq taglist (push tag taglist)))))
(setq taglist (sort (delete-dups taglist) 'string<))
(setq tagstr (mapconcat 'identity taglist sep))
@ -214,10 +214,10 @@ store your org-contacts."
;; replaces keywords with sed, restricted to the header
(call-process "sed" nil nil nil "-ine"
(format "1,/^$/s/^%s:.*$/%s: %s/" header header tagstr) path)
(format "1,/^$/s/^%s:.*$/%s: %s/" header header tagstr) path)
(message (concat "tagging: " (mapconcat 'identity taglist " ")))
(mu4e~proc-add path maildir)))
(mu4e-message (concat "tagging: " (mapconcat 'identity taglist " ")))
(mu4e-refresh-message path maildir)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -334,7 +334,7 @@ will be called for, resp., a message (header row) or an error."
;; sortfield is e.g. ':subject'; this removes the ':'
(if (null sortfield) "nil" (substring (symbol-name sortfield) 1))
;; TODO: use ascending/descending in backend too (it's clearer than 'reverse'
(if (eq sortdir 'descending) "true" "false")
(if (eq sortdir 'descending) "true" "false")
(if maxnum maxnum -1)))
(defun mu4e~proc-move (docid-or-msgid &optional maildir flags)
@ -397,7 +397,7 @@ of 'my' email addresses (see `mu4e-user-mail-address-list')."
"Add the message at PATH to the database.
With MAILDIR set to the maildir this message resides in,
e.g. '/drafts'; if this works, we will receive (:info add :path
<path> :docid <docid>)."
<path> :docid <docid>) as well as (:update <msg-sexp>)."
(mu4e~proc-send-command "add path:\"%s\" maildir:\"%s\""
path maildir))

View File

@ -169,14 +169,16 @@ debuggable (backtrace) error."
(mu4e-log 'error (apply 'mu4e-format frm args))
(error "%s" (apply 'mu4e-format frm args)))
;; the user-error function is only available in emacs-trunk
(unless (fboundp 'user-error)
(defalias 'user-error 'error))
(defun mu4e-warn (frm &rest args)
"Create [mu4e]-prefixed warning based on format FRM and ARGS.
Does a local-exit and does not return. In emacs versions below
24.2, the functions is the same as `mu4e-error'."
(mu4e-log 'error (apply 'mu4e-format frm args))
(if (fboundp 'user-error)
(user-error "%s" (apply 'mu4e-format frm args)) ;; only in emacs-trunk
(error "%s" (apply 'mu4e-format frm args))))
(user-error "%s" (apply 'mu4e-format frm args)))
(defun mu4e~read-char-choice (prompt choices)
"Compatiblity wrapper for `read-char-choice'.
@ -218,7 +220,7 @@ Function will return the cdr of the list element."
;; try to detect old-style options, and warn
(when (characterp (car-safe (cdr-safe option)))
(mu4e-error (concat "Please use the new format for options/actions; "
"see the manual")))
"see the manual")))
(let* ((kar (substring (car option) 0 1))
(val (cdr option)))
(concat
@ -628,7 +630,7 @@ successful, call FUNC (if non-nil) afterwards."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; getting mail / updating the index
;; getting mail / updating the index
;;
;;
(defvar mu4e~update-timer nil
@ -694,7 +696,7 @@ window."
(switch-to-buffer buf)
(set-window-dedicated-p win t)
(erase-buffer)
(insert "\n"))) ;; FIXME -- needed so output starts
(insert "\n"))) ;; FIXME -- needed so output starts
(set-process-sentinel proc
(lambda (proc msg)
(let* ((status (process-status proc))
@ -714,7 +716,7 @@ window."
(process-put proc 'x-interactive (not run-in-background))
(set-process-filter proc 'mu4e~get-mail-process-filter))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -889,6 +891,11 @@ displaying it). Do _not_ bury the current buffer, though."
(goto-char (point-min)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun mu4e-refresh-message (path maildir)
"Re-parse message at PATH and MAILDIR; if this works, we will
receive (:info add :path <path> :docid <docid>) as well as (:update
<msg-sexp>)."
(mu4e~proc-add path maildir))
(provide 'mu4e-utils)
;;; End of mu4e-utils.el