I have a Google Apps script that parses through threads with a label "incomming", fires them off to a webhook, and then marks them as "sent".
(我有一个Google Apps脚本,该脚本通过带有“ incomming”标签的线程进行解析,将它们触发到Webhook,然后将其标记为“ sent”。)
function send() {
var label = GmailApp.getUserLabelByName('incomming');
var sentlabel = GmailApp.getUserLabelByName('sent');
var messages = [];
var threads = label.getThreads();
for (var i = 0; i < threads.length; i++) {
messages = messages.concat(threads[i].getMessages())
}
for (var i = 0; i < messages.length; i++) {
var message = messages[i];
Logger.log(message);
var payload = {
"from": message.getFrom(),
"to": message.getTo(),
"cc": message.getCc(),
"date": message.getDate(),
"subject": message.getSubject(),
"txtbody": message.getPlainBody()
};
var options = {
'method': 'post',
'contentType': 'application/json',
'payload': JSON.stringify(payload),
};
var webhookUrl = '<redacted>';
UrlFetchApp.fetch(webhookUrl, options);
}
// remove the label from these threads so we don't send them to
// slack again next time the script is run
label.removeFromThreads(threads);
Utilities.sleep(200);
sentlabel.addToThreads(threads);
for (var i = 0; i < threads.length; i++) {
threads[i].moveToArchive();
}
}
The problem is, because these emails are generated by a service, they have similar subjects - sometimes the same subject (I can't change this in the service)
(问题是,因为这些电子邮件是由服务生成的,所以它们具有相似的主题-有时是相同的主题(我无法在服务中更改此主题))
Lets say the subject is "Update on X1"
(可以说主题是“在X1上更新”)
When an email comes in for "Update on X1" - the script works fine, sends it off no worries.
(当收到一封有关“在X1上更新”的电子邮件时-该脚本可以正常工作,不用担心,将其发送出去。)
But, if a new "Update on X1" comes in, it sends both the new one and the old one since Gmail labels the whole thread.(但是,如果有新的“ X1更新”出现,则它将发送新邮件和旧邮件,因为Gmail会标记整个线程。)
This results in heavy duplication.
(这导致大量重复。)
How can I fix this?(我怎样才能解决这个问题?)
ask by NictraSavios translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…