This is a collection of dotfiles and scripts for my bspwm setup
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
5.1 KiB

#+TITLE: Mail Configuration
#+OPTIONS: toc:nil
#+PROPERTY: header-args:emacs-lisp :shebang ";;; -*- lexical-binding: t; -*-\n"
** Table of Contents :toc_4:
- [[#mail-functions][Mail Functions]]
- [[#mail-in-emacs-with-mu4e][Mail in Emacs with mu4e]]
- [[#sources][Sources]]
** Mail Functions
#+BEGIN_SRC emacs-lisp
(with-eval-after-load 'auth-source
(defun dot/mail-auth-get-field (host prop)
"Find PROP in `auth-sources' for HOST entry."
(when-let ((source (auth-source-search :max 1 :host host)))
(if (eq prop :secret)
(funcall (plist-get (car source) prop))
(plist-get (flatten-list source) prop)))))
#+END_SRC
** Mail in Emacs with mu4e
Useful mu4e manual pages:
- [[https://www.djcbsoftware.nl/code/mu/mu4e/MSGV-Keybindings.html#MSGV-Keybindings][Key bindings]]
#+BEGIN_SRC emacs-lisp
(use-package mu4e
:ensure nil
:load-path "/usr/share/emacs/site-lisp/mu4e"
:defer 20
:commands mu4e
:config
(setq auth-sources `(,(concat dot-etc-dir "/authinfo.gpg")))
(setq user-full-name (dot/mail-auth-get-field "fullname" :user))
(setq user-mail-address (dot/mail-auth-get-field "info" :user))
(setq mail-user-agent 'mu4e-user-agent)
;; Headers
(setq mu4e-headers-date-format "%d-%m-%Y")
(setq mu4e-headers-time-format "%I:%M %p")
(setq mu4e-headers-long-date-format "%d-%m-%Y %I:%M:%S %p")
;; Syncing
(setq mu4e-get-mail-command (concat "mbsync -a -c " (getenv "XDG_CONFIG_HOME") "/isync/mbsyncrc"))
(setq mu4e-update-interval (* 15 60)) ; 15 minutes
(setq mu4e-maildir "~/mail")
(setq mu4e-attachment-dir "~/downloads")
;; Avoid mail syncing issues when using mbsync
(setq mu4e-change-filenames-when-moving t)
;; Misc
(setq mu4e-completing-read-function 'completing-read)
(setq mu4e-confirm-quit nil)
(setq mu4e-display-update-status-in-modeline t)
(setq mu4e-hide-index-messages t)
(setq mu4e-sent-messages-behavior 'sent)
(setq mu4e-view-show-addresses t)
(setq mu4e-view-show-images nil)
;; Compose
(setq mu4e-compose-context-policy 'ask)
(setq mu4e-compose-dont-reply-to-self t)
(setq mu4e-compose-signature (concat (dot/mail-auth-get-field "fullname" :user) "\nriyyi.com\n"))
(setq mu4e-compose-signature-auto-include t)
;; Contexts
(setq mu4e-context-policy 'pick-first)
(setq mu4e-contexts
`(,(make-mu4e-context
:name "info"
:match-func (lambda (msg)
(when msg
(string= (mu4e-message-field msg :maildir) "/info")))
:vars `((user-mail-address . ,(dot/mail-auth-get-field "info" :user))
(mu4e-drafts-folder . "/info/Drafts")
(mu4e-refile-folder . "/info/Archive")
(mu4e-sent-folder . "/info/Sent")
(mu4e-trash-folder . "/info/Trash")))
,(make-mu4e-context
:name "private"
:match-func (lambda (msg)
(when msg
(string= (mu4e-message-field msg :maildir) "/private")))
:vars `((user-mail-address . ,(dot/mail-auth-get-field "private" :user))
(mu4e-drafts-folder . "/private/Drafts")
(mu4e-refile-folder . "/private/Archive")
(mu4e-sent-folder . "/private/Sent")
(mu4e-trash-folder . "/private/Trash")))
))
;; Do not mark messages as IMAP-deleted, just move them to the Trash directory!
;; https://github.com/djcb/mu/issues/1136#issuecomment-486177435
(setf (alist-get 'trash mu4e-marks)
(list :char '("d" . "▼")
:prompt "dtrash"
:dyn-target (lambda (target msg)
(mu4e-get-trash-folder msg))
:action (lambda (docid msg target)
(mu4e~proc-move docid (mu4e~mark-check-target target) "-N"))))
;; Start mu4e in the background for mail syncing
(mu4e t))
#+END_SRC
Use [[https://github.com/iqbalansari/mu4e-alert][mu4e-alert]] to show new e-mail notifications.
#+BEGIN_SRC emacs-lisp
(use-package mu4e-alert
:after mu4e
:config
(setq mu4e-alert-interesting-mail-query "(maildir:/info/Inbox OR maildir:/private/Inbox) AND flag:unread AND NOT flag:trashed")
(setq mu4e-alert-notify-repeated-mails nil)
(mu4e-alert-set-default-style 'libnotify)
(mu4e-alert-enable-notifications))
#+END_SRC
Sending mail.
#+BEGIN_SRC emacs-lisp
(use-package smtpmail
:ensure nil ; built-in
:after mu4e
:init (setq smtpmail-default-smtp-server "mail.riyyi.com")
:config
(setq smtpmail-smtp-server "mail.riyyi.com")
(setq smtpmail-local-domain "riyyi.com")
(setq smtpmail-smtp-service 587)
(setq smtpmail-stream-type 'starttls)
(setq smtpmail-queue-mail nil))
(use-package sendmail
:ensure nil ; built-in
:after mu4e
:config (setq send-mail-function 'smtpmail-send-it))
(use-package message
:ensure nil ; built-in
:after mu4e
:config
(setq message-kill-buffer-on-exit t)
(setq message-send-mail-function 'smtpmail-send-it))
#+END_SRC
** Sources
- https://rakhim.org/fastmail-setup-with-emacs-mu4e-and-mbsync-on-macos/
- https://wiki.archlinux.org/title/Isync
- https://man.archlinux.org/man/community/isync/mbsync.1.en
- https://gitlab.com/protesilaos/dotfiles/-/blob/master/mbsync/.mbsyncrc
- https://gitlab.com/protesilaos/dotfiles/-/blob/master/emacs/.emacs.d/prot-lisp/prot-mail.el
- https://gitlab.com/protesilaos/dotfiles/-/blob/master/emacs/.emacs.d/prot-lisp/prot-mu4e-deprecated-conf.el
- https://github.com/daviwil/dotfiles/blob/master/Mail.org