Gmailの受信メールを検索して取得する

const query = 'ほげ';   // 検索する文字列
const start = 0;        // 開始番号
const max = 10;         // 取得数
 
const threads = GmailApp.search(query, start, max);
const messagesForThreads = GmailApp.getMessagesForThreads(threads);
 
for(const messages of messagesForThreads){
    console.log(messages[0].getSubject());
    console.log(messages[0].getPlainBody());
}