From 335e71292e4c8d38026a640413e404dab049ac25 Mon Sep 17 00:00:00 2001 From: Random936 Date: Mon, 4 Aug 2025 20:49:23 -0700 Subject: [PATCH] Added mu4e to emacs --- .emacs.d/config.org | 3 +- .emacs.d/email.org | 113 ++++++++++++++++++++++++++++++++++++++++++++ .mbsyncrc | 24 ++++++++++ 3 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 .emacs.d/email.org create mode 100644 .mbsyncrc diff --git a/.emacs.d/config.org b/.emacs.d/config.org index b1492e2..f8c5b91 100644 --- a/.emacs.d/config.org +++ b/.emacs.d/config.org @@ -374,5 +374,6 @@ Load other files: (jm/load-config-if-exists "~/.emacs.d/org.org") ; Org-mode (jm/load-config-if-exists "~/.emacs.d/dired.org") ; Dired Config (jm/load-config-if-exists "~/.emacs.d/lsp.org") ; Language Server Protocol -(jm/load-config-if-exists "~/.emacs.d/erc.org") ; Emacs IRC Client Config +(jm/load-config-if-exists "~/.emacs.d/erc.org") ; IRC Client Config +(jm/load-config-if-exists "~/.emacs.d/email.org") ; Mu4e Config #+end_src diff --git a/.emacs.d/email.org b/.emacs.d/email.org new file mode 100644 index 0000000..d919407 --- /dev/null +++ b/.emacs.d/email.org @@ -0,0 +1,113 @@ +* Custom Functions + +#+begin_src emacs-lisp +(defconst jm/email-filters-path "~/Nextcloud/filters.json") + +(defun jm/any-string-match-p (needles haystack) + (when (listp needles) + (let (result) + (dolist (needle needles result) + (setq result (or result (s-matches-p needle haystack))))))) + +(defun jm/load-email-filters (msg) + (let ((filters (append (json-read-file jm/email-filters-path) nil)) + (trash-flag (member + (car (mu4e-string-to-flags "T")) + (mu4e-message-field msg :flags))) + folder) + (if trash-flag + "/Trash" + (dolist (filter filters) + (let ((subject (mu4e-message-field msg :subject)) + (filter-folder (cdr (assoc-string "folder" filter))) + (subject-filters (append (cdr (assoc-string "subject" filter)) nil)) + (to-filters (append (cdr (assoc-string "to-contact" filter)) nil)) + (from-filters (append (cdr (assoc-string "from-contact" filter)) nil)) + (bcc-filters (append (cdr (assoc-string "bcc-contact" filter)) nil))) + (when (or (jm/any-string-match-p subject-filters subject) + (mu4e-message-contact-field-matches msg :to to-filters) + (mu4e-message-contact-field-matches msg :from from-filters) + (mu4e-message-contact-field-matches msg :bcc bcc-filters)) + (setq folder filter-folder)))) + (if folder folder "/Archive")))) +#+end_src + +* Mu4e + +This section contains the ~mu4e~ emacs specific configuration. + +#+begin_src emacs-lisp + +(use-package mu4e + :ensure nil + :bind ("C-x m" . mu4e) + :config + (add-hook 'mu4e-compose-mode-hook (lambda () (use-hard-newlines -1))) + + (setq mu4e-mu-binary (executable-find "mu") + mu4e-change-filenames-when-moving t ; Avoids syncing issues. + mu4e-search-results-limit 2000 ; Extend header view max message count. + mu4e-compose-format-flowed t) ; Disable hard line wrapping + + ;; Fix message citation style for gmail. + (setq message-cite-style message-cite-style-gmail + message-citation-line-format "On %a, %b %d, %Y at %H:%M %p %f wrote:" + message-citation-line-function 'message-insert-formatted-citation-line) + + ;; Refresh mail every X seconds. Set to 5 minutes currently + (setq mu4e-update-interval (* 5 60) + mu4e-get-mail-command "mbsync -a" + mu4e-maildir "~/.mail") + + ;; Config mu4e folders + (setq mu4e-drafts-folder "/Drafts" + mu4e-sent-folder "/Sent" + mu4e-trash-folder "/Trash" + mu4e-refile-folder #'jm/load-email-filters) + + ;; Config mu4e bookmarks + (setq mu4e-bookmarks + '((:name "Filtered unread messages" :query "flag:unread AND (maildir:/Archive OR maildir:/INBOX) AND NOT flag:trashed" :key ?u) + (:name "All unread messages" :query "flag:unread" :key ?U) + (:name "Today's messages" :query "date:today..now" :key ?t) + (:name "Last 7 days" :query "date:7d..now" :hide-unread t :key ?w) + (:name "Flagged messages" :query "flag:flagged" :key ?f))) + + (setq mu4e-maildir-shortcuts + ;; Proton folders + '((:maildir "/INBOX" :key ?i) + (:maildir "/Archive" :key ?a) + (:maildir "/Drafts" :key ?d) + (:maildir "/Sent" :key ?s) + (:maildir "/Spam" :key ?S) + (:maildir "/Trash" :key ?t) + + ;; My folders + (:maildir "/Folders/Finance" :key ?f) + (:maildir "/Folders/Packages" :key ?p) + (:maildir "/Folders/Work" :key ?w) + (:maildir "/Folders/Club" :key ?c) + (:maildir "/Folders/UCSC" :key ?u) + (:maildir "/Folders/Newsletters" :key ?n)))) +#+end_src + +Adding some configuration to correct ~mu4e~'s default values. +#+begin_src emacs-lisp +(setq user-full-name "Jaden Provost Maxwell-Comfort") +(setq user-mail-address "jadenprovost@proton.me") +#+end_src + +* SMTP + +In order to send mail with ~mu4e~, you must also configure an SMTP client. Based on the ~mu4e~ wiki, I was able to shamelessly steal some of the config for the gmail configuration found [[https://www.djcbsoftware.nl/code/mu/mu4e/Gmail-configuration.html][here]]. + +#+begin_src emacs-lisp +(use-package smtpmail + :after mu4e + :config + (setq smtpmail-stream-type 'starttls + smtpmail-smtp-server "127.0.0.1" + smtpmail-smtp-service 1025)) + +(setq send-mail-function 'smtpmail-send-it) +#+end_src diff --git a/.mbsyncrc b/.mbsyncrc new file mode 100644 index 0000000..d567752 --- /dev/null +++ b/.mbsyncrc @@ -0,0 +1,24 @@ +IMAPAccount protonmail +Host 127.0.0.1 +User jadenprovost@proton.me +PassCmd "rbw get 'protonmail-bridge'" +Port 1143 +TLSType STARTTLS +AuthMechs LOGIN +CertificateFile ~/.config/protonmail/bridge-v3/cert.pem + +IMAPStore protonmail-remote +Account protonmail + +MaildirStore protonmail-local +Path ~/.mail/ +Inbox ~/.mail/INBOX +SubFolders Verbatim + +Channel protonmail +Far :protonmail-remote: +Near :protonmail-local: +Patterns * "!All Mail" +Create Both +Expunge Both +SyncState *