I’ve used Protonmail for several years and use the web interface for the most part and used Thunderbird on the desktop to keep offline copies of email. Since Protnmail takes care of the encryption it requires a local bridge to provide a standard interface like IMAP. Essentially, it is running an IMAP server on the local machine that any compatible client can connect to. Technically, the bridge can be made accessible on a local network so many clients from many machines can connect to it. I might eventually set this up when I have had a chance to get a better handle on vlans and access control.

Installing packages

In order to use connect to the local IMAP bridge locally, I will be using mbsync. I’m using guix for package management, guix (and other package managers) refer to mbsync as isync. The mu package also includes mu4e (at least in version 1.6+ and it’s not recommended to mix/match versions).

1
guix install isync mu

Configuring mbsync

mbsync expects a configuration in ~/.mbsyncrc (does anyone know how to move this to ~/.config? I’m disheartened by all the home directory clutter). Ideally one would GPG encrypt the password but since Proton Bridge generates it locally and it’s is available as clear text to the local machine anyway, I didn’t bother. Instead I just put the password from the ProtonBridge application into a text file (ensure no extra characters exist like space or return) and cat that into the PassCmd.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
IMAPAccount proton
Host 127.0.0.1
User user@protonmail.com
PassCmd "cat ~/.protonBridgePass"
SSLType NONE
CertificateFile /etc/ssl/certs/ca-certificates.crt

IMAPStore proton-remote
Account proton

MaildirStore proton-local
Subfolders Verbatim
Path ~/mail/proton
Inbox ~/mail/proton/inbox

Channel proton
Far :proton-remote:
Near :proton-local:
Patterns *
Create Both
SyncState *

Running the sync command gave me an error that sent me on a goose chase:

1
mbsync -a

Socket error: secure connect to 127.0.0.1 (127.0.0.1:1143): error:1408F10B:SSL routines:ssl3_get_record:wrong version number The issue was the SSLType NONE is the proper config as shown above, I originally had it set to IMAPS. Once the sync starts it will take a long time depending upon how many emails you have.

Configuring mu4e

Configure the mu4e-maildir location to wherever you want to store the mail directory (remember mail in this folder is stored in clear-text). The mu4e-****-folder variables need to include the sub-directory in the relative path, in my case proton.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(use-package mu4e
  :straight nil
  :defer 20 ; Wait until 20 seconds after startup
  :config

  (setq mu4e-change-filenames-when-moving t ; avoid sync conflicts
      mu4e-update-interval (* 10 60) ; check mail 10 minutes
      mu4e-compose-format-flowed t ; re-flow mail so it's not hard wrapped
      mu4e-get-mail-command "mbsync -a"
      mu4e-maildir "~/mail/proton")

  (setq mu4e-drafts-folder "/proton/Drafts"
      mu4e-sent-folder   "/proton/Sent"
      mu4e-refile-folder "/proton/All Mail"
      mu4e-trash-folder  "/proton/Trash")

  (setq mu4e-maildir-shortcuts
      '(("/proton/inbox"     . ?i)
        ("/proton/Sent"      . ?s)
        ("/proton/Trash"     . ?t)
        ("/proton/Drafts"    . ?d)
        ("/proton/All Mail"  . ?a)))

  (setq message-send-mail-function 'smtpmail-send-it
      auth-sources '("~/.authinfo") ;need to use gpg version but only local smtp stored for now
      smtpmail-smtp-server "127.0.0.1"
      smtpmail-smtp-service 1025
      smtpmail-stream-type  'ssl))

I’m also configuring smtpmail in the config section of mu4e just to keep mail config together, smtpmail is part of Emacs core. I’m adding SMTP authentication info to the un-encrypted .authinfo for the same reason as .mbsyncrc explanation above.

1
machine 127.0.0.1 login user@protonmail.com password ProtonBridgeGeneratedPassword port 1025

Using org-mode to compose HTML emails

At this stage plain-text email will work just fine, in order to send email with formatting I’m using org-msg which lets you compose with org markup and sends it out as HTML (including in-lining images, tables, etc.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
(use-package org-msg
  :straight t
  :after mu4e
  :config
  (setq mail-user-agent 'mu4e-user-agent)
  (require 'org-msg)
  (setq org-msg-options "html-postamble:nil H:5 num:nil ^:{} toc:nil author:nil email:nil \\n:t"
      org-msg-startup "hidestars indent inlineimages"
      org-msg-default-alternatives '((new		. (text html))
                                     (reply-to-html	. (text html))
                                     (reply-to-text	. (text)))
      org-msg-convert-citation t)
  (org-msg-mode))

References

Here are a list of references I used to get everything setup and configured: