[spacemacs] sync up with latest template
[~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 mu4e-compose-signature
49 (concat
50 "Amin Bandali\n"
51 "<aminb.org>\n")
52 smtpmail-default-smtp-server "mail.aminb.org"
53 smtpmail-local-domain "aminb.org"
54 smtpmail-smtp-server "mail.aminb.org"
55 smtpmail-stream-type 'ssl
56 smtpmail-smtp-service 465)
57
58 (defvar my-mu4e-account-alist
59 '(("aminb"
60 (mu4e-sent-folder "/aminb/Sent")
61 (mu4e-drafts-folder "/aminb/Drafts")
62 (mu4e-trash-folder "/aminb/Trash")
63 (user-mail-address (get-passwd-file "aminb-mail"))
64 (user-full-name "Amin Bandali")
65 (smtpmail-default-smtp-server "mail.aminb.org")
66 (smtpmail-local-domain "aminb.org")
67 (smtpmail-smtp-user (get-passwd-file "aminb-user"))
68 (smtpmail-smtp-server "mail.aminb.org")
69 (smtpmail-stream-type ssl)
70 (smtpmail-smtp-service 465))
71 ("Gmail"
72 (mu4e-sent-folder "/Gmail/[Gmail].Sent Mail")
73 (mu4e-drafts-folder "/Gmail/[Gmail].Drafts")
74 (mu4e-trash-folder "/Gmail/[Gmail].Trash")
75 (user-mail-address (get-passwd-file "gmail-mail"))
76 (user-full-name "Amin Bandali")
77 (smtpmail-default-smtp-server "smtp.gmail.com")
78 (smtpmail-local-domain "gmail.com")
79 (smtpmail-smtp-user (get-passwd-file "gmail-mail"))
80 (smtpmail-smtp-server "smtp.gmail.com")
81 (smtpmail-stream-type ssl)
82 (smtpmail-smtp-service 465))))
83
84 (defun my-mu4e-set-account ()
85 "Set the account for composing a message."
86 (let* ((account
87 (if mu4e-compose-parent-message
88 (let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
89 (string-match "/\\(.*?\\)/" maildir)
90 (match-string 1 maildir))
91 (completing-read (format "Compose with account: (%s) "
92 (mapconcat #'(lambda (var) (car var))
93 my-mu4e-account-alist "/"))
94 (mapcar #'(lambda (var) (car var)) my-mu4e-account-alist)
95 nil t nil nil (caar my-mu4e-account-alist))))
96 (account-vars (cdr (assoc account my-mu4e-account-alist))))
97 (if account-vars
98 (mapc #'(lambda (var)
99 (set (car var) (cadr var)))
100 account-vars)
101 (error "No email account found"))))
102
103 (add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)
104
105
106 ;; Shortcut for mu4e.
107 (global-set-key (kbd "C-c m") 'mu4e)
108 (evil-leader/set-key "am" 'mu4e)
109
110
111 ;; A special version of the gnus-dired-mail-buffers function
112 ;; that understands mu4e buffers as well
113 (require 'gnus-dired)
114 ;; make the `gnus-dired-mail-buffers' function also work on
115 ;; message-mode derived modes, such as mu4e-compose-mode
116 (defun gnus-dired-mail-buffers ()
117 "Return a list of active message buffers."
118 (let (buffers)
119 (save-current-buffer
120 (dolist (buffer (buffer-list t))
121 (set-buffer buffer)
122 (when (and (derived-mode-p 'message-mode)
123 (null message-sent-message-via))
124 (push (buffer-name buffer) buffers))))
125 (nreverse buffers)))
126
127 (setq gnus-dired-mail-mode 'mu4e-user-agent)
128 (add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode)
129
130 (require 'mu4e-contrib)
131 (setq mu4e-html2text-command 'mu4e-shr2text
132 mu4e-view-html-plaintext-ratio-heuristic 10
133 mu4e-view-prefer-html t)
134
135 ;; For each package, define a function mu4e/init-<package-mu4e>
136 ;;
137 ;; (defun mu4e/init-my-package ()
138 ;; "Initialize my package"
139 ;; )
140 ;;
141 ;; Often the body of an initialize function uses `use-package'
142 ;; For more info on `use-package', see readme:
143 ;; https://github.com/jwiegley/use-package