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