Compare commits
No commits in common. "0d1755550052b03fcfbf61b5763372efaa17e4cc" and "810f759d1cc5c984fa559e3bec68eae962ad8f1d" have entirely different histories.
0d17555500
...
810f759d1c
366
etc/conf.org
366
etc/conf.org
|
@ -3402,207 +3402,223 @@ Initialize by running =nd/mu-init=.
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(nd/require-bin "pandoc" :aur "pandoc-bin")
|
(nd/require-bin "pandoc" :aur "pandoc-bin")
|
||||||
|
|
||||||
|
(nd/when-bin "mu"
|
||||||
|
(require 'mu4e)
|
||||||
|
|
||||||
(let ((acnts-path (f-join (nd/expand-lib-directory "mu4e") "accounts.el")))
|
(use-package password-store
|
||||||
(when (f-exists-p acnts-path)
|
:straight t)
|
||||||
(nd/when-bin "mu"
|
|
||||||
;; load mu itself
|
|
||||||
(require 'mu4e)
|
|
||||||
(require 'smtpmail)
|
|
||||||
;; (require 'smtpmail-async)
|
|
||||||
|
|
||||||
;;
|
(defun nd/mu4e-junk-folder (msg)
|
||||||
;; apply common config shared b/t all accounts I use
|
(->> (mu4e-context-determine msg nil)
|
||||||
;;
|
(mu4e-context-vars)
|
||||||
|
(alist-get 'nd/mu4e-junk-folder)))
|
||||||
|
|
||||||
(defun nd/mu-init (maildir)
|
(defun nd/mu4e-headers-mark-for-junk ()
|
||||||
"Initialize the mu database using available contexts."
|
(interactive)
|
||||||
(->> mu4e-contexts
|
(mu4e-headers-mark-and-next 'junk))
|
||||||
(--map (->> (mu4e-context-vars it)
|
|
||||||
(alist-get 'user-mail-address)
|
|
||||||
(format "--my-address=%s")))
|
|
||||||
(s-join " ")
|
|
||||||
(format "mu init --maildir %s %s" maildir)
|
|
||||||
(shell-command-to-string)))
|
|
||||||
|
|
||||||
(defun nd/mu4e-junk-folder (msg)
|
(defun nd/make-mu4e-context (name dir addr smtp-srv sent-behavior)
|
||||||
"Hacky function to return junk folder from context.
|
(let* ((trash (format "/%s/trash" dir))
|
||||||
|
(drafts (format "/%s/drafts" dir))
|
||||||
|
(sent (format "/%s/sent" dir))
|
||||||
|
(archive (format "/%s/archive" dir))
|
||||||
|
(inbox (format "/%s/inbox" dir))
|
||||||
|
(junk (format "/%s/junk" dir))
|
||||||
|
(shortcuts (--map (list :maildir (car it) :key (cdr it))
|
||||||
|
`((,trash . ?t)
|
||||||
|
(,drafts . ?d)
|
||||||
|
(,sent . ?s)
|
||||||
|
(,archive . ?a)
|
||||||
|
(,inbox . ?i)
|
||||||
|
(,junk . ?j))))
|
||||||
|
|
||||||
Must be bound to symbol `nd/mu4e-junk-folder`."
|
(mf (lambda (d msg)
|
||||||
(->> (mu4e-context-determine msg nil)
|
(-some--> msg
|
||||||
(mu4e-context-vars)
|
(mu4e-message-field it :maildir)
|
||||||
(alist-get 'nd/mu4e-junk-folder)))
|
(string-prefix-p (concat "/" d) it)))))
|
||||||
|
(make-mu4e-context
|
||||||
|
:name name
|
||||||
|
:match-func (-partial mf dir) ; use lexical scope here
|
||||||
|
:vars `((mu4e-trash-folder . ,trash)
|
||||||
|
(mu4e-drafts-folder . ,drafts)
|
||||||
|
(mu4e-sent-folder . ,sent)
|
||||||
|
(mu4e-refile-folder . ,archive)
|
||||||
|
(nd/mu4e-junk-folder . ,junk)
|
||||||
|
(mu4e-sent-messages-behavior . ,sent-behavior)
|
||||||
|
(smtpmail-stream-type . starttls)
|
||||||
|
(smtpmail-smtp-server . ,smtp-srv)
|
||||||
|
(smtpmail-smtp-service . 587)
|
||||||
|
(smtpmail-smtp-user . ,addr)
|
||||||
|
(user-mail-address . ,addr)
|
||||||
|
(mu4e-maildir-shortcuts . ,shortcuts)))))
|
||||||
|
|
||||||
(defun nd/mu4e-headers-mark-for-junk ()
|
;; display mu4e in same window
|
||||||
"Function to mark messages as junk."
|
(add-to-list 'display-buffer-alist
|
||||||
(interactive)
|
`(,(regexp-quote mu4e-main-buffer-name)
|
||||||
(mu4e-headers-mark-and-next 'junk))
|
display-buffer-same-window))
|
||||||
|
|
||||||
(defun nd/make-mu4e-context (name dir addr smtp-srv smtp-tls sent-behavior)
|
(add-to-list
|
||||||
(-let* ((trash (format "/%s/trash" dir))
|
'mu4e-marks
|
||||||
(drafts (format "/%s/drafts" dir))
|
'(junk :char ("j" . "┻")
|
||||||
(sent (format "/%s/sent" dir))
|
:prompt "junk"
|
||||||
(archive (format "/%s/archive" dir))
|
:dyn-target
|
||||||
(inbox (format "/%s/inbox" dir))
|
(lambda (target msg) (nd/mu4e-junk-folder msg))
|
||||||
(junk (format "/%s/junk" dir))
|
:action
|
||||||
(shortcuts (--map (list :maildir (car it) :key (cdr it))
|
(lambda
|
||||||
`((,trash . ?t)
|
(docid msg target)
|
||||||
(,drafts . ?d)
|
(mu4e--server-move docid
|
||||||
(,sent . ?s)
|
(mu4e--mark-check-target target)
|
||||||
(,archive . ?a)
|
"-N"))))
|
||||||
(,inbox . ?i)
|
|
||||||
(,junk . ?j))))
|
|
||||||
;; either use TLS or no authentication for outgoing
|
|
||||||
((smtp-proto smtp-port) (if smtp-tls
|
|
||||||
'(starttls 587)
|
|
||||||
'(nil 25)))
|
|
||||||
(mf (lambda (d msg)
|
|
||||||
(-some--> msg
|
|
||||||
(mu4e-message-field it :maildir)
|
|
||||||
(string-prefix-p (concat "/" d) it)))))
|
|
||||||
(make-mu4e-context
|
|
||||||
:name name
|
|
||||||
:match-func (-partial mf dir) ; use lexical scope here
|
|
||||||
:vars `((mu4e-trash-folder . ,trash)
|
|
||||||
(mu4e-drafts-folder . ,drafts)
|
|
||||||
(mu4e-sent-folder . ,sent)
|
|
||||||
(mu4e-refile-folder . ,archive)
|
|
||||||
(nd/mu4e-junk-folder . ,junk)
|
|
||||||
(mu4e-sent-messages-behavior . ,sent-behavior)
|
|
||||||
(smtpmail-stream-type . ,smtp-proto)
|
|
||||||
(smtpmail-smtp-server . ,smtp-srv)
|
|
||||||
(smtpmail-smtp-service . ,smtp-port)
|
|
||||||
(smtpmail-smtp-user . ,addr)
|
|
||||||
(user-mail-address . ,addr)
|
|
||||||
(mu4e-maildir-shortcuts . ,shortcuts)))))
|
|
||||||
|
|
||||||
;; display mu4e in same window
|
|
||||||
(add-to-list 'display-buffer-alist
|
|
||||||
`(,(regexp-quote mu4e-main-buffer-name)
|
|
||||||
display-buffer-same-window))
|
|
||||||
|
|
||||||
;; special mark for junk (which is different from trash)
|
(setq mail-user-agent 'mu4e-user-agent
|
||||||
;; trash = delete later
|
message-kill-buffer-on-exit t
|
||||||
;; junk = spam, which I don't want to delete so I can train spam filters
|
|
||||||
;;
|
|
||||||
;; NOTE weird cross symbol picked because it looks like a certain digit
|
|
||||||
(add-to-list
|
|
||||||
'mu4e-marks
|
|
||||||
'(junk :char ("j" . "┻")
|
|
||||||
:prompt "junk"
|
|
||||||
:dyn-target
|
|
||||||
(lambda (target msg) (nd/mu4e-junk-folder msg))
|
|
||||||
:action
|
|
||||||
(lambda
|
|
||||||
(docid msg target)
|
|
||||||
(mu4e--server-move docid
|
|
||||||
(mu4e--mark-check-target target)
|
|
||||||
"-N"))))
|
|
||||||
|
|
||||||
;; buttload of common settings I like
|
;; misc
|
||||||
(setq mail-user-agent 'mu4e-user-agent
|
mu4e-change-filenames-when-moving t
|
||||||
message-kill-buffer-on-exit t
|
mu4e-confirm-quit nil
|
||||||
|
mu4e-compose-dont-reply-to-self t
|
||||||
|
mu4e-get-mail-command "mbsync -a && mu-index-emacs-maybe"
|
||||||
|
mu4e-use-fancy-chars t
|
||||||
|
|
||||||
;; misc
|
;; sub some fancy chars that don't have valid codes
|
||||||
mu4e-change-filenames-when-moving t
|
mu4e-headers-trashed-mark '("T" . "Ω")
|
||||||
mu4e-confirm-quit nil
|
mu4e-headers-unread-mark '("U" . "✉")
|
||||||
mu4e-compose-dont-reply-to-self t
|
mu4e-headers-personal-mark '("P" . "Ρ")
|
||||||
mu4e-get-mail-command "mbsync -a && mu-index-emacs-maybe"
|
mu4e-headers-list-mark '("L" . "Λ")
|
||||||
mu4e-use-fancy-chars t
|
mu4e-headers-attach-mark '("a" . "ɑ")
|
||||||
|
mu4e-headers-thread-root-prefix '("* " . "● ")
|
||||||
|
mu4e-headers-threaded-label '("T" . "Ψ")
|
||||||
|
mu4e-headers-related-label '("R" . "↔")
|
||||||
|
|
||||||
;; sub some fancy chars that don't have valid codes
|
;; directories
|
||||||
mu4e-headers-trashed-mark '("T" . "Ω")
|
mu4e-attachment-dir "~/Downloads"
|
||||||
mu4e-headers-unread-mark '("U" . "✉")
|
|
||||||
mu4e-headers-personal-mark '("P" . "Ρ")
|
|
||||||
mu4e-headers-list-mark '("L" . "Λ")
|
|
||||||
mu4e-headers-attach-mark '("a" . "ɑ")
|
|
||||||
mu4e-headers-thread-root-prefix '("* " . "● ")
|
|
||||||
mu4e-headers-threaded-label '("T" . "Ψ")
|
|
||||||
mu4e-headers-related-label '("R" . "↔")
|
|
||||||
|
|
||||||
;; directories
|
;; headers
|
||||||
mu4e-attachment-dir "~/Downloads"
|
mu4e-headers-show-target nil
|
||||||
|
mu4e-headers-fields '((:human-date . 11)
|
||||||
|
(:flags . 5)
|
||||||
|
(:from . 22)
|
||||||
|
(:thread-subject))
|
||||||
|
mu4e-headers-date-format "%F"
|
||||||
|
mu4e-headers-time-format "%R"
|
||||||
|
|
||||||
;; headers
|
;; view
|
||||||
mu4e-headers-show-target nil
|
mu4e-view-show-images t
|
||||||
mu4e-headers-fields '((:human-date . 11)
|
mu4e-view-show-addresses t
|
||||||
(:flags . 5)
|
mu4e-view-prefer-html t
|
||||||
(:from . 22)
|
|
||||||
(:thread-subject))
|
|
||||||
mu4e-headers-date-format "%F"
|
|
||||||
mu4e-headers-time-format "%R"
|
|
||||||
|
|
||||||
;; view
|
;; compose
|
||||||
mu4e-view-show-images t
|
mu4e-compose-signature-auto-include nil ;; sigs are annoying by default
|
||||||
mu4e-view-show-addresses t
|
mu4e-compose-signature "Thank you,\nNathan Dwarshuis"
|
||||||
mu4e-view-prefer-html t
|
|
||||||
|
|
||||||
;; compose
|
;; aliases
|
||||||
message-signature nil
|
mail-personal-alias-file (no-littering-expand-etc-file-name
|
||||||
|
"mailrc")
|
||||||
|
|
||||||
;; aliases
|
;; yanking (aka citing)
|
||||||
mail-personal-alias-file (no-littering-expand-etc-file-name
|
message-yank-prefix "" ;; the ">" characters are annoying
|
||||||
"mailrc")
|
message-yank-cited-prefix ""
|
||||||
|
message-yank-empty-prefix ""
|
||||||
|
|
||||||
;; yanking (aka citing)
|
;; contexts (multiple inboxes)
|
||||||
message-yank-prefix "" ;; the ">" characters are annoying
|
mu4e-context-policy 'pick-first
|
||||||
message-yank-cited-prefix ""
|
mu4e-compose-context-policy 'ask-if-none
|
||||||
message-yank-empty-prefix ""
|
mu4e-contexts
|
||||||
|
(list
|
||||||
|
(nd/make-mu4e-context "personal"
|
||||||
|
"yavin4"
|
||||||
|
"ndwar@yavin4.ch"
|
||||||
|
"peart4prez.yavin4.ch"
|
||||||
|
'sent)
|
||||||
|
(nd/make-mu4e-context "alpha"
|
||||||
|
"gmail"
|
||||||
|
"natedwarshuis@gmail.com"
|
||||||
|
"smtp.gmail.com"
|
||||||
|
'delete)))
|
||||||
|
|
||||||
;; contexts (multiple inboxes)
|
;; enable visual line mode and spell checking
|
||||||
mu4e-context-policy 'pick-first
|
(add-hook 'mu4e-compose-mode-hook 'turn-off-auto-fill)
|
||||||
mu4e-compose-context-policy 'ask-if-none)
|
(add-hook 'mu4e-compose-mode-hook 'visual-line-mode)
|
||||||
|
(add-hook 'mu4e-view-mode-hook 'turn-off-auto-fill)
|
||||||
|
(add-hook 'mu4e-view-mode-hook 'visual-line-mode)
|
||||||
|
(add-hook 'mu4e-compose-mode-hook (lambda () (flyspell-mode 1)))
|
||||||
|
|
||||||
;; enable visual line mode and spell checking
|
;; Outlook doesn't know how to fold mu4e messages by default
|
||||||
(add-hook 'mu4e-compose-mode-hook 'turn-off-auto-fill)
|
;; This is enabled by using 32 underscores followed by the addressing
|
||||||
(add-hook 'mu4e-compose-mode-hook 'visual-line-mode)
|
;; info of the previou message(s).
|
||||||
(add-hook 'mu4e-view-mode-hook 'turn-off-auto-fill)
|
(require 'nnheader) ; necessary for the header macros below
|
||||||
(add-hook 'mu4e-view-mode-hook 'visual-line-mode)
|
|
||||||
(add-hook 'mu4e-compose-mode-hook (lambda () (flyspell-mode 1)))
|
|
||||||
|
|
||||||
;; Outlook doesn't know how to fold mu4e messages by default
|
(defun nd/message-insert-citation-header ()
|
||||||
;; This is enabled by using 32 underscores followed by the addressing
|
"Insert the header of the reply message."
|
||||||
;; info of the previou message(s).
|
(let* ((h message-reply-headers)
|
||||||
(require 'nnheader) ; necessary for the header macros below
|
(sep "________________________________")
|
||||||
|
(from (concat "From: " (mail-header-from h)))
|
||||||
|
(date (concat "Sent: " (mail-header-date h)))
|
||||||
|
(to (concat "To: " user-full-name))
|
||||||
|
(subj (concat "Subject: " (message-strip-subject-re (mail-header-subject h)))))
|
||||||
|
(insert (string-join `("" ,sep ,from ,date ,to ,subj "") "\n"))))
|
||||||
|
|
||||||
(defun nd/message-insert-citation-header ()
|
(setq message-citation-line-function 'nd/message-insert-citation-header)
|
||||||
"Insert the header of the reply message."
|
|
||||||
(let* ((h message-reply-headers)
|
|
||||||
(sep "________________________________")
|
|
||||||
(from (concat "From: " (mail-header-from h)))
|
|
||||||
(date (concat "Sent: " (mail-header-date h)))
|
|
||||||
(to (concat "To: " user-full-name))
|
|
||||||
(subj (concat "Subject: " (message-strip-subject-re (mail-header-subject h)))))
|
|
||||||
(insert (string-join `("" ,sep ,from ,date ,to ,subj "") "\n"))))
|
|
||||||
|
|
||||||
(setq message-citation-line-function 'nd/message-insert-citation-header)
|
;; prevent html to text conversion from destroying links
|
||||||
|
(setq
|
||||||
|
mu4e-compose-pre-hook
|
||||||
|
(lambda ()
|
||||||
|
(let* ((msg mu4e-compose-parent-message)
|
||||||
|
(html (and msg (plist-get msg :body-html)))
|
||||||
|
;; oops, mu4e screwed up
|
||||||
|
(mu4e-html2text-command
|
||||||
|
(nd/if-bin "pandoc"
|
||||||
|
"pandoc -f html -t plain --reference-links"
|
||||||
|
'mu4e-shr2text)))
|
||||||
|
(when (and html mu4e-view-prefer-html (member mu4e-compose-type '(reply forward)))
|
||||||
|
;; hackity hack, since the normal mu4e-message-body-text function
|
||||||
|
;; does not render the desired html, do it here and force the
|
||||||
|
;; aforementioned function to only look at text by removing
|
||||||
|
;; the html
|
||||||
|
(plist-put msg :body-txt (mu4e~html2text-shell msg mu4e-html2text-command))
|
||||||
|
(plist-put msg :body-html nil)))))
|
||||||
|
|
||||||
;; prevent html to text conversion from destroying links
|
(require 'smtpmail)
|
||||||
(setq
|
;; (require 'smtpmail-async)
|
||||||
mu4e-compose-pre-hook
|
(setq send-mail-function 'smtpmail-send-it
|
||||||
(lambda ()
|
smtpmail-debug-info nil
|
||||||
(let* ((msg mu4e-compose-parent-message)
|
auth-source-debug nil
|
||||||
(html (and msg (plist-get msg :body-html)))
|
message-send-mail-function 'smtpmail-send-it)
|
||||||
;; oops, mu4e screwed up
|
(setq auth-sources '(password-store))
|
||||||
(mu4e-html2text-command
|
|
||||||
(nd/if-bin "pandoc"
|
|
||||||
"pandoc -f html -t plain --reference-links"
|
|
||||||
'mu4e-shr2text)))
|
|
||||||
(when (and html mu4e-view-prefer-html (member mu4e-compose-type '(reply forward)))
|
|
||||||
;; hackity hack, since the normal mu4e-message-body-text function
|
|
||||||
;; does not render the desired html, do it here and force the
|
|
||||||
;; aforementioned function to only look at text by removing
|
|
||||||
;; the html
|
|
||||||
(plist-put msg :body-txt (mu4e~html2text-shell msg mu4e-html2text-command))
|
|
||||||
(plist-put msg :body-html nil)))))
|
|
||||||
|
|
||||||
(setq send-mail-function 'smtpmail-send-it
|
(defun nd/mu-init ()
|
||||||
smtpmail-debug-info nil
|
"Initialize the mu database"
|
||||||
auth-source-debug nil
|
(->> mu4e-contexts
|
||||||
message-send-mail-function 'smtpmail-send-it)
|
(--map (->> (mu4e-context-vars it)
|
||||||
|
(alist-get 'user-mail-address)
|
||||||
|
(format "--my-address=%s")))
|
||||||
|
(s-join " ")
|
||||||
|
(format "mu init --maildir /mnt/data/Mail %s")
|
||||||
|
(shell-command-to-string)))
|
||||||
|
|
||||||
;; load instance-specific accounts
|
(defun nd/lookup-oauth-secret (type user)
|
||||||
(load-file acnts-path))))
|
(->> (format "pass email/%s/%s" user type)
|
||||||
|
(shell-command-to-string)
|
||||||
|
(s-trim)))
|
||||||
|
|
||||||
|
(defun nd/xoauth2-get-secrets (host user port)
|
||||||
|
(when (and (string= host "smtp.gmail.com")
|
||||||
|
(string= user "natedwarshuis@gmail.com")
|
||||||
|
(string= port "587"))
|
||||||
|
(list :token-url (nd/lookup-oauth-secret "token_url" user)
|
||||||
|
:client-id (nd/lookup-oauth-secret "client_id" user)
|
||||||
|
:client-secret (nd/lookup-oauth-secret "client_secret" user)
|
||||||
|
:refresh-token (nd/lookup-oauth-secret "refresh_token" user))))
|
||||||
|
|
||||||
|
(use-package auth-source-xoauth2
|
||||||
|
:straight t
|
||||||
|
:after smtpmail
|
||||||
|
:config
|
||||||
|
(setq auth-source-xoauth2-creds #'nd/xoauth2-get-secrets)
|
||||||
|
(add-to-list 'smtpmail-auth-supported 'xoauth2)
|
||||||
|
(auth-source-xoauth2-enable)))
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
** shell
|
** shell
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
mu4e
|
|
Loading…
Reference in New Issue