[spacemacs] add my mu4e contrib layer
[~bandali/configs] / spacemacs / .emacs.d / private / mu4e / packages.el
1 ;;; packages.el --- mu4e Layer packages File for Spacemacs
2 ;;
3 ;; Copyright (c) 2012-2014 Sylvain Benner
4 ;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
5 ;; Copyright (c) 2015 Amin Bandali
6 ;;
7 ;; Authors: Amin Bandali <me@aminb.org>
8 ;; Sylvain Benner <sylvain.benner@gmail.com>
9 ;; URL: https://github.com/aminb/dotfiles
10 ;;
11 ;; This file is not part of GNU Emacs; nor that of spacemacs.
12 ;;
13 ;;; License: GPLv3
14
15 (defvar mu4e-packages
16 '(
17 ;; mu4e is not in any repos, so it's commented
18 ;; mu4e
19 smtpmail
20 )
21 "List of all packages to install and/or initialize. Built-in packages
22 which require an initialization must be listed explicitly in the list.")
23
24 (defvar mu4e-excluded-packages '()
25 "List of packages to exclude.")
26
27 (defun get-string-from-file (filePath)
28 "Return filePath's file content."
29 (with-temp-buffer
30 (insert-file-contents filePath)
31 (buffer-string)))
32 ;; thanks to “Pascal J Bourguignon” and “TheFlyingDutchman
33 ;; 〔zzbba…@aol.com〕”. 2010-09-02
34
35 (defun get-passwd-file (name)
36 "Return name's passwd file content"
37 (get-string-from-file (concat "/home/amin/.passwd/" name)))
38
39 (require 'mu4e)
40 (require 'smtpmail)
41 (setq
42 mu4e-get-mail-command "offlineimap" ;; or fetchmail, or ...
43 mu4e-update-interval 300 ;; update every 5 minutes
44 mu4e-sent-folder "/aminb/Sent"
45 mu4e-drafts-folder "/aminb/Drafts"
46 mu4e-trash-folder "/aminb/Trash"
47 user-mail-address (get-passwd-file "aminb-mail")
48 smtpmail-default-smtp-server "mail.aminb.org"
49 smtpmail-local-domain "aminb.org"
50 smtpmail-smtp-server "mail.aminb.org"
51 smtpmail-stream-type 'ssl
52 smtpmail-smtp-service 465)
53
54 (defvar my-mu4e-account-alist
55 '(("aminb"
56 (mu4e-sent-folder "/aminb/Sent")
57 (mu4e-drafts-folder "/aminb/Drafts")
58 (mu4e-trash-folder "/aminb/Trash")
59 (user-mail-address (get-passwd-file "aminb-mail"))
60 (user-full-name "Amin Bandali")
61 (smtpmail-default-smtp-server "mail.aminb.org")
62 (smtpmail-local-domain "aminb.org")
63 (smtpmail-smtp-user (get-passwd-file "aminb-user"))
64 (smtpmail-smtp-server "mail.aminb.org")
65 (smtpmail-stream-type ssl)
66 (smtpmail-smtp-service 465))
67 ("Gmail"
68 (mu4e-sent-folder "/Gmail/[Gmail].Sent Mail")
69 (mu4e-drafts-folder "/Gmail/[Gmail].Drafts")
70 (mu4e-trash-folder "/Gmail/[Gmail].Trash")
71 (user-mail-address (get-passwd-file "gmail-mail"))
72 (user-full-name "Amin Bandali")
73 (smtpmail-default-smtp-server "smtp.gmail.com")
74 (smtpmail-local-domain "gmail.com")
75 (smtpmail-smtp-user (get-passwd-file "gmail-mail"))
76 (smtpmail-smtp-server "smtp.gmail.com")
77 (smtpmail-stream-type ssl)
78 (smtpmail-smtp-service 465))))
79
80 (defun my-mu4e-set-account ()
81 "Set the account for composing a message."
82 (let* ((account
83 (if mu4e-compose-parent-message
84 (let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
85 (string-match "/\\(.*?\\)/" maildir)
86 (match-string 1 maildir))
87 (completing-read (format "Compose with account: (%s) "
88 (mapconcat #'(lambda (var) (car var))
89 my-mu4e-account-alist "/"))
90 (mapcar #'(lambda (var) (car var)) my-mu4e-account-alist)
91 nil t nil nil (caar my-mu4e-account-alist))))
92 (account-vars (cdr (assoc account my-mu4e-account-alist))))
93 (if account-vars
94 (mapc #'(lambda (var)
95 (set (car var) (cadr var)))
96 account-vars)
97 (error "No email account found"))))
98
99 (add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)
100
101
102 ;; Shortcut for mu4e.
103 (global-set-key (kbd "C-c m") 'mu4e)
104 (evil-leader/set-key "am" 'mu4e)
105
106
107 ;; A special version of the gnus-dired-mail-buffers function
108 ;; that understands mu4e buffers as well
109 (require 'gnus-dired)
110 ;; make the `gnus-dired-mail-buffers' function also work on
111 ;; message-mode derived modes, such as mu4e-compose-mode
112 (defun gnus-dired-mail-buffers ()
113 "Return a list of active message buffers."
114 (let (buffers)
115 (save-current-buffer
116 (dolist (buffer (buffer-list t))
117 (set-buffer buffer)
118 (when (and (derived-mode-p 'message-mode)
119 (null message-sent-message-via))
120 (push (buffer-name buffer) buffers))))
121 (nreverse buffers)))
122
123 (setq gnus-dired-mail-mode 'mu4e-user-agent)
124 (add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode)
125
126 (require 'mu4e-contrib)
127 (setq mu4e-html2text-command 'mu4e-shr2text
128 mu4e-view-html-plaintext-ratio-heuristic 10
129 mu4e-view-prefer-html t)
130
131 ;; For each package, define a function mu4e/init-<package-mu4e>
132 ;;
133 ;; (defun mu4e/init-my-package ()
134 ;; "Initialize my package"
135 ;; )
136 ;;
137 ;; Often the body of an initialize function uses `use-package'
138 ;; For more info on `use-package', see readme:
139 ;; https://github.com/jwiegley/use-package