Skip to content

Instantly share code, notes, and snippets.

@pooza
Last active February 14, 2020 21:35
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 pooza/033bfc6f95e38a545053fce633dc6157 to your computer and use it in GitHub Desktop.
Save pooza/033bfc6f95e38a545053fce633dc6157 to your computer and use it in GitHub Desktop.
Gmail上で、bulkラベルのついた古いメールを削除。
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)
}
})
}
@pooza
Copy link
Author

pooza commented Jan 9, 2020

GASに登録し、1時間毎などで実行。

@pooza
Copy link
Author

pooza commented Feb 14, 2020

V8対応に伴い、更新。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment