mirror of
https://github.com/pestctrl/emacs-config.git
synced 2026-06-14 04:11:18 +00:00
175 lines
6.6 KiB
EmacsLisp
175 lines
6.6 KiB
EmacsLisp
;;; mu4e-config.el --- -*- lexical-binding: t -*-
|
|
|
|
;; Copyright (C) 2023 Benson Chu
|
|
|
|
;; Author: Benson Chu <bensonchu457@gmail.com>
|
|
;; Created: [2023-03-12 09:51]
|
|
|
|
;; This file is not part of GNU Emacs
|
|
|
|
;; 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 <https://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;;; Code:
|
|
(require 'mu4e)
|
|
(require 'mu4e-generic)
|
|
|
|
(add-to-list 'mu4e-view-actions
|
|
'("ViewInBrowser" . mu4e-action-view-in-browser) t)
|
|
|
|
;; (global-set-key (kbd "<f8>") 'mu4e)
|
|
|
|
|
|
(setq mu4e-maildir "~/.mail"
|
|
mu4e-sent-folder "/fastmail/Sent"
|
|
mu4e-drafts-folder "/fastmail/Drafts"
|
|
mu4e-refile-folder "/fastmail/Archive"
|
|
mu4e-trash-folder "/fastmail/Trash")
|
|
|
|
(setq mu4e-maildir-shortcuts
|
|
'(("/fastmail/INBOX" . ?i)
|
|
("/fastmail/important.Development" . ?d)
|
|
("/fastmail/important.Puppet" . ?p)
|
|
("/fastmail/important.VIPs" . ?v)
|
|
("/fastmail/important.unsorted" . ?u)
|
|
("/fastmail/important.tracking" . ?t)
|
|
("/fastmail/important.tracking.receipts" . ?r)
|
|
("/fastmail/corpo" . ?c)
|
|
("/fastmail/Archive" . ?a)
|
|
("/fastmail/Unnecessary.mailing_lists.emacs.emacs-devel" . ?e)
|
|
("/fastmail/Unnecessary.mailing_lists.emacs.emacs-devel.kept" . ?k)
|
|
("/fastmail/Unnecessary.mailing_lists.emacs.emacs-orgmode" . ?O)
|
|
("/fastmail/Unnecessary.mailing_lists.emacs.bug-gnu-emacs" . ?b)
|
|
("/fastmail/Unnecessary.mailing_lists.emacs.help-gnu-emacs" . ?h)
|
|
("/fastmail/Unnecessary.mailing_lists.notmuch" . ?n)))
|
|
|
|
(setq mu4e-bookmarks
|
|
'(( :name "Inbox"
|
|
:query "maildir:/fastmail/INBOX AND NOT flag:trashed"
|
|
:key ?i)
|
|
( :name "Unsorted"
|
|
:query "(maildir:/fastmail/important.unsorted OR maildir:/fastmail/corpo)"
|
|
:key ?u)
|
|
( :name "New emacs-devel"
|
|
:query "maildir:/fastmail/Unnecessary.mailing_lists.emacs.emacs-devel AND flag:unread AND date:2026/03/01.."
|
|
:key ?e)
|
|
( :name "All emacs-devel"
|
|
:query "maildir:/fastmail/Unnecessary.mailing_lists.emacs.emacs-devel AND flag:unread"
|
|
:key ?E)
|
|
( :name "Kept emacs-devel"
|
|
:query "maildir:/fastmail/Unnecessary.mailing_lists.emacs.emacs-devel.kept"
|
|
:key ?k)
|
|
( :name "Today's messages"
|
|
:query "date:today..now"
|
|
:key ?t)
|
|
( :name "Last 7 days"
|
|
:query "date:7d..now"
|
|
:hide-unread t
|
|
:key ?w)))
|
|
|
|
(defvar my/email-accounts
|
|
'("bensonchu457@fastmail.com"
|
|
"bensonchu@fastmail.com"
|
|
"bensonchu457@gmail.com"
|
|
"me@mail.pestctrl.io"
|
|
"dev@mail.pestctrl.io"
|
|
"accounts@mail.pestctrl.io"
|
|
"chuan.chu01@fastmail.com"
|
|
"julie.chu01@fastmail.com"))
|
|
|
|
(defun my/mu-init ()
|
|
(interactive)
|
|
(async-shell-command
|
|
(format "mu init --maildir=~/.mail/ %s"
|
|
(--> my/email-accounts
|
|
(mapcar #'(lambda (x) (concat "--my-address=" x)) it)
|
|
(string-join it " ")))))
|
|
|
|
(defun my-mu4e-set-account ()
|
|
(setq user-mail-address
|
|
(or (and mu4e-compose-parent-message
|
|
(mu4e-contact-email
|
|
(-any
|
|
#'(lambda (x)
|
|
(mu4e-message-contact-field-matches-me mu4e-compose-parent-message
|
|
x))
|
|
'(:to :cc :bcc :from))))
|
|
(completing-read "Compose with account: "
|
|
my/email-accounts
|
|
nil t))))
|
|
|
|
(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)
|
|
|
|
;; (setcar mu4e-headers-thread-last-child-prefix "╰┬►")
|
|
;; (setcar mu4e-headers-thread-first-child-prefix "├┬►")
|
|
;; (setcar mu4e-headers-thread-connection-prefix "│")
|
|
|
|
|
|
(defun my/mu4e~headers-thread-prefix (thread)
|
|
"Calculate the thread prefix based on thread info THREAD."
|
|
(when thread
|
|
(let* ((prefix "")
|
|
(level (plist-get thread :level))
|
|
(has-child (plist-get thread :has-child))
|
|
(last-child (plist-get thread :last-child))
|
|
(duplicate (plist-get thread :duplicate)))
|
|
;; Do not prefix root messages.
|
|
(when (= level 0)
|
|
(setq mu4e~headers-thread-state '())
|
|
(when has-child
|
|
(setq prefix "┬►")))
|
|
(if (> level 0)
|
|
(let* ((length (length mu4e~headers-thread-state))
|
|
(padding (make-list (max 0 (- level length)) nil)))
|
|
;; Trim and pad the state to ensure a message will
|
|
;; always be shown with the correct indentation, even if
|
|
;; a broken thread is returned. It's trimmed to level-1
|
|
;; because the current level has always an connection
|
|
;; and it used a special formatting.
|
|
(setq mu4e~headers-thread-state
|
|
(cl-subseq (append mu4e~headers-thread-state padding)
|
|
0 (- level 1)))
|
|
;; Prepare the thread prefix.
|
|
(setq prefix
|
|
(concat
|
|
;; Current mu4e~headers-thread-state, composed by
|
|
;; connections or blanks.
|
|
(mapconcat
|
|
(lambda (s)
|
|
(if s "│" " "))
|
|
mu4e~headers-thread-state "")
|
|
(if last-child "╰" "├")
|
|
(if has-child "┬" "─")
|
|
"►"))))
|
|
;; If a new sub-thread will follow (has-child) and the current
|
|
;; one is still not done (not last-child), then a new
|
|
;; connection needs to be added to the tree-state. It's not
|
|
;; necessary to a blank (nil), because padding will handle
|
|
;; that.
|
|
(if (and has-child (not last-child))
|
|
(setq mu4e~headers-thread-state
|
|
(append mu4e~headers-thread-state '(t))))
|
|
;; Return the thread prefix.
|
|
(format "%s%s"
|
|
(propertize prefix 'face 'mu4e-related-face)
|
|
(if duplicate
|
|
(mu4e~headers-thread-prefix-map 'duplicate) "")))))
|
|
|
|
(advice-add #'mu4e~headers-thread-prefix
|
|
:override
|
|
#'my/mu4e~headers-thread-prefix)
|
|
|
|
(provide 'mu4e-configuration)
|
|
;;; mu4e-config.el ends here
|