Skip to content

Instantly share code, notes, and snippets.

@marshyon
Last active November 1, 2022 14:09
Show Gist options
  • Save marshyon/7252914a0063748130fe9d4485123e53 to your computer and use it in GitHub Desktop.
Save marshyon/7252914a0063748130fe9d4485123e53 to your computer and use it in GitHub Desktop.
delete all mails in Protonmail

Why ?

If you intend to stop using Protonmail, non of this is required however if you just want to clear down unwanted emails and claim back storage quota this may be of use.

According to ProtonMail support in normal operation you need to move emails to the delete folder then go into the delete folder and delete all to get rid of them.

This way youre 'all mail' folder wont just fill up eternally, increasing storage and thus require to buy more storage

Also if youve got a paid plan and wish to delete an associated domain name, you can't do this untill all emails that are addressed to that domain have first been deleted.

So you may find yourself with > 1000 emails in 'all mail' and even though Protomail say you can use an email client like Thunderbird you are stuck with Protmail bridge saying that you are not allowed to remove items from all mail folder

Manually clicking on 'move to trash', clicking on trash to 'delete all' for 50 emails at a time X however many times you need to do this, possibly going into the hundereds is not really a viable option.

Backup

Backup any emails you want to keep.

If you have a paid account there is a tool that will run on Windows and Mac that can do this, still currently in beta but it works ok

https://proton.me/blog/import-export-beta

Another way is to install onto Windows, Linux or Mac the bridge service :

https://proton.me/mail/bridge

Then any imap compliant email client can be used to connect to your ProtonMail account, download locally any emails you want to keep or even upload them elsewhere

Run the script

Disclaimer - you do this at your own risk and have read the above in order to back up any emails you want to keep !

Navigate to the 'all mail' folder in protonmail in Chrome or a compatible, modern browser and open the console in dev tools

paste the above script

run the script by pasting :

runMain()

Restore

Restore any emails you backed up previously if you need to

let runCount = 0;
let maxRuns = 4;
const deleteEmails = () => {
document.querySelector("#idSelectAll").click();
document.querySelector('[data-testid="toolbar:movetotrash"]').click();
document.querySelector('[data-shortcut-target="navigation-link trash"]').click();
};
const clearEmails = () => {
document.querySelector('[data-testid="toolbar:more-dropdown"]').click();
document.querySelector('[data-testid="toolbar:more-empty"]').click();
document.querySelector('[data-testid="confirm-empty-folder"]').click();
document.querySelector('[data-shortcut-target="navigation-link allmail"]').click();
};
const runMain = () => {
console.log(`run count ${runCount} max is ${maxRuns} ...`)
deleteEmails();
console.log('waiting for 20 seconds ...')
setTimeout(() => {
console.log('clearing emails ...')
clearEmails()
console.log('returning to all mails ...')
document.querySelector('[data-shortcut-target="navigation-link allmail"]').click();
console.log('waiting for 25 seconds ...')
setTimeout(() => {
runCount = runCount + 1;
if(runCount < maxRuns) {
console.log('re-running runMain() ...')
runMain()
} else {
console.log(`run count ${runCount} exceeded ${maxRuns}, done.`)
}
}, 25000);
}, 20000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment