Skip to content

Instantly share code, notes, and snippets.

@rosenpin
Created August 11, 2018 13:39
Show Gist options
  • Save rosenpin/a00cf5f2bfac8d589e5790faa896b2ca to your computer and use it in GitHub Desktop.
Save rosenpin/a00cf5f2bfac8d589e5790faa896b2ca to your computer and use it in GitHub Desktop.
Delete all emails in an open folder in Protonmail
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function deleteAllMails(){
for (var i = 0;i<100;i++){
setTimeout(function(){document.getElementById("selectAll").click()},1000);
setTimeout(function(){document.getElementsByClassName("moveElement-btn-delete")[0].click()},3000);
setTimeout(function(){document.getElementById("confirmModalBtn").click()},5000);
await sleep(10000)
}
}
deleteAllMails()
@nayr1991
Copy link

If you end up like me stuck with messages in All mail, but no other folder, you can use the following to delete:

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
async function deleteAllMails(){
 for (var i = 0;i<100;i++){
        setTimeout(function(){document.getElementById("idSelectAll").click()},500);
        setTimeout(function(){document.querySelectorAll('[data-testid="toolbar:movetotrash"]')[0].click()},1000);
        setTimeout(function(){document.querySelectorAll('[data-testid="toolbar:next-page"]')[0].click()},1500);
        await sleep(5000);
 }
}
deleteAllMails();

Instead of selecting all, deleting and then refreshing, this will select all, delete and then move forward a page.
This gets around the fact that the All mail folder includes messages already in trash.

I also couldn't get @pavanbuzz's getTotalEmailPages to work. I had 3000 pages but never really dove into why it was failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment