Skip to content

Commit

Permalink
Updates #10
Browse files Browse the repository at this point in the history
- Removing helm-mu; I prefer consult-mu but it requires manual installation.
- Adding an Outlook example.
- Gmail specific archive and deletion.
- Improvement to the documentation, README.
  • Loading branch information
danielfleischer authored Aug 30, 2024
2 parents d54712f + c5155ce commit c23930c
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 37 deletions.
49 changes: 48 additions & 1 deletion .mbsync
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ SyncState *

IMAPAccount Apple
Host imap.mail.me.com
PORT 993
User a@icloud.com
PassCmd "gpg -q --for-your-eyes-only --no-tty -d ~/.authinfo.gpg | awk '/machine imap.mail.me.com/ {print $NF}'"
AuthMechs LOGIN
Expand Down Expand Up @@ -162,3 +161,51 @@ Channel Apple-sent
Channel Apple-all

####################################################################

IMAPAccount Outlook
Host outlook.office365.com
User a@outlook.com
PassCmd "gpg -q --for-your-eyes-only --no-tty -d ~/.authinfo.gpg | awk '/machine outlook.office365.com login a@outlook.com/ {print $NF}'"
AuthMechs LOGIN
TLSType IMAPS
TLSVersions +1.2

MaildirStore Outlook-local
Path ~/Mail/Outlook/
Inbox ~/Mail/Outlook/Inbox
SubFolders Verbatim

IMAPStore Outlook-remote
Account Outlook

Channel Outlook-all
Far :Outlook-remote:
Near :Outlook-local:
Patterns "INBOX" "Archive" "Sent"
CopyArrivalDate yes
Create Both
Expunge Both
SyncState *

Channel Outlook-junk
Far :Outlook-remote:"Junk"
Near :Outlook-local:"Spam"
CopyArrivalDate yes
Create Both
Expunge Both
SyncState *

Channel Outlook-trash
Far :Outlook-remote:"Deleted"
Near :Outlook-local:"Trash"
CopyArrivalDate yes
Create Both
Expunge Both
SyncState *

Group Outlook
Channel Outlook-all
Channel Outlook-junk
Channel Outlook-trash

########################################################################
93 changes: 75 additions & 18 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#+html: <a href="https://melpa.org/#/mu4easy"><img alt="MELPA" src="https://melpa.org/packages/mu4easy-badge.svg"/></a>
#+html: <a href="https://stable.melpa.org/#/mu4easy"><img src="https://stable.melpa.org/packages/mu4easy-badge.svg"></a>

A global minor mode that defines a full working setup for mu4e and =mbsync=, based on mu 1.8+. Easily setup accounts and aliases from these providers: *Google*, *Apple*, *GMX* and *Proton*. Additional packages are installed and configured for a better experience, including =mu4e-column-faces=, =mu4e-alert=, =org-msg= and =helm-mu=. Some customizations are available, run =(customize-group 'mu4easy)=.
A global minor mode that defines a full working setup for mu4e and =mbsync=, based on mu 1.12+. Easily setup accounts and
aliases from these providers: *Google*, *Apple*, *GMX*, *Outlook*, and *Proton*. Additional packages are installed and configured for a
better experience, including =mu4e-column-faces=, =mu4e-alert=, and =org-msg=. Some customizations are available, run
=(customize-group 'mu4easy)=.

Install locally and use the =load-path= variable, e.g.:
#+begin_src elisp
Expand Down Expand Up @@ -32,10 +35,11 @@ See later more details on the =mu4easy-context= macro.

Make sure you have =mu= in your in PATH.

- mbsync Configuration
- =mbsync= Configurations:
- [[#Google][Google]]
- [[#Apple][Apple]]
- [[#GMX][GMX]]
- [[#Outlook][Outlook]]
- [[#Proton][Proton]]
- [[#mu4e][mu4e configuration]]

Expand All @@ -48,7 +52,7 @@ Make sure you have =mu= in your in PATH.

The important part is to normalize all accounts to have the same structure, containing the folders Inbox, Archive, Sent,
Trash, Drafts and Spam. I would advice against syncing the Drafts folder because it can lead to issues. If you decide
not to sync it, just remove the relevant lines from the =.mbsyncrc= file.
not to sync it, just remove the relevant lines from the =.mbsyncrc= file. *We assume isync 1.5.0 or newer*.

Let's go over each provider and examine the gotchas.

Expand Down Expand Up @@ -213,6 +217,57 @@ Expunge Both
SyncState *
#+end_src

*** Outlook
:PROPERTIES:
:CREATED: [2024-08-30 Fri 15:43]
:END:
#+begin_src conf
IMAPAccount Outlook
Host outlook.office365.com
User a@outlook.com
PassCmd "gpg -q --for-your-eyes-only --no-tty -d ~/.authinfo.gpg | awk '/machine outlook.office365.com login a@outlook.com/ {print $NF}'"
AuthMechs LOGIN
TLSType IMAPS
TLSVersions +1.2

MaildirStore Outlook-local
Path ~/Mail/Outlook/
Inbox ~/Mail/Outlook/Inbox
SubFolders Verbatim

IMAPStore Outlook-remote
Account Outlook

Channel Outlook-all
Far :Outlook-remote:
Near :Outlook-local:
Patterns "INBOX" "Archive" "Sent"
CopyArrivalDate yes
Create Both
Expunge Both
SyncState *

Channel Outlook-junk
Far :Outlook-remote:"Junk"
Near :Outlook-local:"Spam"
CopyArrivalDate yes
Create Both
Expunge Both
SyncState *

Channel Outlook-trash
Far :Outlook-remote:"Deleted"
Near :Outlook-local:"Trash"
CopyArrivalDate yes
Create Both
Expunge Both
SyncState *

Group Outlook
Channel Outlook-all
Channel Outlook-junk
Channel Outlook-trash
#+end_src
*** Proton
:PROPERTIES:
:CREATED: [2021-05-09 Sun 22:49]
Expand Down Expand Up @@ -258,19 +313,22 @@ In order to us Proton, one needs to install a bridge application. It specifies t
Let's go over the important parts of the elisp code.

#+begin_src elisp
(setf (alist-get 'trash mu4e-marks)
'(:char ("d" . "▼")
:prompt "dtrash"
:dyn-target (lambda (target msg) (mu4e-get-trash-folder msg))
;; Here's the main difference to the regular trash mark, no +T
;; before -N so the message is not marked as IMAP-deleted:
(setf (alist-get 'refile mu4e-marks)
'(:char ("r" . "▶")
:prompt "refile"
:dyn-target (lambda (target msg) (mu4e-get-refile-folder msg))
;; Notice the special treatment for Gmail.
:action (lambda (docid msg target)
(mu4e--server-move docid (mu4e--mark-check-target target) "+S-u-N"))))
(let ((maildir (mu4e-message-field msg :maildir)))
(if (string-match-p "Gmail\\|Google" maildir)
(mu4e--server-remove docid)
(mu4e--server-move docid (mu4e--mark-check-target target) "+S-u-N"))))))
#+end_src

I picked this code and realized that, at least for Google, if you flag a message =trashed=, it just disappears. This code
instead flags the message as =seen=, removes the flags =unseen= and =new= and finally, moves it to the Trash folder, which is
synced to the server and gets deleted according to a policy you control.
Gmail requires special treatment for *archiving* and *deletion*, since folders are labels and everything exist in the =All
Mail=, in addition to other "locations" like =Inbox=, =Sent=, etc. Here, we deal with Gmail by regex matching with the
maildir name; adapt if needed. In this example, archiving for Gmail means removing the email (from the Inbox) while for
other providers it means moving the email. Similar notion for deletion.

#+begin_src elisp
(cl-defmacro mu4easy-context (&key c-name maildir mail smtp
Expand Down Expand Up @@ -301,13 +359,12 @@ synced to the server and gets deleted according to a policy you control.
(mu4e-refile-folder . ,refile)
(mu4e-compose-signature . (concat ,sig))
(mu4e-sent-messages-behavior . ,sent-action)
(smtpmail-smtp-user . ,smtp-mail)
(smtpmail-starttls-credentials . ((,smtp ,smtp-port nil nil)))
(smtpmail-auth-credentials . '((,smtp ,smtp-port ,smtp-mail nil)))
(smtpmail-default-smtp-server . ,smtp)
(smtpmail-smtp-server . ,smtp)
(smtpmail-stream-type . ,smtp-type)
(smtpmail-smtp-service . ,smtp-port)
(smtpmail-smtp-user . ,smtp-mail)
(smtpmail-smtp-server . ,smtp)
(smtpmail-debug-info . t)
(smtpmail-debug-verbose . t)
(org-msg-signature . ,sig)
(mu4e-maildir-shortcuts .
((,inbox . ?i)
Expand Down
40 changes: 22 additions & 18 deletions mu4easy.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; Keywords: mail
;; Homepage: https://github.com/danielfleischer/mu4easy
;; Version: 1.0
;; Package-Requires: ((emacs "25.1") (mu4e-column-faces "1.2.1") (mu4e-alert "1.0") (helm-mu "1.0.0") (org-msg "4.0"))
;; Package-Requires: ((emacs "25.1") (mu4e-column-faces "1.2.1") (mu4e-alert "1.0") (org-msg "4.0"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand All @@ -26,9 +26,14 @@
;; This package contains a collection of packages and configurations
;; making it easy and fun to use email with Emacs using mu, mu4e, mbsync
;; and other improvements. The setup supports multiple email providers
;; such as Google, Apple, GMX and Proton. In addition to this elisp
;; package, there is an mbsync configuration that needs to be changed
;; and copied manually.
;; such as Google, Apple, GMX, Outlook and Proton. In addition to this
;; elisp package, there is an mbsync configuration that needs to be
;; changed and copied manually.

;; Please check out the repository
;; https://github.com/danielfleischer/mu4easy as it contains
;; documentation and an mbsync configuration example, which will not be
;; installed when installing the package with MELPA.

;;; Code:
(require 'smtpmail)
Expand All @@ -37,7 +42,6 @@
(require 'mu4e-contrib)
(require 'mu4e-column-faces)
(require 'mu4e-alert)
(require 'helm-mu)
(require 'org-msg)

(defgroup mu4easy nil
Expand Down Expand Up @@ -126,9 +130,13 @@ Argument MSG msg at point."
:prompt "dtrash"
:dyn-target (lambda (target msg) (mu4e-get-trash-folder msg))
;; Here's the main difference to the regular trash mark, no +T
;; before -N so the message is not marked as IMAP-deleted:
;; before -N so the message is not marked as IMAP-deleted, unless
;; it's Gmail.
:action (lambda (docid msg target)
(mu4e--server-move docid (mu4e--mark-check-target target) "+S-u-N"))))
(let ((maildir (mu4e-message-field msg :maildir)))
(if (string-match-p "Gmail\\|Google" maildir)
(mu4e--server-move docid (mu4e--mark-check-target target) "+T+S-u-N")
(mu4e--server-move docid (mu4e--mark-check-target target) "+S-u-N"))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Consistent Refile
Expand All @@ -137,8 +145,12 @@ Argument MSG msg at point."
'(:char ("r" . "")
:prompt "refile"
:dyn-target (lambda (target msg) (mu4e-get-refile-folder msg))
;; Notice the special treatment for Gmail.
:action (lambda (docid msg target)
(mu4e--server-move docid (mu4e--mark-check-target target) "+S-u-N"))))
(let ((maildir (mu4e-message-field msg :maildir)))
(if (string-match-p "Gmail\\|Google" maildir)
(mu4e--server-remove docid)
(mu4e--server-move docid (mu4e--mark-check-target target) "+S-u-N"))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Respond in text-mode if prefix
Expand Down Expand Up @@ -212,13 +224,10 @@ SIG signature string; supports org formatting thanks to org-msg."
(mu4e-compose-signature . (concat ,sig))
(mu4e-compose-format-flowed . t)
(mu4e-sent-messages-behavior . ,sent-action)
(smtpmail-smtp-user . ,smtp-mail)
(smtpmail-starttls-credentials . ((,smtp ,smtp-port nil nil)))
(smtpmail-auth-credentials . '((,smtp ,smtp-port ,smtp-mail nil)))
(smtpmail-default-smtp-server . ,smtp)
(smtpmail-smtp-server . ,smtp)
(smtpmail-stream-type . ,smtp-type)
(smtpmail-smtp-service . ,smtp-port)
(smtpmail-smtp-user . ,smtp-mail)
(smtpmail-smtp-server . ,smtp)
(smtpmail-debug-info . t)
(smtpmail-debug-verbose . t)
(org-msg-signature . ,sig)
Expand Down Expand Up @@ -341,7 +350,6 @@ See `mu4easy-context' for function signature."
(define-key mu4e-main-mode-map (kbd "U") #'mu4easy-update-mail-and-index)
(define-key mu4e-view-mode-map (kbd "<tab>") #'shr-next-link)
(define-key mu4e-view-mode-map (kbd "<backtab>") #'shr-previous-link)
(define-key mu4e-search-minor-mode-map (kbd "s") #'helm-mu)
(define-key mu4e-headers-mode-map (kbd "M") #'mu4e-headers-mark-all)
(define-key mu4e-headers-mode-map (kbd "N") #'mu4e-headers-mark-all-unread-read))

Expand Down Expand Up @@ -397,8 +405,6 @@ See `mu4easy-context' for function signature."
")
(setq mu4e-icalendar-trash-after-reply nil)
(setq mu4e-icalendar-diary-file diary-file)
(setq helm-mu-append-implicit-wildcard nil)
(setq helm-mu-gnu-sed-program "gsed")
(setq org-msg-options "html-postamble:nil H:5 num:nil ^:{} toc:nil author:nil email:nil \\n:t tex:imagemagick")
(setq org-msg-startup "hidestars indent inlineimages")
(setq org-msg-default-alternatives '((new . (text html))
Expand Down Expand Up @@ -452,8 +458,6 @@ See `mu4easy-context' for function signature."
(custom-reevaluate-setting 'message-citation-line-format)
(custom-reevaluate-setting 'mu4e-icalendar-trash-after-reply)
(custom-reevaluate-setting 'mu4e-icalendar-diary-file)
(custom-reevaluate-setting 'helm-mu-append-implicit-wildcard)
(custom-reevaluate-setting 'helm-mu-gnu-sed-program)
(custom-reevaluate-setting 'org-msg-options)
(custom-reevaluate-setting 'org-msg-startup)
(custom-reevaluate-setting 'org-msg-default-alternatives)
Expand Down

0 comments on commit c23930c

Please sign in to comment.