This script searches email and moves any existing threads to trash.
See Gmail search operator documentation for more information.
const searchStr = 'in:inbox from:myaccount@gmail.com older_than:30d';
function moveSearchedThreadsToTrash() {
// Find messages related to search string and move to trash
const threads = GmailApp.search(searchStr).forEach(thread => thread.moveToTrash());
}
function logNumSearchedThreads() {
// Find messages related to search string and log number of matching threads
Logger.log(GmailApp.search(searchStr).length);
}