summaryrefslogtreecommitdiff
path: root/.emacs.d/modules/thanos-mu4e.el
blob: c1fffd031eaa5b0a191d09ee14f03004830c74da (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
;;; thanos-mu4e.el --- mu4e configuration            -*- lexical-binding: t; -*-

;; Copyright (C) 2023  Thanos Apollo

;; Author: Thanos Apollo <[email protected]>
;; Keywords: extensions

;; 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 'smtpmail)


(when is-zeus
  (add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e/"))

(require 'mu4e)

(when is-zeus (setf mu4e-update-interval (* 10 60)))

(setf mu4e-get-mail-command "mbsync -a")

(defun set-mu4e-context (context-name full-name mail-address signature)
  "Return a mu4e context named CONTEXT-NAME with :match-func matching
    folder name CONTEXT-NAME in Maildir. The context's `user-mail-address',
    `user-full-name' and `mu4e-compose-signature'`smtpmail-smpt-server' is set to MAIL-ADDRESS
    FULL-NAME SIGNATURE and SERVER respectively.
    Special folders are set to context specific folders."
  (let ((dir-name (concat "/" context-name)))
    (make-mu4e-context
     :name context-name
     ;; we match based on the maildir of the message
     :match-func
     `(lambda (msg)
	(when msg
	  (string-match-p
	   ,(concat "^" dir-name)
	   (mu4e-message-field msg :maildir))))
     :vars
     `((user-mail-address    . ,mail-address)
       (user-full-name       . ,full-name)
       (mu4e-sent-folder     . ,(concat dir-name "/Sent"))
       (mu4e-drafts-folder   . ,(concat dir-name "/Drafts"))
       (mu4e-trash-folder    . ,(concat dir-name "/Trash"))
       (mu4e-trash-folder    . ,(concat dir-name "/Starred"))
       (mu4e-refile-folder   . ,(concat dir-name "/Archive"))
       (mu4e-compose-signature . ,signature)))))
;;Fixing duplicate UID errors when using mbsync and mu4e
(setf mu4e-change-filenames-when-moving t)

(setf mu4e-maildir-shortcuts
      '(("/Public/Inbox" . ?I)
	("/Inbox" . ?i)
	("/Sent" . ?s)
	("/Emacs/dev" . ?e)))

(setf mu4e-contexts
      (list
       (make-mu4e-context
	:name "Public"
	:match-func
	(lambda (msg)
	  (when msg
	    (string-prefix-p "/" (mu4e-message-field msg :maildir))))
	:vars '((user-mail-address . "[email protected]")
		(user-full-name    . "Thanos Apollo")
		(mu4e-drafts-folder  . "/Drafts")
		(mu4e-sent-folder  . "/Sent")
		(mu4e-refile-folder  . "/Archive")
		(mu4e-trash-folder  . "/Trash")))
       (make-mu4e-context
	:name "Fastmail"
	:match-func
	(lambda (msg)
	  (when msg
	    (string-prefix-p "/" (mu4e-message-field msg :maildir))))
	:vars '((user-mail-address . "[email protected]")
		(user-full-name    . "Thanos Apollo")
		(mu4e-drafts-folder  . "/Drafts")
		(mu4e-sent-folder  . "/Sent")
		(mu4e-refile-folder  . "/Archive")
		(mu4e-trash-folder  . "/Trash")))))

(setf message-send-mail-function 'smtpmail-send-it
      smtpmail-smtp-server "smtp.fastmail.com"
      smtpmail-smtp-service 465
      smtpmail-stream-type 'ssl
      mu4e-compose-signature "\nThanos Apollo\nhttps://thanosapollo.com"
      mu4e-compose-context-policy 'ask
      mu4e-compose-format-flowed t)

(setf mu4e-view-actions
      (delete-dups
       (append
	'(("gapply git patches" . mu4e-action-git-apply-patch)
	  ("mgit am patch" . mu4e-action-git-apply-mbox)
	  ("bb4 am patch" . mu4e-action-git-apply-b4)
	  ("ssetup reword list with b4" . mu4e-action-setup-reword-b4)
	  ("crun checkpatch script" . my-mu4e-action-run-check-patch)
	  ("MCheck if merged" . my-mu4e-action-check-if-merged)))))

(setf mu4e-view-actions
      (delete-dups
       (append
	'(("gapply git patches" . mu4e-action-git-apply-patch)
	  ("mgit am patch" . mu4e-action-git-apply-mbox)
	  ("bb4 am patch" . mu4e-action-git-apply-b4)
	  ("ssetup reword list with b4" . mu4e-action-setup-reword-b4)
	  ("crun checkpatch script" . my-mu4e-action-run-check-patch)
	  ("MCheck if merged" . my-mu4e-action-check-if-merged)))))

(require 'mu4e-alert)
(mu4e-alert-enable-mode-line-display)

(define-key thanos/applications-map (kbd "m") 'mu4e)

(provide 'thanos-mu4e)
;;; thanos-mu4e.el ends here