161 lines
7.3 KiB
EmacsLisp
161 lines
7.3 KiB
EmacsLisp
;; (C) Copyright Collin J. Doering 2014
|
|
;;
|
|
;; This program 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.
|
|
;;
|
|
;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
;; File: mu4e.el
|
|
;; Author: Collin J. Doering <collin.doering@rekahsoft.ca>
|
|
;; Date: Oct 22, 2014
|
|
|
|
;; Setup email using mu4e (offlineimap in the background) and smtpmail
|
|
(require 'mu4e)
|
|
(require 'smtpmail)
|
|
|
|
(setq mail-user-agent 'mu4e-user-agent
|
|
mu4e-get-mail-command "mbsync -a"
|
|
mu4e-update-interval 300
|
|
mu4e-user-mail-address-list (list "collin.doering@gmail.com" "rekahsoft@gmail.com")
|
|
message-kill-buffer-on-exit t
|
|
mu4e-use-fancy-chars t
|
|
mu4e-sent-messages-behavior 'delete
|
|
mu4e-confirm-quit nil
|
|
mu4e-headers-date-format "%d/%b/%Y %H:%M" ; date format
|
|
message-signature "Collin J. Doering\n\nhttp://rekahsoft.ca\nhttp://blog.rekahsoft.ca\n"
|
|
mu4e-compose-signature message-signature
|
|
message-signature-insert-empty-line t
|
|
mu4e-html2text-command "pandoc -f html -t asciidoc"
|
|
|
|
mu4e-view-show-images t
|
|
mu4e-view-image-max-width 800
|
|
|
|
;; Default email for smtp and mu4e
|
|
user-mail-address "collin.doering@gmail.com"
|
|
|
|
;; Setup mu4e default sent and draft folders
|
|
mu4e-sent-folder "/collin.doering-gmail/[Gmail].Sent"
|
|
mu4e-drafts-folder "/collin.doering-gmail/[Gmail].Drafts"
|
|
|
|
;; Set location of maildir
|
|
mu4e-maildir "~/.mail"
|
|
|
|
;; Setup smtp defaults
|
|
user-full-name "Collin J. Doering"
|
|
smtpmail-smtp-server "smtp.gmail.com"
|
|
smtpmail-smtp-service 587
|
|
smtpmail-auth-credentials "~/.authinfo.gpg"
|
|
smtpmail-stream-type 'starttls
|
|
smtpmail-debug-info t
|
|
message-send-mail-function 'smtpmail-send-it)
|
|
|
|
;; Override default mu4e-bookmarks with custom ones
|
|
(setq mu4e-bookmarks
|
|
'(("flag:unread AND NOT flag:trashed AND NOT maildir:/collin.doering-gmail/[Gmail].Spam AND NOT maildir:/rekahsoft-gmail/[Gmail].Spam" "Unread messages" ?u)
|
|
("date:today..now AND NOT maildir:/collin.doering-gmail/[Gmail].Spam AND NOT maildir:/rekahsoft-gmail/[Gmail].Spam" "Today's messages" ?t)
|
|
("date:7d..now AND NOT maildir:/collin.doering-gmail/[Gmail].Spam AND NOT maildir:/rekahsoft-gmail/[Gmail].Spam" "Last 7 days" ?w)
|
|
("mime:image/*" "Messages with images" ?p)
|
|
|
|
;; For collin.doering-gmail maildir
|
|
("flag:unread AND maildir:/collin.doering-gmail/INBOX AND NOT flag:trashed AND NOT maildir:/collin.doering-gmail/[Gmail].Spam" "Unread messages to collin.doering-gmail" ?z)
|
|
("date:today..now AND maildir:/collin.doering-gmail/INBOX AND NOT maildir:/collin.doering-gmail/[Gmail].Spam" "Today's messages to collin.doering-gmail" ?x)
|
|
("date:7d..now AND maildir:/collin.doering-gmail/INBOX AND NOT maildir:/collin.doering-gmail/[Gmail].Spam" "Last 7 days (collin.doering-gmail)" ?c)
|
|
("mime:image/* AND maildir:/collin.doering-gmail/INBOX" "Messages with images to collin.doering-gmail" ?v)
|
|
|
|
;; For rekahsoft-gmail maildir
|
|
("flag:unread AND maildir:/rekahsoft-gmail/INBOX AND NOT flag:trashed AND NOT maildir:/rekahsoft-gmail/[Gmail].Spam" "Unread messages to rekahsoft-gmail" ?m)
|
|
("date:today..now AND maildir:/rekahsoft-gmail/INBOX AND NOT maildir:/rekahsoft-gmail/[Gmail].Spam" "Today's messages to rekahsoft-gmail" ?,)
|
|
("date:7d..now AND maildir:/rekahsoft-gmail/INBOX AND NOT maildir:/rekahsoft-gmail/[Gmail].Spam" "Last 7 days (rekahsoft-gmail)" ?.)
|
|
("mime:image/* AND maildir:/rekahsoft-gmail/INBOX" "Messages with images to rekahsoft-gmail" ?/)))
|
|
|
|
;; TODO: consolidate my-mu4e-account-alist and smtp-accounts
|
|
(defvar my-mu4e-account-alist
|
|
'(("collin.doering-gmail"
|
|
(mu4e-sent-folder "/collin.doering-gmail/[Gmail].Sent")
|
|
(mu4e-drafts-folder "/collin.doering-gmail/[Gmail].Drafts")
|
|
(user-mail-address "collin.doering@gmail.com"))
|
|
("rekahsoft-gmail"
|
|
(mu4e-sent-folder "/rekahsoft-gmail/[Gmail].Sent")
|
|
(mu4e-drafts-folder "/rekahsoft-gmail/[Gmail].Drafts")
|
|
(user-mail-address "rekahsoft@gmail.com"))))
|
|
|
|
(defun my-mu4e-set-account ()
|
|
"Set the account for composing a message."
|
|
(let* ((account
|
|
(if mu4e-compose-parent-message
|
|
(let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
|
|
(string-match "/\\(.*?\\)/" maildir)
|
|
(match-string 1 maildir))
|
|
(completing-read (format "Compose with account: (%s) "
|
|
(mapconcat #'(lambda (var) (car var)) my-mu4e-account-alist "/"))
|
|
(mapcar #'(lambda (var) (car var)) my-mu4e-account-alist)
|
|
nil t nil nil (caar my-mu4e-account-alist))))
|
|
(account-vars (cdr (assoc account my-mu4e-account-alist))))
|
|
(if account-vars
|
|
(mapc #'(lambda (var)
|
|
(set (car var) (cadr var)))
|
|
account-vars)
|
|
(error "No email account found"))))
|
|
|
|
(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)
|
|
|
|
;; Attach files using dired using 'C-c RET C-a'
|
|
;; Thanks to: http://www.djcbsoftware.nl/code/mu/mu4e/Attaching-files-with-dired.html#Attaching-files-with-dired
|
|
(require 'gnus-dired)
|
|
;; make the `gnus-dired-mail-buffers' function also work on
|
|
;; message-mode derived modes, such as mu4e-compose-mode
|
|
(defun gnus-dired-mail-buffers ()
|
|
"Return a list of active message buffers."
|
|
(let (buffers)
|
|
(save-current-buffer
|
|
(dolist (buffer (buffer-list t))
|
|
(set-buffer buffer)
|
|
(when (and (derived-mode-p 'message-mode)
|
|
(null message-sent-message-via))
|
|
(push (buffer-name buffer) buffers))))
|
|
(nreverse buffers)))
|
|
|
|
(setq gnus-dired-mail-mode 'mu4e-user-agent)
|
|
(add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode)
|
|
|
|
;; Setup mu4e-maildirs-extension
|
|
(require 'mu4e-maildirs-extension)
|
|
(mu4e-maildirs-extension)
|
|
|
|
(setq smtp-accounts
|
|
'(("collin.doering@gmail.com" "Collin J. Doering" "smtp.gmail.com")
|
|
("rekahsoft@gmail.com" "rekahsoft" "smtp.gmail.com")))
|
|
|
|
(defun my-change-smtp ()
|
|
(save-excursion
|
|
(loop with from = (save-restriction
|
|
(message-narrow-to-headers)
|
|
(message-fetch-field "from"))
|
|
for (addr fname server) in smtp-accounts
|
|
when (string-match addr from)
|
|
do (setq user-mail-address addr
|
|
user-full-name fname
|
|
smtpmail-smtp-server server
|
|
smtpmail-smtp-user addr))))
|
|
|
|
(defadvice smtpmail-via-smtp
|
|
(before change-smtp-by-message-from-field (recipient buffer &optional ask) activate)
|
|
(with-current-buffer buffer (my-change-smtp)))
|
|
|
|
(ad-activate 'smtpmail-via-smtp)
|
|
|
|
;; Set environment variables set by gpg-agent --daemon in ~/.gpg-agent-info
|
|
;; TODO: perhaps better error handling if ~/.gpg-agent-info doesn't exist
|
|
(mapc (lambda (x) (setenv (car x) (cadr x)))
|
|
(with-temp-buffer
|
|
(insert-file-contents "~/.gpg-agent-info")
|
|
(mapcar (lambda (x) (split-string x "=" t)) (split-string (buffer-string) "\n" t))))
|