Last active
October 12, 2019 07:42
-
-
Save mipsparc/d1763982444a049f18559787532518b2 to your computer and use it in GitHub Desktop.
2日以内のDMARC XMLを取得するサンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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