I'm trying to create a script for Gmail to get only "NOT trashed" emails but I'm getting the thashed emails too.
Why?
function fromGmailToDrive() {
var query = "in:inbox -in:trash has:attachment";
var threads = GmailApp.search(query);
threads.forEach((t) => {
const messages = t.getMessages()
messages.forEach((m) => {
console.log("m.isInTrash():", m.isInTrash()) //<- some are true, why?
})
})
}
That query is working if I use it in Gmail browser app.