summaryrefslogtreecommitdiff
path: root/lisp/email.el
blob: bb5dde78ac5bbe1ee0b0f2a997f66ce57827515a (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
(require 'mu4e)
(require 'org-mu4e)
(require 'mu4e-contrib)

(setq shr-color-visible-luminance-min 30)

(setq mu4e-get-mail-command "offlineimap"
      mu4e-compose-signature-auto-include nil
      mu4e-compose-dont-reply-to-self t
      mu4e-update-interval 60
      mu4e-headers-include-related t)

(setq mu4e-use-fancy-chars t)
(setq mu4e-headers-seen-mark    '("" . ""))
(setq mu4e-headers-unread-mark  '("u" . "✉"))

;; Don't update list of emails automatically.  I update the list
;; manually with "g".
(setq mu4e-headers-auto-update nil)

(setq mu4e-view-show-addresses t)
(setq mu4e-hide-index-messages t)
(setq mu4e-html2text-command 'mu4e-shr2text)
(setq mu4e-view-show-images t)
;; use imagemagick, if available
(when (fboundp 'imagemagick-register-types)
  (imagemagick-register-types))

(setq mu4e-maildir        "~/Mail"             ;; top-level Maildir
      mu4e-attachment-dir "~/Downloads"
      mu4e-sent-folder    "/private/Sent"      ;; folder for sent messages
      mu4e-drafts-folder  "/private/Drafts"    ;; unfinished messages
      mu4e-trash-folder   "/private/Trash"     ;; trashed messages
      mu4e-refile-folder  "/private/Archives"  ;; saved messages
      user-mail-address   "rekado@elephly.net")

(defvar my-mu4e-account-alist
  '(("private"
     (mu4e-sent-folder   "/private/Sent")
     (mu4e-drafts-folder "/private/Drafts")
     (mu4e-trash-folder  "/private/Trash")
     (mu4e-refile-folder "/private/Archives"))))

(setq mu4e-user-mail-address-list
      (mapcar (lambda (account) (cadr (assq 'user-mail-address account)))
              my-mu4e-account-alist))

(defun my-mu4e-set-account ()
  "Set the account for composing a message."
  (let* ((account
          (if mu4e-compose-parent-message
              (let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
                (string-match "/\\(.*?\\)/" maildir)
                (match-string 1 maildir))
            (completing-read (format "Compose with account: (%s) "
                                     (mapconcat #'(lambda (var) (car var))
                                                my-mu4e-account-alist "/"))
                             (mapcar #'(lambda (var) (car var)) my-mu4e-account-alist)
                             nil t nil nil (caar my-mu4e-account-alist))))
         (account-vars (cdr (assoc account my-mu4e-account-alist))))
    (if account-vars
        (mapc #'(lambda (var)
                  (set (car var) (cadr var)))
              account-vars)
      (error "No email account found"))))

(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)

;; pretty quotes!
(add-hook 'message-mode-hook 'typo-mode)

(let ((guix     "(list:guix-devel@gnu.org OR list:bug-guix@gnu.org OR list:help-guix@gnu.org OR list:guix-sysadmin@gnu.org OR list:guix-security.gnu.org)")
      (guile    "(list:guile-user@gnu.org OR list:guile-devel@gnu.org OR list:bug-guile@gnu.org)")
      (emacs    "(list:emacs-devel@gnu.org)")
      (lilypond "(list:lilypond-devel@gnu.org)")
      (eoma     "(list:arm-netbook@lists.phcomp.co.uk)")
      (fsfe     "(subject:\"Willkommen in der FSFE\" list:berlin-bounces@lists.fsfe.org OR list:berlin-owner@lists.fsfe.org OR list:coordinators@lists.fsfe.org OR list:berlin@lists.fsfe.org OR list:newsletter-en@fsfeurope.org OR list:newsletter-de@fsfeurope.org)")
      (dojo     "(list:coderdojo-berlin-discussion@googlegroups.com OR to:hello@fhain.coderdojo.berlin)")
      (unread   "(flag:unread AND NOT flag:trashed)")
      (me       "(body:rekado OR body:Ricardo)"))
  (setq mu4e-bookmarks
        (list
         ;; TODO: don't match my own signature
         (list (concat me " " unread)
               "Mentioning me (unread)" ?R)
         (list "maildir:\"/private/INBOX\""
               "Personal inbox"  ?i)
         (list "date:today..now"
               "Today's messages" ?t)
         (list "date:today..now"
               "Last 7 days" ?w)
         (list (concat "maildir:\"/private/INBOX\"" " " unread)
               "Unread messages (private)"  ?u)
         (list (concat guix " " unread)
               "Guix"  ?1)
         (list (concat guile " " unread)
               "Guile"  ?2)
         (list (concat lilypond " " unread)
               "Lilypond"  ?3)
         (list (concat fsfe " " unread)
               "FSFE"  ?4)
         (list (concat dojo " " unread)
               "CoderDojo"  ?5)
         (list (concat eoma " " unread)
               "EOMA68"  ?6)
         (list (concat emacs " " unread)
               "Emacs"  ?7)
         (list (concat "maildir:\"/private/mailinglists\""
                       " " unread
                       " NOT " guix
                       " NOT " guile
                       " NOT " lilypond
                       " NOT " fsfe
                       " NOT " eoma
                       " NOT " emacs
                       " NOT " dojo)
               "Unread list messages"  ?m)
         (list "maildir:\"/private/INBOX\" flag:flagged"
               "Flagged (private)"  ?f)
         (list "maildir:\"/mdc-personal/INBOX\" flag:flagged"
               "Flagged (work)"  ?g))))

; set up email sending with msmtp
(setq mail-user-agent 'mu4e-user-agent)
(setq mail-specify-envelope-from t)
(setq mail-envelope-from 'header)

(setq message-kill-buffer-on-exit t)
(setq message-sendmail-envelope-from 'header)
(setq message-send-mail-function 'message-send-mail-with-sendmail)

;;use msmtp instead of sendmail
(setq sendmail-program "~/.guix-profile/bin/msmtp")

(global-set-key (kbd "<f12>") 'mu4e)

;; Crypto
(setq mml2015-encrypt-to-self t)
(setq mml2015-sign-with-sender t)

(add-hook 'mu4e-compose-mode-hook
  (defun my/maybe-reply-encrypted ()
    "Encrypt automatically if parent message was also encrypted."
    (let ((msg mu4e-compose-parent-message))
      (when (and msg (member 'encrypted (mu4e-message-field msg :flags)))
        (mml-secure-message-sign-encrypt)))))

(add-hook 'mu4e-view-mode-hook
  (defun my/maybe-decrypt-inline ()
    "Attempt to decrypt inline PGP messages automatically."
    (save-excursion
      (goto-char (point-min))
      (re-search-forward "-----BEGIN PGP MESSAGE-----$" nil t)
      (let ((armor-start (match-beginning 0)))
        (when armor-start
          (let ((armor-end (re-search-forward "^-----END PGP MESSAGE-----$" nil t)))
            (when armor-end
              ;; Don't ask if I want to replace the text.  Just do it.
              (flet ((yes-or-no-p (&rest args) t)
                     (y-or-n-p (&rest args) t))
                (epa-decrypt-armor-in-region armor-start armor-end)))))))))