2012-04-24 17:11:56 +02:00
|
|
|
|
;;; mu4e-actions.el -- part of mu4e, the mu mail user agent
|
|
|
|
|
;;
|
2016-01-09 20:27:13 +01:00
|
|
|
|
;; Copyright (C) 2011-2016 Dirk-Jan C. Binnema
|
2012-04-24 17:11:56 +02:00
|
|
|
|
|
|
|
|
|
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
|
|
|
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
|
|
|
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
;;
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; Example actions for messages, attachments (see chapter 'Actions' in the
|
|
|
|
|
;; manual)
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
2012-06-10 15:14:21 +02:00
|
|
|
|
(eval-when-compile (byte-compile-disable-warning 'cl-functions))
|
2012-04-24 17:11:56 +02:00
|
|
|
|
(require 'cl)
|
2013-10-08 05:52:29 +02:00
|
|
|
|
(require 'ido)
|
2012-06-10 15:14:21 +02:00
|
|
|
|
|
2016-02-20 10:21:24 +01:00
|
|
|
|
(require 'mu4e-utils)
|
2012-09-26 16:28:30 +02:00
|
|
|
|
(require 'mu4e-message)
|
2012-04-24 17:11:56 +02:00
|
|
|
|
(require 'mu4e-meta)
|
|
|
|
|
|
2012-09-26 16:28:30 +02:00
|
|
|
|
|
2012-05-12 16:10:57 +02:00
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2012-04-24 17:11:56 +02:00
|
|
|
|
(defun mu4e-action-count-lines (msg)
|
2012-11-10 14:01:17 +01:00
|
|
|
|
"Count the number of lines in the e-mail message.
|
|
|
|
|
Works for headers view and message-view."
|
2012-04-24 17:11:56 +02:00
|
|
|
|
(message "Number of lines: %s"
|
|
|
|
|
(shell-command-to-string
|
2012-09-26 16:28:30 +02:00
|
|
|
|
(concat "wc -l < " (shell-quote-argument (mu4e-message-field msg :path))))))
|
2012-05-12 16:10:57 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2012-04-24 17:11:56 +02:00
|
|
|
|
|
|
|
|
|
|
2012-04-24 17:48:07 +02:00
|
|
|
|
|
2012-05-12 16:10:57 +02:00
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2017-01-30 20:05:04 +01:00
|
|
|
|
(defvar mu4e-msg2pdf
|
|
|
|
|
(let ((exec-path (cons (concat mu4e-builddir "/toys/msg2pdf/") exec-path)))
|
|
|
|
|
(locate-file "msg2pdf" exec-path exec-suffixes))
|
2012-04-24 17:11:56 +02:00
|
|
|
|
"Path to the msg2pdf toy.")
|
|
|
|
|
|
|
|
|
|
(defun mu4e-action-view-as-pdf (msg)
|
2012-11-10 14:01:17 +01:00
|
|
|
|
"Convert the message to pdf, then show it.
|
|
|
|
|
Works for the message view."
|
2012-04-24 17:11:56 +02:00
|
|
|
|
(unless (file-executable-p mu4e-msg2pdf)
|
2012-07-10 11:11:06 +02:00
|
|
|
|
(mu4e-error "msg2pdf not found; please set `mu4e-msg2pdf'"))
|
2012-04-24 17:11:56 +02:00
|
|
|
|
(let* ((pdf
|
2017-01-03 16:45:03 +01:00
|
|
|
|
(shell-command-to-string
|
|
|
|
|
(concat mu4e-msg2pdf " "
|
|
|
|
|
(shell-quote-argument (mu4e-message-field msg :path))
|
|
|
|
|
" 2> /dev/null")))
|
|
|
|
|
(pdf (and pdf (> (length pdf) 5)
|
|
|
|
|
(substring pdf 0 -1)))) ;; chop \n
|
2012-04-29 16:32:34 +02:00
|
|
|
|
(unless (and pdf (file-exists-p pdf))
|
2012-09-26 16:28:30 +02:00
|
|
|
|
(mu4e-warn "Failed to create PDF file"))
|
2012-04-24 17:11:56 +02:00
|
|
|
|
(find-file pdf)))
|
2012-05-12 16:10:57 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
2017-01-03 16:45:03 +01:00
|
|
|
|
|
2016-02-20 10:21:24 +01:00
|
|
|
|
(defun mu4e~write-body-to-html (msg)
|
|
|
|
|
"Write the body (either html or text) to a temporary file;
|
|
|
|
|
return the filename."
|
2012-09-26 16:28:30 +02:00
|
|
|
|
(let* ((html (mu4e-message-field msg :body-html))
|
2017-01-03 16:45:03 +01:00
|
|
|
|
(txt (mu4e-message-field msg :body-txt))
|
|
|
|
|
(tmpfile (mu4e-make-temp-file "html"))
|
|
|
|
|
(attachments (remove-if (lambda (part)
|
|
|
|
|
(or (null (plist-get part :attachment))
|
|
|
|
|
(null (plist-get part :cid))))
|
|
|
|
|
(mu4e-message-field msg :parts))))
|
2012-08-30 11:54:26 +02:00
|
|
|
|
(unless (or html txt)
|
|
|
|
|
(mu4e-error "No body part for this message"))
|
|
|
|
|
(with-temp-buffer
|
2016-01-31 11:48:12 +01:00
|
|
|
|
(insert "<head><meta charset=\"UTF-8\"></head>\n")
|
2012-08-30 11:54:26 +02:00
|
|
|
|
(insert (or html (concat "<pre>" txt "</pre>")))
|
2012-09-25 06:38:57 +02:00
|
|
|
|
(write-file tmpfile)
|
2016-04-16 17:13:47 +02:00
|
|
|
|
;; rewrite attachment urls
|
|
|
|
|
(mapc (lambda (attachment)
|
|
|
|
|
(goto-char (point-min))
|
2017-01-03 16:45:03 +01:00
|
|
|
|
(while (re-search-forward (format "src=\"cid:%s\""
|
|
|
|
|
(plist-get attachment :cid)) nil t)
|
2016-04-16 17:13:47 +02:00
|
|
|
|
(if (plist-get attachment :temp)
|
2017-01-03 16:45:03 +01:00
|
|
|
|
(replace-match (format "src=\"%s\"" (plist-get attachment :temp)))
|
|
|
|
|
(replace-match (format "src=\"%s%s\"" temporary-file-directory
|
|
|
|
|
(plist-get attachment :name)))
|
|
|
|
|
(let ((tmp-attachment-name (format "%s%s" temporary-file-directory
|
|
|
|
|
(plist-get attachment :name))))
|
|
|
|
|
(mu4e~proc-extract 'save (mu4e-message-field msg :docid)
|
|
|
|
|
(plist-get attachment :index)
|
|
|
|
|
mu4e-decryption-policy tmp-attachment-name)
|
2016-08-01 21:11:05 +02:00
|
|
|
|
(mu4e-remove-file-later tmp-attachment-name)))))
|
2017-01-03 16:45:03 +01:00
|
|
|
|
attachments)
|
2016-04-16 17:13:47 +02:00
|
|
|
|
(save-buffer)
|
2016-02-20 10:21:24 +01:00
|
|
|
|
tmpfile)))
|
2012-05-12 16:10:57 +02:00
|
|
|
|
|
2016-02-20 10:21:24 +01:00
|
|
|
|
(defun mu4e-action-view-in-browser (msg)
|
|
|
|
|
"View the body of the message in a browser.
|
|
|
|
|
You can influence the browser to use with the variable
|
2016-03-15 05:40:21 +01:00
|
|
|
|
`browse-url-generic-program', and see the discussion of privacy
|
|
|
|
|
aspects in `(mu4e) Displaying rich-text messages'."
|
2016-02-20 10:21:24 +01:00
|
|
|
|
(browse-url (concat "file://"
|
|
|
|
|
(mu4e~write-body-to-html msg))))
|
2012-04-24 17:11:56 +02:00
|
|
|
|
|
2016-01-24 11:32:09 +01:00
|
|
|
|
(defun mu4e-action-view-with-xwidget (msg)
|
2016-02-20 10:21:24 +01:00
|
|
|
|
"View the body of the message inside xwidget-webkit. This is
|
2016-03-15 05:40:21 +01:00
|
|
|
|
only available in emacs 25+; also see the discussion of privacy
|
|
|
|
|
aspects in `(mu4e) Displaying rich-text messages'."
|
2016-01-24 11:32:09 +01:00
|
|
|
|
(unless (fboundp 'xwidget-webkit-browse-url)
|
|
|
|
|
(mu4e-error "No xwidget support available"))
|
2016-02-20 10:21:24 +01:00
|
|
|
|
(xwidget-webkit-browse-url
|
|
|
|
|
(concat "file://" (mu4e~write-body-to-html msg)) t))
|
2016-01-24 11:32:09 +01:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-03 16:45:03 +01:00
|
|
|
|
|
2012-05-12 16:10:57 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2016-01-24 11:32:09 +01:00
|
|
|
|
(defconst mu4e-text2speech-command "festival --tts"
|
|
|
|
|
"Program that speaks out text it receives on standard-input.")
|
2012-04-24 17:11:56 +02:00
|
|
|
|
|
2012-05-12 16:10:57 +02:00
|
|
|
|
(defun mu4e-action-message-to-speech (msg)
|
|
|
|
|
"Pronounce the message text using `mu4e-text2speech-command'."
|
2012-09-26 16:28:30 +02:00
|
|
|
|
(unless (mu4e-message-field msg :body-txt)
|
|
|
|
|
(mu4e-warn "No text body for this message"))
|
2012-05-12 16:10:57 +02:00
|
|
|
|
(with-temp-buffer
|
2012-09-26 16:28:30 +02:00
|
|
|
|
(insert (mu4e-message-field msg :body-txt))
|
2012-05-12 16:10:57 +02:00
|
|
|
|
(shell-command-on-region (point-min) (point-max)
|
|
|
|
|
mu4e-text2speech-command)))
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2012-04-24 17:11:56 +02:00
|
|
|
|
|
2012-04-24 17:48:07 +02:00
|
|
|
|
|
|
|
|
|
|
2012-05-12 16:10:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2012-04-24 17:48:07 +02:00
|
|
|
|
(defvar mu4e-captured-message nil
|
|
|
|
|
"The last-captured message (the s-expression).")
|
|
|
|
|
|
2012-04-24 17:11:56 +02:00
|
|
|
|
(defun mu4e-action-capture-message (msg)
|
|
|
|
|
"Remember MSG; we can create a an attachment based on this msg
|
2012-04-24 17:48:07 +02:00
|
|
|
|
with `mu4e-compose-attach-captured-message'."
|
2012-04-24 17:11:56 +02:00
|
|
|
|
(setq mu4e-captured-message msg)
|
|
|
|
|
(message "Message has been captured"))
|
2012-05-12 16:10:57 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2012-04-24 17:11:56 +02:00
|
|
|
|
|
|
|
|
|
|
2012-05-12 16:10:57 +02:00
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2012-04-24 17:11:56 +02:00
|
|
|
|
(defvar mu4e-org-contacts-file nil
|
2012-11-10 14:01:17 +01:00
|
|
|
|
"File to store contact information for org-contacts.
|
|
|
|
|
Needed by `mu4e-action-add-org-contact'.")
|
2012-04-24 17:11:56 +02:00
|
|
|
|
|
|
|
|
|
(eval-when-compile ;; silence compiler warning about free variable
|
|
|
|
|
(unless (require 'org-capture nil 'noerror)
|
|
|
|
|
(defvar org-capture-templates nil)))
|
|
|
|
|
|
|
|
|
|
(defun mu4e-action-add-org-contact (msg)
|
|
|
|
|
"Add an org-contact entry based on the From: address of the
|
|
|
|
|
current message (in headers or view). You need to set
|
|
|
|
|
`mu4e-org-contacts-file' to the full path to the file where you
|
|
|
|
|
store your org-contacts."
|
2012-09-03 10:15:27 +02:00
|
|
|
|
(unless (require 'org-capture nil 'noerror)
|
2012-07-10 11:11:06 +02:00
|
|
|
|
(mu4e-error "org-capture is not available."))
|
2012-04-24 17:11:56 +02:00
|
|
|
|
(unless mu4e-org-contacts-file
|
2012-07-10 11:11:06 +02:00
|
|
|
|
(mu4e-error "`mu4e-org-contacts-file' is not defined."))
|
2012-09-26 16:28:30 +02:00
|
|
|
|
(let* ((sender (car-safe (mu4e-message-field msg :from)))
|
2012-04-24 17:11:56 +02:00
|
|
|
|
(name (car-safe sender)) (email (cdr-safe sender))
|
|
|
|
|
(blurb
|
|
|
|
|
(format
|
|
|
|
|
(concat
|
2015-05-20 16:44:41 +02:00
|
|
|
|
"* %%?%s\n"
|
2012-04-24 17:11:56 +02:00
|
|
|
|
":PROPERTIES:\n"
|
2015-05-20 16:44:41 +02:00
|
|
|
|
":EMAIL: %s\n"
|
2012-04-24 17:11:56 +02:00
|
|
|
|
":NICK:\n"
|
|
|
|
|
":BIRTHDAY:\n"
|
|
|
|
|
":END:\n\n")
|
|
|
|
|
(or name email "")
|
|
|
|
|
(or email "")))
|
|
|
|
|
(key "mu4e-add-org-contact-key")
|
|
|
|
|
(org-capture-templates
|
|
|
|
|
(append org-capture-templates
|
|
|
|
|
(list (list key "contacts" 'entry
|
|
|
|
|
(list 'file mu4e-org-contacts-file) blurb)))))
|
|
|
|
|
(message "%S" org-capture-templates)
|
2012-06-10 11:21:41 +02:00
|
|
|
|
(when (fboundp 'org-capture)
|
|
|
|
|
(org-capture nil key))))
|
2012-05-12 16:10:57 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
|
2012-10-29 11:26:17 +01:00
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
(defun mu4e-action-git-apply-patch (msg)
|
|
|
|
|
"Apply the git [patch] message."
|
2013-10-03 10:21:09 +02:00
|
|
|
|
(let ((path (ido-read-directory-name "Target directory: "
|
2017-01-03 16:45:03 +01:00
|
|
|
|
(car ido-work-directory-list)
|
|
|
|
|
"~/" t)))
|
2013-10-25 13:08:00 +02:00
|
|
|
|
(setf ido-work-directory-list
|
2017-01-03 16:45:03 +01:00
|
|
|
|
(cons path (delete path ido-work-directory-list)))
|
2012-10-29 11:26:17 +01:00
|
|
|
|
(shell-command
|
|
|
|
|
(format "cd %s; git apply %s"
|
|
|
|
|
path
|
|
|
|
|
(mu4e-message-field msg :path)))))
|
2013-10-25 13:09:26 +02:00
|
|
|
|
|
|
|
|
|
(defun mu4e-action-git-apply-mbox (msg)
|
2015-08-31 16:07:10 +02:00
|
|
|
|
"Apply and commit the git [patch] MSG.
|
|
|
|
|
|
|
|
|
|
If the `default-directory' matches the most recent history entry don't
|
|
|
|
|
bother asking for the git tree again (useful for bulk actions)."
|
|
|
|
|
|
|
|
|
|
(let ((cwd (car ido-work-directory-list)))
|
|
|
|
|
(unless (and (stringp cwd) (string= default-directory cwd))
|
|
|
|
|
(setq cwd (ido-read-directory-name "Target directory: "
|
2017-01-03 16:45:03 +01:00
|
|
|
|
cwd
|
|
|
|
|
"~/" t))
|
2015-08-31 16:07:10 +02:00
|
|
|
|
(setf ido-work-directory-list
|
2017-01-03 16:45:03 +01:00
|
|
|
|
(cons cwd (delete cwd ido-work-directory-list))))
|
2013-10-25 13:09:26 +02:00
|
|
|
|
(shell-command
|
|
|
|
|
(format "cd %s; git am %s"
|
2017-01-03 16:45:03 +01:00
|
|
|
|
(shell-quote-argument cwd)
|
|
|
|
|
(shell-quote-argument (mu4e-message-field msg :path))))))
|
2013-10-25 13:09:26 +02:00
|
|
|
|
|
2012-10-29 11:26:17 +01:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
2012-04-24 17:11:56 +02:00
|
|
|
|
|
2012-12-06 19:14:05 +01:00
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
(defvar mu4e-action-tags-header "X-Keywords"
|
2012-12-15 11:06:32 +01:00
|
|
|
|
"Header where tags are stored. Used by `mu4e-action-retag-message'.
|
|
|
|
|
Make sure it is one of the headers mu recognizes for storing
|
|
|
|
|
tags: X-Keywords, X-Label, Keywords. Also note that changing
|
|
|
|
|
this setting on already tagged messages can lead to messages
|
2013-03-17 10:58:08 +01:00
|
|
|
|
with multiple tags headers.")
|
2012-12-06 19:14:05 +01:00
|
|
|
|
|
2014-10-30 14:08:14 +01:00
|
|
|
|
(defvar mu4e-action-tags-completion-list '()
|
|
|
|
|
"List of tags to show for autocompletion in
|
|
|
|
|
`mu4e-action-retag-message'.")
|
|
|
|
|
|
2013-03-16 18:42:41 +01:00
|
|
|
|
(defun mu4e~contains-line-matching (regexp path)
|
2013-03-11 22:36:36 +01:00
|
|
|
|
"Determine whether the file at path contains a line matching
|
|
|
|
|
the given regexp."
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(insert-file-contents path)
|
2013-03-17 18:45:16 +01:00
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(if (re-search-forward regexp nil t)
|
|
|
|
|
t
|
|
|
|
|
nil))))
|
2013-03-11 22:36:36 +01:00
|
|
|
|
|
2013-03-16 18:42:41 +01:00
|
|
|
|
(defun mu4e~replace-first-line-matching (regexp to-string path)
|
2013-03-11 22:36:36 +01:00
|
|
|
|
"Replace the first line in the file at path that matches regexp
|
2013-03-17 10:58:08 +01:00
|
|
|
|
with the string replace."
|
2013-03-11 22:36:36 +01:00
|
|
|
|
(with-temp-file path
|
|
|
|
|
(insert-file-contents path)
|
2013-03-17 18:45:16 +01:00
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-min))
|
2013-03-17 10:58:08 +01:00
|
|
|
|
(if (re-search-forward regexp nil t)
|
|
|
|
|
(replace-match to-string nil nil)))))
|
2013-03-11 22:36:36 +01:00
|
|
|
|
|
2012-12-15 11:06:32 +01:00
|
|
|
|
(defun mu4e-action-retag-message (msg &optional retag-arg)
|
2014-10-30 14:08:14 +01:00
|
|
|
|
"Change tags of a message. Accepts a comma-separated list of
|
|
|
|
|
additions and removals.
|
|
|
|
|
|
|
|
|
|
Example: +tag,+long tag,-oldtag
|
|
|
|
|
|
|
|
|
|
would add 'tag' and 'long tag', and remove 'oldtag'."
|
|
|
|
|
(let* (
|
2017-01-03 16:45:03 +01:00
|
|
|
|
(path (mu4e-message-field msg :path))
|
2012-12-09 14:07:21 +01:00
|
|
|
|
(maildir (mu4e-message-field msg :maildir))
|
|
|
|
|
(oldtags (mu4e-message-field msg :tags))
|
2017-01-03 16:45:03 +01:00
|
|
|
|
(tags-completion
|
|
|
|
|
(append
|
|
|
|
|
mu4e-action-tags-completion-list
|
|
|
|
|
(mapcar (lambda (tag) (format "+%s" tag))
|
|
|
|
|
mu4e-action-tags-completion-list)
|
|
|
|
|
(mapcar (lambda (tag) (format "-%s" tag))
|
|
|
|
|
oldtags)))
|
|
|
|
|
(retag (if retag-arg
|
|
|
|
|
(split-string retag-arg ",")
|
|
|
|
|
(completing-read-multiple "Tags: " tags-completion)))
|
2012-12-09 14:07:21 +01:00
|
|
|
|
(header mu4e-action-tags-header)
|
2016-01-14 21:26:10 +01:00
|
|
|
|
(sep (cond ((string= header "Keywords") ", ")
|
2012-12-09 14:07:21 +01:00
|
|
|
|
((string= header "X-Label") " ")
|
|
|
|
|
((string= header "X-Keywords") ", ")
|
|
|
|
|
(t ", ")))
|
|
|
|
|
(taglist (if oldtags (copy-sequence oldtags) '()))
|
|
|
|
|
tagstr)
|
2014-10-30 14:08:14 +01:00
|
|
|
|
(dolist (tag retag taglist)
|
2013-03-16 16:58:17 +01:00
|
|
|
|
(cond
|
2013-03-17 10:27:42 +01:00
|
|
|
|
((string-match "^\\+\\(.+\\)" tag)
|
2013-03-16 16:58:17 +01:00
|
|
|
|
(setq taglist (push (match-string 1 tag) taglist)))
|
2013-03-17 10:27:42 +01:00
|
|
|
|
((string-match "^\\-\\(.+\\)" tag)
|
2012-12-09 14:07:21 +01:00
|
|
|
|
(setq taglist (delete (match-string 1 tag) taglist)))
|
|
|
|
|
(t
|
|
|
|
|
(setq taglist (push tag taglist)))))
|
2013-03-17 18:45:16 +01:00
|
|
|
|
|
2012-12-06 19:14:05 +01:00
|
|
|
|
(setq taglist (sort (delete-dups taglist) 'string<))
|
|
|
|
|
(setq tagstr (mapconcat 'identity taglist sep))
|
2013-03-17 18:45:16 +01:00
|
|
|
|
|
2013-03-11 22:36:36 +01:00
|
|
|
|
(setq tagstr (replace-regexp-in-string "[\\&]" "\\\\\\&" tagstr))
|
|
|
|
|
(setq tagstr (replace-regexp-in-string "[/]" "\\&" tagstr))
|
2013-03-17 18:45:16 +01:00
|
|
|
|
|
2013-03-16 18:42:41 +01:00
|
|
|
|
(if (not (mu4e~contains-line-matching (concat header ":.*") path))
|
2013-03-17 10:58:08 +01:00
|
|
|
|
;; Add tags header just before the content
|
|
|
|
|
(mu4e~replace-first-line-matching
|
|
|
|
|
"^$" (concat header ": " tagstr "\n") path)
|
2013-03-17 18:45:16 +01:00
|
|
|
|
|
2013-03-11 22:36:36 +01:00
|
|
|
|
;; replaces keywords, restricted to the header
|
2013-03-16 18:42:41 +01:00
|
|
|
|
(mu4e~replace-first-line-matching
|
2013-03-17 10:58:08 +01:00
|
|
|
|
(concat header ":.*")
|
|
|
|
|
(concat header ": " tagstr)
|
2017-01-03 16:45:03 +01:00
|
|
|
|
path))
|
2013-03-17 18:45:16 +01:00
|
|
|
|
|
2012-12-15 11:06:32 +01:00
|
|
|
|
(mu4e-message (concat "tagging: " (mapconcat 'identity taglist ", ")))
|
2012-12-09 14:07:21 +01:00
|
|
|
|
(mu4e-refresh-message path maildir)))
|
2015-11-07 06:36:31 +01:00
|
|
|
|
|
|
|
|
|
(defun mu4e-action-show-thread (msg)
|
|
|
|
|
"Show all messages that are in the same thread as the message
|
2016-05-19 19:05:29 +02:00
|
|
|
|
at point. Point remains on the message with the message-id where
|
|
|
|
|
the action was invoked. If invoked in view-mode, continue to
|
|
|
|
|
display the message."
|
2015-11-07 06:36:31 +01:00
|
|
|
|
(let ((msgid (mu4e-message-field msg :message-id)))
|
|
|
|
|
(when msgid
|
|
|
|
|
(let ((mu4e-headers-show-threads t)
|
|
|
|
|
(mu4e-headers-include-related t))
|
|
|
|
|
(mu4e-headers-search
|
2017-01-03 16:45:03 +01:00
|
|
|
|
(format "msgid:%s" msgid)
|
|
|
|
|
nil nil nil
|
|
|
|
|
msgid (eq major-mode 'mu4e-view-mode))))))
|
2012-12-06 19:14:05 +01:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
|
2012-04-24 17:11:56 +02:00
|
|
|
|
(provide 'mu4e-actions)
|