This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+email/mu4e/funcs.el

54 lines
2 KiB
EmacsLisp
Raw Normal View History

;;; funcs.el --- mu4e Layer functions File for Spacemacs
2015-08-02 05:30:30 +00:00
;;
;; Copyright (c) 2012-2017 Sylvain Benner & Contributors
2015-08-02 05:30:30 +00:00
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defun mu4e//search-account-by-mail-address (mailto)
"Return the account given an email address in MAILTO."
(car (rassoc-if (lambda (x)
(equal (cadr (assoc 'user-mail-address x)) (car mailto)))
mu4e-account-alist)))
2015-08-02 05:30:30 +00:00
(defun mu4e/set-account ()
"Set the account for composing a message.
This function tries to guess the correct account from the email address first
then fallback to the maildir."
2015-08-02 05:30:30 +00:00
(let* ((account
(if mu4e-compose-parent-message
(let* ((mailtos
(mu4e-message-field mu4e-compose-parent-message :to))
(mailto-account
(car (cl-remove-if-not
'identity
(mapcar 'mu4e//search-account-by-mail-address
mailtos))))
(maildir
(mu4e-message-field mu4e-compose-parent-message :maildir))
(maildir-account
(progn
(string-match "/\\(.*?\\)/" maildir)
(match-string 1 maildir))))
(or mailto-account maildir-account))
2016-01-12 06:37:58 +00:00
(funcall mu4e-completing-read-function
"Compose with account:"
(mapcar (lambda (var) (car var)) mu4e-account-alist))))
2015-08-02 05:30:30 +00:00
(account-vars (cdr (assoc account mu4e-account-alist))))
(if account-vars
(mu4e//map-set account-vars)
(error "No email account found"))))
(defun mu4e//map-set (vars)
"Setq an alist VARS of variables and values."
(mapc (lambda (var) (set (car var) (cadr var)))
vars))
(defun mu4e/mail-account-reset ()
"Reset mail account info to first."
(mu4e//map-set (cdar mu4e-account-alist)))