0
我使用此工具將附件保存到共享的Google雲端硬盤文件夾,並在郵件發生更改時收到通知。只要我搜索pdf附件,一切都很好。正如我設置文件:xls返回的消息遠遠超過預期。不僅如此,調試返回的線程是正確的,並且將查詢插入到Gmail的搜索字段中,但getmessages()返回的是38個消息(以及附件!查詢參數。會話視圖在Gmail中處於禁用狀態,與此附件的唯一匹配是from:字段。 我試圖改變參考數據(通過添加newer_than),並沒有改變;我改變了循環,沒有任何改變。我是否錯過了一些非常愚蠢的東西,或者這是xls的一種錯誤?使用此代碼搜索Gmail for xls附件
function salvataggioTavoloTecnico(){
var folderName = 'tavoloTecnico';
var p = 0;
var f1s= DriveApp.getFoldersByName(folderName).next().getFiles();
while (f1s.hasNext()) {
var f1 = f1s.next();
p++
} Logger.log(p);
var d = new Date();
d.setDate(d.getDate()-1);
var n = d.getFullYear() + "/" + addZero(d.getMonth()+1) + "/" + addZero(d.getDate());
var query = 'in:anywhere has:attachment filename:XLS newer_than:5d (from:[email protected] OR from:[email protected] OR from:[email protected])';
//var query = 'in:anywhere has:attachment filename:xls '+ 'after:'+n+' (from:[email protected] OR from:[email protected] OR from:[email protected])';
var elenco = GmailApp.search(query);
var quanteMail = elenco.length; Logger.log(quanteMail);
labelName = GmailApp.createLabel('Movimenti - Tavolo tecnico');
for (var i = 0 ; i < quanteMail; i++) {
//for (var i in elenco) {
elenco[i].addLabel(labelName);
var thr = elenco[i];
var nn = thr.getMessageCount();
Logger.log(nn);
var mesgs = thr.getMessages();
var www = mesgs.length;
for(var j = 0 ; j < www ; j ++){
var attachments = mesgs[j].getAttachments();
var rrr = attachments.length;
for(var k = 0 ; k < rrr ; k ++) {
var attachment = attachments[k];
var attachmentBlob = attachment.copyBlob();
var file = DriveApp.createFile(attachmentBlob);
DriveApp.getFoldersByName(folderName).next().addFile(file);
}
}
}
var c = 0;
var f2s = DriveApp.getFoldersByName(folderName).next().getFiles();
while (f2s.hasNext()) {
var f2 = f2s.next();
c++
}
if (c > p) { GmailApp.sendEmail("[email protected]", " avviso "+folderName, "Un nuovo file è stato aggiunto")};
}