Instantly share code, notes, and snippets.

@agzam /.mbsyncrc
Last active Aug 24, 2018

Embed
What would you like to do?
Emacs mail: mu4e + mbsync configs
Create Both
Expunge Both
SyncState *
IMAPAccount home
Host imap.gmail.com
User home@email.com
PassCmd "gpg2 -q --for-your-eyes-only --no-tty -d ~/.mail/.mailpass-home.gpg"
SSLType IMAPS
AuthMechs LOGIN
IMAPStore home-remote
Account home
MaildirStore home-local
Subfolders Verbatim
Path ~/.mail/home/
Inbox ~/.mail/home/inbox
Channel home-inbox
Master :home-remote:
Slave :home-local:
Patterns "*" "![Gmail]/Spam"
Create Both
SyncState *

This is a typical configuration that can be used for setting up mu4e as email client and isync as the transport. Two gmail accounts are used.

Install:

  • isync/mbsync
  • mu4e
  • mu4e-maildirs-extension (Emacs package)

Replace instances of home@email.com, work@email.com, full-name, signature etc.

.mbsyncrc Includes only part for "home", "work" email setup is similar

(with-eval-after-load 'mu4e
(setq mu4e-maildir "~/.mail"
mu4e-get-mail-command "mbsync -a --verbose"
mu4e-update-interval 600
mu4e-compose-signature-auto-include nil
mu4e-view-show-images t
mu4e-view-show-addresses t
mu4e-enable-notifications nil
mu4e-enable-mode-line t
mu4e-headers-skip-duplicates t
;; rename files when moving, needed for mbsync
mu4e-change-filenames-when-moving t
mu4e-compose-dont-reply-to-self t
mu4e-compose-format-flowed nil
fill-flowed-encode-column 280
mu4e-user-mail-address-list '("home@email.com" "work@email.com")
mu4e-compose-complete-only-personal t
mu4e-enable-async-operations t
org-mu4e-link-query-in-headers-mode nil
org-mu4e-convert-to-html t
;; customize the reply-quote-string
message-citation-line-format "On %a %d %b %Y at %R, %f wrote:\n"
;; choose to use the formatted string
message-citation-line-function 'message-insert-formatted-citation-line)
(setq smtpmail-smtp-server "smtp.gmail.com"
smtpmail-smtp-service 587
smtpmail-queue-mail nil
smtpmail-queue-dir "~/.mail/queue/cur"
send-mail-function 'smtpmail-send-it
message-send-mail-function 'smtpmail-send-it
mu4e-sent-messages-behavior 'delete
mail-envelope-from 'header
mail-user-agent 'mu4e-user-agent
smtpmail-debug-info t
smtpmail-debug-verb t)
(defun mu4e-message-maildir-matches (msg rx)
(string-match rx (mu4e-message-field msg :maildir)))
(setq
mu4e-compose-context-policy 'always-ask
mu4e-contexts
`(,(make-mu4e-context
:name "home"
:enter-func (lambda ()
(mu4e-message "Switch to home@mail.com"))
;; leave-func not defined
:match-func (lambda (msg)
(when msg
(mu4e-message-maildir-matches msg "^/home/")
(mu4e-message-contact-field-matches msg :to "home@email.com")
))
:vars '((mu4e-sent-folder . "/home/[Gmail]/Sent Mail")
(mu4e-trash-folder . "/home/[Gmail]/Trash")
(mu4e-refile-folder . "/home/[Gmail]/All Mail")
(mu4e-drafts-folder . "/home/[Gmail]/Drafts")
(user-mail-address . "home@email.com")
(user-full-name . "Ag Ibragimov")
(smtpmail-smtp-user . "work@mail.com")
(mu4e-compose-signature . (concat "Thanks,\n" "Ag\n"))))
,(make-mu4e-context
:name "work"
:enter-func (lambda ()
(mu4e-message "Switch to work@email.com"))
;; leave-func not defined
:match-func (lambda (msg)
(when msg
(mu4e-message-maildir-matches msg "^/work/")
;; (mu4e-message-contact-field-matches msg :to "@mayvenn.com")
))
:vars '((mu4e-sent-folder . "/work/[Gmail]/Sent Mail")
(mu4e-trash-folder . "/work/[Gmail]/Trash")
(mu4e-refile-folder . "/work/[Gmail]/All Mail")
(mu4e-drafts-folder . "/work/[Gmail]/Drafts")
(user-mail-address . "work@email.com")
(user-full-name . "Ag Ibragimov")
(smtpmail-smtp-user . "work@email.com")
(mu4e-compose-signature . (concat "Thanks,\n" "Ag\n"))))))
(add-hook 'mu4e-compose-mode-hook #'turn-off-auto-fill)
(add-hook 'mu4e-compose-mode-hook #'spacemacs/toggle-visual-line-navigation-on)
(setq mu4e-view-actions
'(("capture message" . mu4e-action-capture-message)
("view in browser" . mu4e-action-view-in-browser)
("show this thread" . mu4e-action-show-thread)
("View as pdf" . mu4e-action-view-as-pdf)))
(add-to-list
'mu4e-header-info-custom
'(:foldername . (:name "Folder information"
:shortname "Folder"
:help "Message short storage information"
:function (lambda (msg)
(let ((shortaccount)
(maildir (or (mu4e-message-field msg :maildir) ""))
(mailinglist (or (mu4e-message-field msg :mailing-list) "")))
(if (not (string= mailinglist ""))
(setq mailinglist (mu4e-get-mailing-list-shortname mailinglist)))
(when (not (string= maildir ""))
(setq shortaccount
(substring
(replace-regexp-in-string "^/\\(\\w+\\)/.*$" "\\1" maildir)
0 1))
(setq maildir (replace-regexp-in-string ".*/\\([^/]+\\)$" "\\1" maildir))
(if (> (length maildir) 15)
(setq maildir (concat (substring maildir 0 14) "")))
(setq maildir (concat "[" shortaccount "] " maildir)))
(cond
((and (string= maildir "")
(not (string= mailinglist "")))
mailinglist)
((and (not (string= maildir ""))
(string= mailinglist ""))
maildir)
((and (not (string= maildir ""))
(not (string= mailinglist "")))
(concat maildir " (" mailinglist ")"))
(t "")))))))
(defun ed/get-mail-header (header-name path)
(replace-regexp-in-string
"[ \t\n]*$"
""
(shell-command-to-string
(concat "/usr/bin/sed -n '/^" header-name ":/I{:loop t;h;n;/^ /{H;x;s/\\n//;t loop};x;p}' '" path "' | sed -n 's/^" header-name ": \\(.*\\)$/\\1/Ip'"))))
(defun ed/get-origin-mail-system-header (msg)
(let ((path (or (mu4e-message-field msg :path) "")))
(if (or (string= path "")
(not (file-readable-p path)))
"no path found"
(let ((xmailer (ed/get-mail-header "x-mailer" path))
(useragent (ed/get-mail-header "user-agent" path)))
(if (string= xmailer useragent)
xmailer
(cond
((string= xmailer "") useragent)
((string= useragent "") xmailer)
(t (concat xmailer " (xmailer)\n" useragent " (user-agent)"))))))))
(add-to-list 'mu4e-header-info-custom
'(:useragent . (:name "User-Agent"
:shortname "UserAgt."
:help "Mail client used by correspondant"
:function ed/get-origin-mail-system-header)))
(setq mu4e-headers-fields
'((:flags . 5)
(:human-date . 22)
(:size . 6)
(:foldername . 25)
(:from-or-to . 25)
(:subject . nil))
mu4e-headers-date-format "%a %d %b %Y %H:%M"
mu4e-headers-time-format "%H:%M"
mu4e-use-fancy-chars nil
mu4e-view-fields '(:from :to :cc :subject :flags :date :maildir :mailing-list :tags :useragent :attachments :signature :decryption))
(mu4e-maildirs-extension))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment