我对GAS和Javascript一般都很陌生,并且已经进行了广泛的搜索,以找到为什么这不起作用的答案,但是还没有找到解决方案。我想知道你们其中一个人是否能找到问题。这是我的代码:
function maintenanceRequest() {
var findFirstRequest = GmailApp.search("to:censored label:ems-request AND is:unread", 0, 1)[0];
var firstRequest = findFirstRequest.getMessages()[0];
var parseRequest = firstRequest.getPlainBody();
var requestString = String(parseRequest);
if ("Mark archived mail as read" == requestString) {
markArchivedAsRead();
findFirstRequest.moveToArchive();
}
else if ("Cleanup" == requestString) {
weeklyCleanup();
findFirstRequest.moveToArchive();
}
else {
GmailApp.sendEmail("censored", "Failure to parse command", "The EMS has recieved your request but has failed to recognize the command '" + parseRequest + "'. Please try again, using the terms 'Mark archived as read' or 'Cleanup'. If you would like to add an eligible command, please refer to function 'maintenanceRequest'.", {
name: "Email Maintenance Service",
from: "censored"
})
//Add moveToArchive line here after debugging
}
}
代码始终会跳过if
和else if
语句,并跳转到else
语句,无论电子邮件的内容如何。我尝试过使用==
和===
都无济于事,并尝试切换参数所在的边。无济于事。我甚至创建了一个新的var
,requestString
来将parseRequest
转换为字符串,即使我已经99%确定它已经是一个字符串..那么是什么给出了?问题出在哪里?
答案 0 :(得分:2)
尝试在字符串中添加修剪:requestString = requestString.trim()
在您从其他服务获取的任何字符串上使用修剪通常是一种安全的选择。