2016-01-18 03:06:04 +00:00
|
|
|
;;; funcs.el --- mu4e Layer functions File for Spacemacs
|
2015-08-02 05:30:30 +00:00
|
|
|
;;
|
2017-01-06 03:51:13 +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
|
|
|
|
|
2016-02-09 23:39:49 +00:00
|
|
|
(defun mu4e//search-account-by-mail-address (mailto)
|
|
|
|
"Return the account given an email address in MAILTO."
|
2016-01-18 11:02:37 +00:00
|
|
|
(car (rassoc-if (lambda (x)
|
2016-02-09 23:39:49 +00:00
|
|
|
(equal (cadr (assoc 'user-mail-address x)) (car mailto)))
|
2016-01-18 11:02:37 +00:00
|
|
|
mu4e-account-alist)))
|
|
|
|
|
2015-08-02 05:30:30 +00:00
|
|
|
(defun mu4e/set-account ()
|
2016-02-09 23:39:49 +00:00
|
|
|
"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
|
2016-01-18 11:02:37 +00:00
|
|
|
(let* ((mailtos
|
|
|
|
(mu4e-message-field mu4e-compose-parent-message :to))
|
|
|
|
(mailto-account
|
2016-02-09 23:39:49 +00:00
|
|
|
(car (cl-remove-if-not
|
|
|
|
'identity
|
2016-02-15 15:55:54 +00:00
|
|
|
(mapcar 'mu4e//search-account-by-mail-address
|
2016-02-09 23:39:49 +00:00
|
|
|
mailtos))))
|
2016-01-18 11:02:37 +00:00
|
|
|
(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)))
|