保存上次邮件的附件



我需要用替换的旧文件将来自一个发件人的文件格式为"gz"的附件保存到谷歌驱动器中的文件夹GmailToDrive中

这里的应用程序脚本保存附件从最后一封邮件我得到了答案的脚本,但有些地方是错误的。我认为,这个-query='in:inbox有:nouserlabels'+query+'AND from:entrepot@fmlogistic.frAND older_than:4h';

你能帮我吗?非常感谢!

// GLOBALS
//Array of file extension which you would like to extract to Drive
var fileTypesToExtract = ['gz'];
//Name of the folder in google drive i which files will be put
var folderName = 'GmailToDrive';
//Name of the label which will be applied after processing the mail message
var labelName = 'GmailToDrive';
function GmailToDrive(){
var query = '';
//filename:jpg OR filename:tif OR filename:gif OR fileName:png OR filename:bmp OR filename:svg'; //'after:'+formattedDate+
for(var i in fileTypesToExtract){
query += (query === '' ?('filename:'+fileTypesToExtract[i]) : (' OR filename:'+fileTypesToExtract[i]));
}
//ADD the only email adress you want to check + EDIT : only last 24h emails
query = 'in:inbox has:nouserlabels ' + query + ' AND from:entrepot@fmlogistic.fr AND older_than:4h';
var threads = GmailApp.search(query);
var label = getGmailLabel_(labelName);
var parentFolder;
if(threads.length > 0){
parentFolder = getFolder_(folderName);
}
var root = DriveApp.getRootFolder();
for(var i in threads){
var mesgs = threads[i].getMessages();
for(var j in mesgs){
//ADD: check if the mail is unread:
if (mesgs[j].isUnread()) {
var attachments = mesgs[j].getAttachments();
for(var k in attachments){
var attachment = attachments[k];
var isDefinedType = checkIfDefinedType_(attachment);
if(!isDefinedType) continue;
var attachmentBlob = attachment.copyBlob();
var file = DriveApp.createFile(attachmentBlob);
parentFolder.addFile(file);
root.removeFile(file);
}
}
} // close if unread
} // close for msg loop
//ADD: Set thread (all mail included) as read
GmailApp.markThreadRead(threads[i]);
threads[i].addLabel(label);
}

根据文档:

older_than可用于早于使用d(天(、m(月(和y(年(的时间段的消息

因此,4h不起作用。

相关内容

  • 没有找到相关文章

最新更新