DEV Community

Discussion on: Empty emails from specific address from gmail trash

Collapse
 
elphaba1986 profile image
bLUE

Thanks a lot for your post. I found a few improvements in case someone else is interested. :)

const clientGmail = 'your email@gmail.com'

const page = {
q: "in:trash from: abusers_email@whatever.com",
pageToken: null,
}

const limit = 5400000;

function deleteFromTrash() {
const threadList = Gmail.Users.Threads.list('me', page);
var x= threadList.resultSizeEstimate
if(x!=0){
threadList.threads.forEach(threadss => {

const id = threadss.id
const threadByOtherAPI = GmailApp.getThreadById(id)

const threadDate = threadByOtherAPI.getLastMessageDate()
const timeNow = new Date
const period = timeNow - threadDate
const recent = period < limit

if (recent) {
  Gmail.Users.Threads.remove(clientGmail, id);
  }
})
Enter fullscreen mode Exit fullscreen mode

}
}