Last active
February 5, 2020 08:16
-
-
Save rikvermeer/65fedb6f66e8510607c24c1db8f7db19 to your computer and use it in GitHub Desktop.
Roundcube delete duplicates from console (js)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* In chrome, open the console in the developer tools extension | |
* Select the mailbox folder which you want to clean | |
* Run this code in the console | |
* Goto the next page (max mails/page = 200) and execute the code again | |
* Repeat from the start until no more duplicate entities are logged anymore | |
* | |
* Troubleshooting: | |
* - If you get failing authentications in the network tab: try updating the token below | |
* - If the "Deleted Items" folder does not exist, change the name below | |
*/ | |
var url = 'https://example.com/roundcube/'; | |
//Get X-Roundcube-Request token from another request header | |
var token = 'BP2IKZwXkqmxXOcucCDK71ujILrH87vw'; | |
//Create an array with the messages | |
//remove the header row | |
//map the data | |
var mails = [...rcmail.message_list.list.rows].slice(1).map((mail, idx) => { return { | |
idx: idx, | |
uid: mail.uid, | |
sub: mail.innerText, | |
deleted: false | |
} } ); | |
mails.forEach(m => { | |
//Compare on subject (sender, time, subject) | |
var dups = mails.filter(m2 => m.sub === m2.sub && m2.deleted === false); | |
if(dups.length > 1) { | |
console.log(m.uid, m.sub, {_uid: `${m.uid}`}); | |
//Set deleted to true so one message remains | |
m.deleted = true; | |
//Move the mail to "Deleted Items" | |
fetch(url + '?_task=mail&_action=move', { | |
method: 'post', | |
mode: 'same-origin', | |
headers: { | |
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8", | |
"X-Roundcube-Request": token | |
}, | |
body: `_target_mbox=Deleted+Items&_uid=${m.uid}&_mbox=Sent+Items&_remote=1&_unlock=loading1580853415186` | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment