Skip to content

Instantly share code, notes, and snippets.

@rosenpin
Created August 11, 2018 13:39
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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()
@tg12
Copy link

tg12 commented Jun 11, 2021

Would this have changed at all, It has been handy!

@pavanbuzz
Copy link

pavanbuzz commented Sep 7, 2021

This latest code will delete based on current webmail

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

function getTotalEmailPages(){

    document.querySelectorAll('[data-testid="toolbar:page-number-dropdown"]')[0].click();
    let returnvalue = document.getElementsByClassName("dropdown dropdown--bottom toolbar-dropdown no-outline")[0].getElementsByTagName("ul")[0].getElementsByTagName("li").length;
    document.querySelectorAll('[data-testid="toolbar:page-number-dropdown"]')[0].click();
    console.log(`total pages remaining - ${returnvalue}`);
    return returnvalue;
}

async function deleteAllMails(){
	while(getTotalEmailPages() > 0){
        setTimeout(function(){document.getElementById("idSelectAll").click()},1000);
        setTimeout(function(){document.querySelectorAll('[data-testid="toolbar:movetotrash"]')[0].click()},3000);
        setTimeout(function(){document.querySelectorAll('[data-testid="filter-dropdown:show-read"]')[0].click()},6000);
        setTimeout(function(){document.querySelectorAll('[data-testid="filter-dropdown:show-all"]')[0].click()},9000);
        await sleep(12000);
	}
}

deleteAllMails();

@mininmobile
Copy link

mininmobile commented Oct 26, 2021

@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