我创建了这个谷歌应用程序脚本以创建文件夹(在谷歌驱动器中)并共享它们。
但有时我在 addEditor 函数运行时收到此错误消息: https ://script.google.com说:遇到错误:电子邮件不正确:myemail@mydomain.com
但是,如果我直接将这封电子邮件插入文件夹的共享面板中,那么它就可以工作......
*//---- EMAILS
function validateEmail (emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}
//---- FOLDERS
function FolderCreateByPathShared(path,editorsList,viewersList){
// path e.g. : 'F1/F2/F3', 'F1' created in root
// e.g. : FolderCreateByPathShared('F1/F2/F3',['toto.titi@domaine.com'],[''])
var f=FolderCreateByPath(path);
if(viewersList){
for(var c=0 ; c<viewersList.length ; c++){
if(validateEmail(viewersList[c])) f.addViewer(viewersList[c]);
}
}
if(editorsList){
for(var c=0 ; c<editorsList.length ; c++){
if(validateEmail(editorsList[c])) f.addEditor(editorsList[c]);
}
}
return f;
}*