Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armarti/38c8990e8b834f186662988bc0cd0822 to your computer and use it in GitHub Desktop.
Save armarti/38c8990e8b834f186662988bc0cd0822 to your computer and use it in GitHub Desktop.
WIP

Postbox / ThunderBird + ProtonMail MultiAddress Setup

This has only been tried on macOS 11. And even then I haven't run these instructions end-to-end. This is pieced together from trial & error.

This could be scripted but it's late.

  1. Go to devtools of https://beta.protonmail.com/settings/u/0/identity

  2. Find the https://beta.protonmail.com/api/addresses request in the Network panel

  3. Copy the response json

  4. In the devtools console set:

var c = { ...copied json... };
  1. Clean out super secret stuff and keep only { [email1]: "Display Name 1", ... }:
var noms = c.Addresses.reduce((acc, o) => {
  acc[o.Email] = o.DisplayName;
  return acc;
}, {});
  1. With ProtonMail Bridge, get the local credentials with 'info' and save it to a txt file:
$ "/Applications/ProtonMail Bridge.app/Contents/MacOS/ProtonMail Bridge" --cli

>>> info
...
Configuration for user1@myemail.com
IMAP Settings
Address:   127.0.0.1
IMAP port: 1143
Username:  user1@myemail.com
Password:  abc123
Security:  STARTTLS

SMTP Settings
Address:   127.0.0.1
IMAP port: 1025
Username:  user1@myemail.com
Password:  abc123
Security:  SSL
...
>>> exit

$
  1. Somehow get this txt file to look like this json:
{
  "smtp": {
    "username": "user1@myemail.com",
    "security": "SSL",
    "port": "1025",
    "password": "abc123",
    "address": "127.0.0.1"
  },
  "imap": {
    "username": "user1@myemail.com",
    "security": "STARTTLS",
    "port": "1143",
    "password": "abc123",
    "address": "127.0.0.1"
  }
}
  1. Add display names with this:
creds.forEach((el, i, arr) => {
  arr[i].displayName = noms[el.imap.username];
});
  1. Turn this into the XML config format with this:
var cfg = `
<?xml version="1.0" encoding="UTF-8"?>\n<clientConfig version="1.1">` +
creds.map(el => `
  <emailProvider id="${el.imap.username}">
    <domain>${el.imap.username.split('@')[1]}</domain>
    <displayName>${el.displayName}</displayName>
    <displayShortName>${(el.displayName.match(/\b[A-Z]+/g) || []).join('')}</displayShortName>
    <incomingServer type="imap">
      <hostname>${el.imap.address}</hostname>
      <port>${el.imap.port}</port>
      <socketType>${el.imap.security}</socketType>
      <authentication>password-cleartext</authentication>
      <password>${el.imap.password}</password>
      <username>${el.imap.username}</username>
    </incomingServer>
    <outgoingServer type="smtp">
      <hostname>${el.smtp.address}</hostname>
      <port>${el.smtp.port}</port>
      <socketType>${el.smtp.security}</socketType>
      <authentication>password-cleartext</authentication>
      <password>${el.smtp.password}</password>
      <username>${el.smtp.username}</username>
    </outgoingServer>
  <emailProvider>
`).join('\n') + `
</clientConfig>`;
  1. X
var credsMap = {};
creds.forEach(o => {
  var d = o.imap.username.split('@')[1] + '.xml';
  if(!credsMap[d]) credsMap[d] = [];
  credsMap[d].push(o);
});
var credsMapXml = Object.fromEntries(Object.entries(credsMap).map(([fn, vArr]) => [fn, `
<?xml version="1.0" encoding="UTF-8"?>
<clientConfig version="1.1">` + vArr.map(el => `
  <emailProvider id="${el.imap.username}">
      <domain>${el.imap.username.split('@')[1]}</domain>
      <displayName>${el.displayName}</displayName>
      <displayShortName>${(el.displayName.match(/\b[A-Z]+/g) || []).join('')}</displayShortName>
      <incomingServer type="imap">
      <hostname>${el.imap.address}</hostname>
      <port>${el.imap.port}</port>
      <socketType>${el.imap.security}</socketType>
      <authentication>password-cleartext</authentication>
      <password>${el.imap.password}</password>
      <username>${el.imap.username}</username>
      </incomingServer>
      <outgoingServer type="smtp">
      <hostname>${el.smtp.address}</hostname>
      <port>${el.smtp.port}</port>
      <socketType>${el.smtp.security}</socketType>
      <authentication>password-cleartext</authentication>
      <password>${el.smtp.password}</password>
      <username>${el.smtp.username}</username>
      </outgoingServer>
    <emailProvider>
  `).join('\n') + `
  </clientConfig>`
]));

writeFile = require('fs').writeFile;
for(const [fn, str] of Object.entries(credsMapXml)) {
  writeFile(fn, str, 'utf8', err => {
    if(err) throw err;
  });
}
  1. Try to figure out what to do with the file by reading these:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment