Merge pull request #110 from aroig/retag

* add support for retagging messages (use mu4e-actions)
This commit is contained in:
Dirk-Jan C. Binnema 2012-12-09 04:50:17 -08:00
commit cd138a17dc
3 changed files with 61 additions and 10 deletions

View File

@ -380,7 +380,6 @@ typedef struct _ServerContext ServerContext;
typedef MuError (*CmdFunc) (ServerContext*,GSList*,GError**);
/* 'add' adds a message to the database, and takes two parameters:
* 'path', which is the full path to the message, and 'maildir', which
* is the maildir this message lives in (e.g. "/inbox"). response with
@ -392,6 +391,8 @@ cmd_add (ServerContext *ctx, GSList *args, GError **err)
{
unsigned docid;
const char *maildir, *path;
MuMsg *msg;
gchar *sexp;
GET_STRING_OR_ERROR_RETURN (args, "path", &path, err);
GET_STRING_OR_ERROR_RETURN (args, "maildir", &maildir, err);
@ -403,6 +404,15 @@ cmd_add (ServerContext *ctx, GSList *args, GError **err)
gchar *escpath;
escpath = mu_str_escape_c_literal (path, TRUE);
print_expr ("(:info add :path %s :docid %u)", escpath, docid);
msg = mu_store_get_msg (ctx->store, docid, err);
if (msg) {
sexp = mu_msg_to_sexp (msg, docid, NULL, MU_MSG_OPTION_VERIFY);
print_expr ("(:update %s :move nil)", sexp);
mu_msg_unref(msg);
g_free (sexp);
}
g_free (escpath);
}

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)

View File

@ -228,19 +228,19 @@ marking if it still had that."
(if embedded
(local-set-key "q" 'kill-buffer-and-window)
(setq mu4e~view-buffer buf))
(setq mu4e~view-buffer buf)))
(unless (eq major-mode 'mu4e-view-mode)
(mu4e-view-mode))
(setq ;; buffer local
mu4e~view-msg msg
mu4e~view-headers-buffer headersbuf))
mu4e~view-msg msg
mu4e~view-headers-buffer headersbuf)
(unless (or refresh embedded)
(unless (or refresh embedded)
;; no use in trying to set flags again, or when it's an embedded
;; message
(mu4e~view-mark-as-read-maybe))
;; and switch!
(mu4e-view-mode))))
(mu4e~view-mark-as-read-maybe)))))
(defun mu4e~view-construct-header (field val &optional dont-propertize-val)