Skip to content

Instantly share code, notes, and snippets.

@mipsparc mipsparc/retribe_xmls.js
Last active Oct 12, 2019

Embed
What would you like to do?
2日以内のDMARC XMLを取得するサンプルコード
function retribeXMLs()
{
var xmls = [];
var messages;
var zipblob;
var fileblob;
// 2日以内のすべてのスレッドを取得
var threads = GmailApp.search('newer_than:2d');
for (var i = 0; i < threads.length; i++) {
// スレッドからメッセージ(各メール)を取得
messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
// 添付されたzipバイナリ(1つのみ)を取得
zipblob = messages[j].getAttachments()[0].copyBlob();
try {
// XMLファイルのバイナリを取得
fileblob = Utilities.unzip(zipblob);
} catch (e) {
continue;
}
for (var k = 0; k < fileblob.length; k++) {
// 配列にXML文字列を追加する
xmls.push(fileblob[k].getDataAsString());
}
}
}
return xmls;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.