Compare commits

...

2 Commits

Author SHA1 Message Date
Nathan Dwarshuis 0d17555500 FIX typo 2024-03-14 10:19:32 -04:00
Nathan Dwarshuis 6df300b58a ENH make email config modular 2024-03-14 10:19:08 -04:00
2 changed files with 179 additions and 194 deletions

View File

@ -3402,23 +3402,44 @@ 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)
(use-package password-store (let ((acnts-path (f-join (nd/expand-lib-directory "mu4e") "accounts.el")))
:straight t) (when (f-exists-p acnts-path)
(nd/when-bin "mu"
;; load mu itself
(require 'mu4e)
(require 'smtpmail)
;; (require 'smtpmail-async)
;;
;; apply common config shared b/t all accounts I use
;;
(defun nd/mu-init (maildir)
"Initialize the mu database using available contexts."
(->> mu4e-contexts
(--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/mu4e-junk-folder (msg)
"Hacky function to return junk folder from context.
Must be bound to symbol `nd/mu4e-junk-folder`."
(->> (mu4e-context-determine msg nil) (->> (mu4e-context-determine msg nil)
(mu4e-context-vars) (mu4e-context-vars)
(alist-get 'nd/mu4e-junk-folder))) (alist-get 'nd/mu4e-junk-folder)))
(defun nd/mu4e-headers-mark-for-junk () (defun nd/mu4e-headers-mark-for-junk ()
"Function to mark messages as junk."
(interactive) (interactive)
(mu4e-headers-mark-and-next 'junk)) (mu4e-headers-mark-and-next 'junk))
(defun nd/make-mu4e-context (name dir addr smtp-srv sent-behavior) (defun nd/make-mu4e-context (name dir addr smtp-srv smtp-tls sent-behavior)
(let* ((trash (format "/%s/trash" dir)) (-let* ((trash (format "/%s/trash" dir))
(drafts (format "/%s/drafts" dir)) (drafts (format "/%s/drafts" dir))
(sent (format "/%s/sent" dir)) (sent (format "/%s/sent" dir))
(archive (format "/%s/archive" dir)) (archive (format "/%s/archive" dir))
@ -3431,7 +3452,10 @@ Initialize by running =nd/mu-init=.
(,archive . ?a) (,archive . ?a)
(,inbox . ?i) (,inbox . ?i)
(,junk . ?j)))) (,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) (mf (lambda (d msg)
(-some--> msg (-some--> msg
(mu4e-message-field it :maildir) (mu4e-message-field it :maildir)
@ -3445,9 +3469,9 @@ Initialize by running =nd/mu-init=.
(mu4e-refile-folder . ,archive) (mu4e-refile-folder . ,archive)
(nd/mu4e-junk-folder . ,junk) (nd/mu4e-junk-folder . ,junk)
(mu4e-sent-messages-behavior . ,sent-behavior) (mu4e-sent-messages-behavior . ,sent-behavior)
(smtpmail-stream-type . starttls) (smtpmail-stream-type . ,smtp-proto)
(smtpmail-smtp-server . ,smtp-srv) (smtpmail-smtp-server . ,smtp-srv)
(smtpmail-smtp-service . 587) (smtpmail-smtp-service . ,smtp-port)
(smtpmail-smtp-user . ,addr) (smtpmail-smtp-user . ,addr)
(user-mail-address . ,addr) (user-mail-address . ,addr)
(mu4e-maildir-shortcuts . ,shortcuts))))) (mu4e-maildir-shortcuts . ,shortcuts)))))
@ -3457,6 +3481,11 @@ Initialize by running =nd/mu-init=.
`(,(regexp-quote mu4e-main-buffer-name) `(,(regexp-quote mu4e-main-buffer-name)
display-buffer-same-window)) display-buffer-same-window))
;; special mark for junk (which is different from trash)
;; trash = delete later
;; 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 (add-to-list
'mu4e-marks 'mu4e-marks
'(junk :char ("j" . "┻") '(junk :char ("j" . "┻")
@ -3470,7 +3499,7 @@ Initialize by running =nd/mu-init=.
(mu4e--mark-check-target target) (mu4e--mark-check-target target)
"-N")))) "-N"))))
;; buttload of common settings I like
(setq mail-user-agent 'mu4e-user-agent (setq mail-user-agent 'mu4e-user-agent
message-kill-buffer-on-exit t message-kill-buffer-on-exit t
@ -3509,8 +3538,7 @@ Initialize by running =nd/mu-init=.
mu4e-view-prefer-html t mu4e-view-prefer-html t
;; compose ;; compose
mu4e-compose-signature-auto-include nil ;; sigs are annoying by default message-signature nil
mu4e-compose-signature "Thank you,\nNathan Dwarshuis"
;; aliases ;; aliases
mail-personal-alias-file (no-littering-expand-etc-file-name mail-personal-alias-file (no-littering-expand-etc-file-name
@ -3523,19 +3551,7 @@ Initialize by running =nd/mu-init=.
;; contexts (multiple inboxes) ;; contexts (multiple inboxes)
mu4e-context-policy 'pick-first mu4e-context-policy 'pick-first
mu4e-compose-context-policy 'ask-if-none mu4e-compose-context-policy 'ask-if-none)
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)))
;; enable visual line mode and spell checking ;; enable visual line mode and spell checking
(add-hook 'mu4e-compose-mode-hook 'turn-off-auto-fill) (add-hook 'mu4e-compose-mode-hook 'turn-off-auto-fill)
@ -3580,45 +3596,13 @@ Initialize by running =nd/mu-init=.
(plist-put msg :body-txt (mu4e~html2text-shell msg mu4e-html2text-command)) (plist-put msg :body-txt (mu4e~html2text-shell msg mu4e-html2text-command))
(plist-put msg :body-html nil))))) (plist-put msg :body-html nil)))))
(require 'smtpmail)
;; (require 'smtpmail-async)
(setq send-mail-function 'smtpmail-send-it (setq send-mail-function 'smtpmail-send-it
smtpmail-debug-info nil smtpmail-debug-info nil
auth-source-debug nil auth-source-debug nil
message-send-mail-function 'smtpmail-send-it) message-send-mail-function 'smtpmail-send-it)
(setq auth-sources '(password-store))
(defun nd/mu-init () ;; load instance-specific accounts
"Initialize the mu database" (load-file acnts-path))))
(->> mu4e-contexts
(--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)))
(defun nd/lookup-oauth-secret (type user)
(->> (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
local/lib/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
mu4e