-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-mail.el
160 lines (123 loc) · 5.23 KB
/
my-mail.el
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
;;; my-mail.el --- Mail Configuration
;; Copyright (C) 2019 Julien Masson
;; Author: Julien Masson <massonju.eseo@gmail.com>
;; URL: https://github.com/JulienMasson/jm-config/
;; This file is part of GNU Emacs.
;; GNU Emacs 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.
;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Code:
;; default citation format
(setq message-citation-line-format "On %a %d %b %Y at %R, %f wrote:\n")
(setq message-citation-line-function 'message-insert-formatted-citation-line)
;; default message signature
(setq message-signature "Julien Masson")
;; hide In-Reply-To field
(add-to-list 'message-hidden-headers "^In-Reply-To:")
;; message buffer will be killed after sending a message
(setq message-kill-buffer-on-exit t)
;; jmail
(require 'jmail)
;; set Mail User Agent
(setq mail-user-agent 'jmail-user-agent)
;; set top maildir
(setq jmail-top-maildir "~/.cache/mails")
;; set mbsync config file
(setq jmail-sync-config-file (concat my-private-dotfiles-path ".mbsyncrc"))
;; set msmtp config file
(setq jmail-smtp-config-file (concat my-private-dotfiles-path ".msmtprc"))
;; default query options
(setq jmail-default-query-options '(:thread t :auto-fold-thread t :related t))
;; sync/refresh every 3 mins
(setq jmail-sync-refresh-every (* 3 60))
;; display html by default
(setq jmail-view-html-default-view t)
;; enable org-msg for jmail
(jmail-org-msg-enable)
;; org msg
(require 'org-msg)
(setq org-msg-options "html-postamble:nil H:5 num:nil ^:{} toc:nil author:nil email:nil \\n:t")
(setq org-msg-startup "hidestars noindent inlineimages")
(setq org-msg-default-alternatives '(text html))
(setq org-msg-convert-citation t)
(setq org-msg-signature "
#+begin_signature
Julien Masson
#+end_signature")
;; do not improve reply header
(defun org-msg-improve-reply-header (xml css))
;; cached unread data
(defvar jmail-unread-data-cached nil)
(defun jmail--cache-unread-data (props count)
(when-let ((query (plist-get props :query)))
(if (> count 0)
(if (assoc query jmail-unread-data-cached)
(setcdr (assoc query jmail-unread-data-cached) count)
(add-to-list 'jmail-unread-data-cached (cons query count)))
(when (assoc query jmail-unread-data-cached)
(setq jmail-unread-data-cached
(assoc-delete-all query jmail-unread-data-cached #'string=))))))
(add-hook 'jmail-unread-count-hook #'jmail--cache-unread-data)
(defun jmail--clear-cache-unread ()
(setq jmail-unread-data-cached nil))
(add-hook 'jmail-quit-hook #'jmail--clear-cache-unread)
;; send patch
(require 'send-patch)
;; setup jmail env when sending patchs
(defun send-patch-setup-jmail-env ()
(when-let ((accounts (jmail-get-accounts jmail-smtp-config-file))
(from (message-fetch-field "From")))
(pcase-let ((`(,_ ,email) (gnus-extract-address-components from)))
(when-let ((account (cl-find-if (lambda (e) (string= email (plist-get (cdr e) :email)))
accounts)))
(jmail-compose-mode)
(jmail-capf-setup)
(jmail-compose-setup-send-mail)
(setq-local mail-host-address (replace-regexp-in-string ".+@" "" email))
(jmail-compose-set-extra-arguments (car account) email)))))
(add-hook 'send-patch-compose-hook 'send-patch-setup-jmail-env)
;; add kernel recipients function
(defun patch-get-from-field (patch)
(with-temp-buffer
(insert-file-contents patch nil 0 256)
(goto-char (point-min))
(while (re-search-forward "^From: " nil t))
(buffer-substring (point) (line-end-position))))
(defun send-patch-get-recipients-kernel (patchs)
(let* ((cmd (concat "./scripts/get_maintainer.pl " patch))
(receivers (split-string (shell-command-to-string cmd) "\n"))
(user (patch-get-from-field (car patchs)))
(cc `("linux-kernel@vger.kernel.org" ,(if user user)))
to)
(dolist (user receivers)
(save-match-data
(when (string-match "\\(.*\\) \(\\(.*\\):.*" user)
(if (string-equal (match-string 2 user) "maintainer")
(add-to-list 'to (match-string 1 user))
(add-to-list 'cc (match-string 1 user))))))
(list to cc)))
(add-to-list 'send-patch-get-recipients-funcs
(cons "Kernel" 'send-patch-get-recipients-kernel) t)
;; add uboot recipients function
(defun send-patch-get-recipients-uboot (patch)
(let* ((cmd (concat "./scripts/get_maintainer.pl " patch))
(receivers (split-string (shell-command-to-string cmd) "\n"))
(to '("u-boot@lists.denx.de"))
cc)
(dolist (user receivers)
(save-match-data
(when (string-match "\\(.*\\) \(\\(.*\\):.*" user)
(if (string-equal (match-string 2 user) "maintainer")
(add-to-list 'cc (match-string 1 user))
(add-to-list 'to (match-string 1 user))))))
(list to cc)))
(add-to-list 'send-patch-get-recipients-funcs
(cons "U-Boot" 'send-patch-get-recipients-uboot) t)
(provide 'my-mail)