init-mu4e.el 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ;;; mu4e
  2. ;;; REVIEW: Handle attachments in attached e-mails.
  3. ;;; See https://github.com/djcb/mu/issues/454#issuecomment-320616279.
  4. ;;; TODO: <tab> should go to next link in text e-mails too.
  5. ;; We need 'main' to setup pinentry-emacs for GPG.
  6. (require 'main)
  7. (require 'init-message)
  8. (when (require 'mu4e-maildirs-extension nil t)
  9. (mu4e-maildirs-extension))
  10. (defun ambrevar/mu4e-headers ()
  11. "Like `mu4e' but show the header view.
  12. Default to unread messages if the header buffer does not already exist."
  13. (interactive)
  14. (mu4e~start)
  15. (if (get-buffer "*mu4e-headers*" )
  16. (switch-to-buffer "*mu4e-headers*")
  17. (mu4e-headers-search "flag:unread AND NOT flag:trashed")))
  18. (setq
  19. ;; Attachments
  20. mu4e-attachment-dir "~/Downloads"
  21. mu4e-save-multiple-attachments-without-asking t
  22. ;; IMAP sync.
  23. mu4e-maildir "~/.cache/mail"
  24. mu4e-get-mail-command "mbsync -a"
  25. mu4e-update-interval 90
  26. mu4e-headers-auto-update nil ; Don't refresh so that we don't lose the current filter upon, e.g. reading e-mails.
  27. mu4e-change-filenames-when-moving t ; Preferred for mbsync according to the man page.
  28. ;; Don't bother me with context on startup.
  29. mu4e-context-policy nil
  30. ;; For reporting bugs, "C-x m", etc.
  31. mail-user-agent 'mu4e-user-agent
  32. mu4e-compose-dont-reply-to-self t
  33. ;; Display
  34. mu4e-headers-date-format "%F %R"
  35. mu4e-headers-fields '((:human-date . 16)
  36. (:flags . 6)
  37. (:size . 6)
  38. (:mailing-list . 10)
  39. (:from . 22)
  40. (:subject))
  41. mu4e-headers-time-format "%R"
  42. mu4e-view-show-addresses t
  43. mu4e-view-show-images t
  44. mu4e-view-image-max-width 800
  45. mu4e-hide-index-messages t
  46. ;; Gmail-style threading.
  47. mu4e-headers-include-related t
  48. ;; Gmail likes format=flowed(?)
  49. ;; mu4e-compose-format-flowed
  50. ;; 'sent is good for most providers. Gmail requires 'delete.
  51. mu4e-sent-messages-behavior 'sent
  52. ;; Because default completion can be extended (e.g. Helm, Ivy).
  53. mu4e-completing-read-function 'completing-read)
  54. ;;; Press "aV" to view in browser.
  55. (add-to-list 'mu4e-view-actions '("ViewInBrowser" . mu4e-action-view-in-browser) t)
  56. ;;; Custom bookmarks
  57. (add-to-list 'mu4e-bookmarks
  58. '("maildir:\".*inbox.*\" size:1M.." "Big inbox messages" ?b))
  59. ;;; Unicode chars for decoration might cause issues with some fonts or in terminals.
  60. ;;; https://github.com/djcb/mu/issues/733
  61. ;;; https://github.com/djcb/mu/issues/1062
  62. ;; (setq mu4e-use-fancy-chars t)
  63. ;;; REVIEW: Sorting in ascending order is impeded by
  64. ;;; `mu4e-search-results-limit': the 500 oldest e-mails will be displayed first.
  65. ;;; https://github.com/djcb/mu/issues/809
  66. ;; (setq mu4e-headers-sort-direction 'ascending)
  67. ;;; Since we sort in ascending direction, we default to the end of buffer.
  68. ;; (add-hook 'mu4e-headers-found-hook 'end-of-buffer)
  69. (add-hook 'mu4e-conversation-hook 'ambrevar/mu4e-select-dictionary)
  70. ;;; Make some e-mails stand out a bit.
  71. (set-face-foreground 'mu4e-unread-face "yellow")
  72. (set-face-attribute 'mu4e-flagged-face nil :inherit 'font-lock-warning-face)
  73. ;;; Confirmation on every mark execution is too slow to my taste.
  74. (defun ambrevar/mu4e-mark-execute-all-no-confirm ()
  75. (interactive)
  76. (mu4e-mark-execute-all t))
  77. (define-key mu4e-headers-mode-map "x" 'ambrevar/mu4e-mark-execute-all-no-confirm)
  78. (when (require 'helm-mu nil t)
  79. (dolist (map (list mu4e-headers-mode-map mu4e-main-mode-map mu4e-view-mode-map))
  80. (define-key map "s" 'helm-mu)))
  81. ;;; Org captures
  82. (when (require 'org-mu4e nil t)
  83. (dolist (map (list mu4e-view-mode-map mu4e-headers-mode-map))
  84. ;; Org mode has "C-c C-t" for 'org-todo.
  85. (define-key map (kbd "C-c C-t") 'org-mu4e-store-and-capture))
  86. (setq org-mu4e-link-query-in-headers-mode nil)
  87. (require 'init-org) ; For org-agenda-files
  88. (defun ambrevar/org-mail-date (&optional msg)
  89. (with-current-buffer (mu4e-get-headers-buffer)
  90. (mu4e-message-field (or msg (mu4e-message-at-point)) :date)))
  91. (add-to-list 'org-capture-templates
  92. `("t" "Mark e-mail in agenda" entry (file+headline ,(car org-agenda-files) "E-mails")
  93. "* %?\nSCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"++7d\" nil (ambrevar/org-mail-date)))\n%a\n")))
  94. (defun ambrevar/mu4e-kill-ring-save-message-id (&optional msg)
  95. "Save MSG's \"message-id\" field to the kill-ring.
  96. If MSG is nil, use message at point."
  97. (interactive)
  98. (kill-new (mu4e-message-field (or msg (mu4e-message-at-point)) :message-id)))
  99. (load (expand-file-name "mail/mu4e.el" (getenv "PERSONAL")) :noerror)
  100. (provide 'init-mu4e)