我正在尝试使以下 Google Apps 脚本正常工作,取自另一个较早的 Groups 帖子。它基本上正在工作到调用 getThreads(n, m) 的地步。返回的错误代码是:
TypeError:无法调用 null 的方法“addToThreads”。
有没有更简单的方法来调试 getThreads() 函数?目标是将标签从 EVERNOTE 更改为 Scripts/Forward。
// Set up multiple labels/sub-labels and add one or more email addresses
function forwardEmails() {
forwardThreads("EVERNOTE", "username@m.evernote.com", "@Filtered Email Archive");
// forwardThreads("Forward/MoreItems", "username1@gmail.com, username2@gmail.com", "MORE INFO");
}
function forwardThreads(label, addr, subjSuffix) {
var maxSubjLength = 250;
var applylabel = GmailApp.getUserLabelByName("Scripts/Forward");
// Send individual and threaded emails.
var msgs, msg, i, j, subject, options, labels, page;
labels = GmailApp.getUserLabelByName(label)
var threads = labels.getThreads()
for (i=0; i < threads.length; i++) {
msgs = threads[i].getMessages();
for (j=0; j < msgs.length; j++) {
msg = msgs[j];
subject = msg.getSubject();
if (subject.length + subjSuffix.length > maxSubjLength) {
subject = subject.substring(0, maxSubjLength - subjSuffix.length);
}
options = { htmlBody: msg.getBody(), attachments : msg.getAttachments() };
GmailApp.sendEmail(addr, subject +" "+ subjSuffix, msg.getBody(), options);
}
}
while(!page || page.length == 100) {
page = labels.getThreads(0, 100);
// Apply new label; move the thread out of other label
applylabel.addToThreads(page); // ***** Failing on this line - assume page is NULL
labels.removeFromThreads(page);
}
}