我有从扫描仪通过电子邮件收到的文档。
扫描仪无法改变主题。来自扫描仪的所有电子邮件主题均相同“扫描到电子邮件服务器作业”
但是,每个文件名都是唯一的。
谷歌将消息串联起来,而我通常希望继续进行串联。
我运行一个脚本来提取 PDF 并放入驱动器,然后将消息发送到垃圾箱。
问题是......未来的扫描在整个线程上运行相同的脚本,因此每次运行脚本时我都会得到相同文档的大量副本。
我在这里和其他地方看了这个:使用Google脚本从线程中永久删除仅一封Gmail消息 https://stackoverflow.com/questions/42930853/permanently-delete-only-one-gmail-message-from-a-thread-using-a-google-script
threads[i].moveToTrash();
预期行为:不要对垃圾箱中的邮件运行脚本。问题是,整个线程都被标记为垃圾。
实际行为:它在整个线程上运行脚本......甚至是来自同一发件人、具有相同主题的垃圾箱中的消息。
目标:
永久删除邮件,以便脚本不会在具有相同主题的先前邮件上运行。
或者在收到邮件后将主题更改为文件名,并在提取附件后停止对邮件进行线程处理
或者添加适用于单个消息(而不是线程)的标签,该标签不会堵塞我的标签/文件夹。
另外,为了澄清,我不能只检查文件名是否唯一......因为它们经常在驱动器中重命名。
下面的最后 2 行来自http://www.googleappsscript.org/home/fetch-gmail-attachment-to-google-drive-using-google-apps-script http://www.googleappsscript.org/home/fetch-gmail-attachment-to-google-drive-using-google-apps-script不工作。整个线程被重新处理......并且所有附件被再次添加。
var root = DriveApp.getRootFolder();
for(var i in threads){
var mesgs = threads[i].getMessages();
for(var j in mesgs){
//get attachments
var attachments = mesgs[j].getAttachments();
for(var k in attachments){
var attachment = attachments[k];
var isImageType = checkIfImage_(attachment);
if(!isImageType) continue;
var attachmentBlob = attachment.copyBlob();
var file = DriveApp.createFile(attachmentBlob);
parentFolder.addFile(file);
root.removeFile(file);
}
}
threads[i].addLabel(label);
//ADDED BELOW TO MOVE TO TRASH
threads[i].moveToTrash();
threads[i].removeFromThread();
}