Skip to content

Instantly share code, notes, and snippets.

@mipsparc
Last active October 12, 2019 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mipsparc/d1763982444a049f18559787532518b2 to your computer and use it in GitHub Desktop.
Save mipsparc/d1763982444a049f18559787532518b2 to your computer and use it in GitHub Desktop.
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