Last active
February 14, 2020 21:35
-
-
Save pooza/033bfc6f95e38a545053fce633dc6157 to your computer and use it in GitHub Desktop.
Gmail上で、bulkラベルのついた古いメールを削除。
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 purgeMails () { | |
const days = 30 | |
const step = 500 | |
const labels = ['label:bulk'] | |
const date = new Date() | |
date.setDate(date.getDate() - days) | |
labels.map(label => { | |
let offset = 0 | |
let threads = GmailApp.search(label, offset, step) | |
while (0 < threads.length) { | |
threads.map(thread => { | |
if (thread.getLastMessageDate() < date) { | |
thread.moveToTrash() | |
} | |
}) | |
offset += step | |
threads = GmailApp.search(label, offset, step) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GASに登録し、1時間毎などで実行。