2023-09-20 21:31:19 +02:00
|
|
|
|
;;; mu4e-contrib.el --- User-contributed functions -*- lexical-binding: t -*-
|
2020-02-11 12:23:40 +01:00
|
|
|
|
|
2023-09-20 21:31:19 +02:00
|
|
|
|
;; Copyright (C) 2013-2023 Dirk-Jan C. Binnema
|
2013-04-29 22:52:17 +02:00
|
|
|
|
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
2020-02-11 12:23:40 +01:00
|
|
|
|
|
2021-05-29 23:36:13 +02:00
|
|
|
|
;; mu4e is free software: you can redistribute it and/or modify
|
2013-04-29 22:52:17 +02:00
|
|
|
|
;; 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.
|
|
|
|
|
|
2021-05-29 23:36:13 +02:00
|
|
|
|
;; mu4e is distributed in the hope that it will be useful,
|
2013-04-29 22:52:17 +02:00
|
|
|
|
;; 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
|
2021-05-29 23:36:13 +02:00
|
|
|
|
;; along with mu4e. If not, see <http://www.gnu.org/licenses/>.
|
2013-04-29 22:52:17 +02:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; Some user-contributed functions for mu4e
|
2020-02-11 12:32:47 +01:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2020-02-06 19:28:24 +01:00
|
|
|
|
(require 'mu4e-headers)
|
|
|
|
|
(require 'mu4e-view)
|
|
|
|
|
(require 'bookmark)
|
|
|
|
|
(require 'eshell)
|
2013-06-03 20:09:20 +02:00
|
|
|
|
|
2022-05-29 11:28:42 +02:00
|
|
|
|
|
2020-02-11 15:10:35 +01:00
|
|
|
|
;;; Various simple commands
|
2013-04-29 22:52:17 +02:00
|
|
|
|
(defun mu4e-headers-mark-all-unread-read ()
|
2013-04-29 22:52:55 +02:00
|
|
|
|
"Put a ! \(read) mark on all visible unread messages."
|
2013-04-29 22:52:17 +02:00
|
|
|
|
(interactive)
|
|
|
|
|
(mu4e-headers-mark-for-each-if
|
|
|
|
|
(cons 'read nil)
|
2019-09-16 19:54:59 +02:00
|
|
|
|
(lambda (msg _param)
|
2013-04-29 22:52:17 +02:00
|
|
|
|
(memq 'unread (mu4e-msg-field msg :flags)))))
|
|
|
|
|
|
|
|
|
|
(defun mu4e-headers-flag-all-read ()
|
2013-04-29 22:52:55 +02:00
|
|
|
|
"Flag all visible messages as \"read\"."
|
2013-04-29 22:52:17 +02:00
|
|
|
|
(interactive)
|
|
|
|
|
(mu4e-headers-mark-all-unread-read)
|
|
|
|
|
(mu4e-mark-execute-all t))
|
|
|
|
|
|
2015-11-17 05:06:41 +01:00
|
|
|
|
(defun mu4e-headers-mark-all ()
|
2022-05-29 11:28:42 +02:00
|
|
|
|
"Mark all headers for some action.
|
2021-08-30 21:02:49 +02:00
|
|
|
|
Ask user what action to execute."
|
2015-11-17 05:06:41 +01:00
|
|
|
|
(interactive)
|
|
|
|
|
(mu4e-headers-mark-for-each-if
|
|
|
|
|
(cons 'something nil)
|
2019-09-16 19:54:59 +02:00
|
|
|
|
(lambda (_msg _param) t))
|
2015-11-17 05:06:41 +01:00
|
|
|
|
(mu4e-mark-execute-all))
|
|
|
|
|
|
2013-04-29 22:52:17 +02:00
|
|
|
|
|
2022-05-29 11:28:42 +02:00
|
|
|
|
|
2020-02-11 15:10:35 +01:00
|
|
|
|
;;; Bogofilter/SpamAssassin
|
|
|
|
|
;;
|
|
|
|
|
;; Support for handling spam with Bogofilter with the possibility
|
|
|
|
|
;; to define it for SpamAssassin, contributed by Gour.
|
|
|
|
|
;;
|
|
|
|
|
;; To add the actions to the menu, you can use something like:
|
|
|
|
|
;;
|
2015-05-25 08:28:56 +02:00
|
|
|
|
;; (add-to-list 'mu4e-headers-actions
|
|
|
|
|
;; '("sMark as spam" . mu4e-register-msg-as-spam) t)
|
|
|
|
|
;; (add-to-list 'mu4e-headers-actions
|
|
|
|
|
;; '("hMark as ham" . mu4e-register-msg-as-ham) t)
|
|
|
|
|
|
|
|
|
|
(defvar mu4e-register-as-spam-cmd nil
|
2021-08-30 21:02:49 +02:00
|
|
|
|
"Command for invoking spam processor to register message as spam.
|
|
|
|
|
For example for bogofilter, use \"/usr/bin/bogofilter -Ns < %s\"")
|
2015-05-25 08:28:56 +02:00
|
|
|
|
|
|
|
|
|
(defvar mu4e-register-as-ham-cmd nil
|
|
|
|
|
"Command for invoking spam processor to register message as ham.
|
|
|
|
|
For example for bogofile, use \"/usr/bin/bogofilter -Sn < %s\"")
|
|
|
|
|
|
|
|
|
|
(defun mu4e-register-msg-as-spam (msg)
|
2021-08-30 21:02:49 +02:00
|
|
|
|
"Register MSG as spam."
|
2015-05-25 08:28:56 +02:00
|
|
|
|
(interactive)
|
|
|
|
|
(let* ((path (shell-quote-argument (mu4e-message-field msg :path)))
|
2021-08-30 21:02:49 +02:00
|
|
|
|
(command (format mu4e-register-as-spam-cmd path)))
|
2015-05-25 08:28:56 +02:00
|
|
|
|
(shell-command command))
|
2020-02-11 12:00:46 +01:00
|
|
|
|
(mu4e-mark-at-point 'delete nil))
|
2015-05-25 08:28:56 +02:00
|
|
|
|
|
|
|
|
|
(defun mu4e-register-msg-as-ham (msg)
|
2021-08-30 21:02:49 +02:00
|
|
|
|
"Register MSG as ham."
|
2015-05-25 08:28:56 +02:00
|
|
|
|
(interactive)
|
|
|
|
|
(let* ((path (shell-quote-argument(mu4e-message-field msg :path)))
|
2021-08-30 21:02:49 +02:00
|
|
|
|
(command (format mu4e-register-as-ham-cmd path)))
|
2015-05-25 08:28:56 +02:00
|
|
|
|
(shell-command command))
|
2020-02-11 12:00:46 +01:00
|
|
|
|
(mu4e-mark-at-point 'something nil))
|
2019-12-01 13:24:03 +01:00
|
|
|
|
|
2016-04-19 20:27:38 +02:00
|
|
|
|
;; (add-to-list 'mu4e-view-actions
|
|
|
|
|
;; '("sMark as spam" . mu4e-view-register-msg-as-spam) t)
|
|
|
|
|
;; (add-to-list 'mu4e-view-actions
|
|
|
|
|
;; '("hMark as ham" . mu4e-view-register-msg-as-ham) t)
|
|
|
|
|
|
|
|
|
|
(defun mu4e-view-register-msg-as-spam (msg)
|
2021-08-30 21:02:49 +02:00
|
|
|
|
"Register MSG as spam (view mode)."
|
2016-04-19 20:27:38 +02:00
|
|
|
|
(interactive)
|
|
|
|
|
(let* ((path (shell-quote-argument (mu4e-message-field msg :path)))
|
|
|
|
|
(command (format mu4e-register-as-spam-cmd path)))
|
|
|
|
|
(shell-command command))
|
|
|
|
|
(mu4e-view-mark-for-delete))
|
|
|
|
|
|
|
|
|
|
(defun mu4e-view-register-msg-as-ham (msg)
|
2021-08-30 21:02:49 +02:00
|
|
|
|
"Mark MSG as ham (view mode)."
|
2016-04-19 20:27:38 +02:00
|
|
|
|
(interactive)
|
|
|
|
|
(let* ((path (shell-quote-argument(mu4e-message-field msg :path)))
|
|
|
|
|
(command (format mu4e-register-as-ham-cmd path)))
|
|
|
|
|
(shell-command command))
|
|
|
|
|
(mu4e-view-mark-for-something))
|
|
|
|
|
|
2022-05-29 11:28:42 +02:00
|
|
|
|
|
2020-02-11 15:10:35 +01:00
|
|
|
|
;;; Eshell functions
|
|
|
|
|
;;
|
|
|
|
|
;; Code for `gnus-dired-attached' modified to run from eshell,
|
|
|
|
|
;; allowing files to be attached to an email via mu4e using the
|
|
|
|
|
;; eshell. Does not depend on gnus.
|
2016-08-17 03:45:32 +02:00
|
|
|
|
|
2021-08-29 16:30:10 +02:00
|
|
|
|
|
2021-08-30 21:02:49 +02:00
|
|
|
|
(defun mu4e--active-composition-buffers ()
|
|
|
|
|
"Return all active mu4e composition buffers."
|
2021-08-29 16:30:10 +02:00
|
|
|
|
(let (buffers)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(dolist (buffer (buffer-list t))
|
|
|
|
|
(set-buffer buffer)
|
|
|
|
|
(when (eq major-mode 'mu4e-compose-mode)
|
|
|
|
|
(push (buffer-name buffer) buffers))))
|
|
|
|
|
(nreverse buffers)))
|
|
|
|
|
|
2023-01-04 11:16:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; backward compat until 27.1 is univeral.
|
|
|
|
|
(defalias 'mu4e--flatten-list
|
|
|
|
|
(if (fboundp 'flatten-list)
|
|
|
|
|
#'flatten-list
|
|
|
|
|
(with-no-warnings
|
|
|
|
|
#'eshell-flatten-list)))
|
|
|
|
|
|
|
|
|
|
;; backward compat ntil 28.1 is universal.
|
|
|
|
|
(defalias 'mu4e--mm-default-file-type
|
|
|
|
|
(if (fboundp 'mm-default-file-type)
|
|
|
|
|
#'mm-default-file-type
|
|
|
|
|
(with-no-warnings
|
|
|
|
|
#'mm-default-file-encoding)))
|
|
|
|
|
|
2016-08-17 03:45:32 +02:00
|
|
|
|
(defun eshell/mu4e-attach (&rest args)
|
2021-08-30 21:02:49 +02:00
|
|
|
|
"Attach files to a mu4e message using eshell with ARGS.
|
|
|
|
|
If no mu4e buffers found, compose a new message and then attach
|
|
|
|
|
the file."
|
2016-08-17 03:45:32 +02:00
|
|
|
|
(let ((destination nil)
|
|
|
|
|
(files-str nil)
|
|
|
|
|
(bufs nil)
|
|
|
|
|
;; Remove directories from the list
|
2016-08-28 03:03:02 +02:00
|
|
|
|
(files-to-attach
|
|
|
|
|
(delq nil (mapcar
|
2021-08-30 21:02:49 +02:00
|
|
|
|
(lambda (f) (if (or (not (file-exists-p f))
|
2023-01-04 11:16:30 +01:00
|
|
|
|
(file-directory-p f))
|
|
|
|
|
nil
|
|
|
|
|
(expand-file-name f)))
|
2023-11-02 17:15:32 +01:00
|
|
|
|
(mu4e--flatten-list (reverse args))))))
|
2016-08-17 03:45:32 +02:00
|
|
|
|
;; warn if user tries to attach without any files marked
|
|
|
|
|
(if (null files-to-attach)
|
|
|
|
|
(error "No files to attach")
|
|
|
|
|
(setq files-str
|
|
|
|
|
(mapconcat
|
|
|
|
|
(lambda (f) (file-name-nondirectory f))
|
|
|
|
|
files-to-attach ", "))
|
2021-08-30 21:02:49 +02:00
|
|
|
|
(setq bufs (mu4e--active-composition-buffers))
|
2016-08-17 03:45:32 +02:00
|
|
|
|
;; set up destination mail composition buffer
|
|
|
|
|
(if (and bufs
|
|
|
|
|
(y-or-n-p "Attach files to existing mail composition buffer? "))
|
|
|
|
|
(setq destination
|
|
|
|
|
(if (= (length bufs) 1)
|
|
|
|
|
(get-buffer (car bufs))
|
2016-08-28 03:03:02 +02:00
|
|
|
|
(let ((prompt (mu4e-format "%s" "Attach to buffer")))
|
2020-05-18 17:01:52 +02:00
|
|
|
|
(substring-no-properties
|
|
|
|
|
(funcall mu4e-completing-read-function prompt
|
|
|
|
|
bufs)))))
|
2016-08-17 03:45:32 +02:00
|
|
|
|
;; setup a new mail composition buffer
|
2016-08-28 03:03:02 +02:00
|
|
|
|
(if (y-or-n-p "Compose new mail and attach this file? ")
|
|
|
|
|
(progn (mu4e-compose-new)
|
|
|
|
|
(setq destination (current-buffer)))))
|
|
|
|
|
;; if buffer was found, set buffer to destination buffer, and attach files
|
|
|
|
|
(if (not (eq destination 'nil))
|
|
|
|
|
(progn (set-buffer destination)
|
2020-02-11 12:00:46 +01:00
|
|
|
|
(goto-char (point-max)) ; attach at end of buffer
|
2016-08-28 03:03:02 +02:00
|
|
|
|
(while files-to-attach
|
|
|
|
|
(mml-attach-file (car files-to-attach)
|
2023-11-02 17:15:32 +01:00
|
|
|
|
(or (mu4e--mm-default-file-type
|
2023-01-04 11:16:30 +01:00
|
|
|
|
(car files-to-attach))
|
2016-08-28 03:03:02 +02:00
|
|
|
|
"application/octet-stream") nil)
|
|
|
|
|
(setq files-to-attach (cdr files-to-attach)))
|
|
|
|
|
(message "Attached file(s) %s" files-str))
|
|
|
|
|
(message "No buffer to attach file to.")))))
|
2015-05-25 08:28:56 +02:00
|
|
|
|
|
2020-02-11 13:26:45 +01:00
|
|
|
|
;;; _
|
2013-04-29 22:52:17 +02:00
|
|
|
|
(provide 'mu4e-contrib)
|
2020-02-11 12:38:01 +01:00
|
|
|
|
;;; mu4e-contrib.el ends here
|