Adds an action to change tags header

New action mu4e-action-retag-message that reads tag changes from the user and
modifies the corresponding header (X-Keywords, X-Label, etc) on the message.
This commit is contained in:
Abdó Roig-Maranges 2012-12-06 19:14:05 +01:00
parent dc5786792e
commit fb2f5d6a53
1 changed files with 42 additions and 1 deletions

View File

@ -172,7 +172,7 @@ store your org-contacts."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun mu4e-action-git-apply-patch (msg)
"Apply the git [patch] message."
(let ((path (read-directory-name "Target directory: " nil "~/" t) ))
(let ((path (read-directory-name "Target directory: " nil "~/" t) ))
(shell-command
(format "cd %s; git apply %s"
path
@ -180,4 +180,45 @@ store your org-contacts."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar mu4e-action-tags-header "X-Keywords"
"Header where tags are stored.")
(defun mu4e-action-retag-message (msg)
"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)
(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)))))
(setq taglist (sort (delete-dups taglist) 'string<))
(setq tagstr (mapconcat 'identity taglist sep))
(setq tagstr (replace-regexp-in-string "[\\/&]" "\\\\\\&" tagstr))
;; 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)
(message (concat "tagging: " (mapconcat 'identity taglist " ")))
(mu4e~proc-add path maildir)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(provide 'mu4e-actions)