Last active
June 16, 2019 22:43
-
-
Save ikemo3/144dde762453e7a1d03f8101a6585acf to your computer and use it in GitHub Desktop.
たすくまの過去のメールを引っ張り出すGoogle Apps Script
This file contains hidden or 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 main() { | |
wakeupTaskumaMail(nowMinusDate(7)); | |
wakeupTaskumaMail(nowMinusDate(30)); | |
} | |
function wakeupTaskumaMail(date) { | |
const query = "label:たすくま " + toYYYYMMDD(date); | |
const threads = GmailApp.search(query); | |
for (var i = 0; i < threads.length; i++) { | |
const thread = threads[i]; | |
thread.markUnread(); | |
thread.moveToInbox(); | |
} | |
} | |
function toYYYYMMDD(dateObj) { | |
const date = dateObj.getDate(); | |
const dateStr = (date >= 10) ? String(date) : "0" + String(date); | |
const month = dateObj.getMonth() + 1; | |
const monthStr = (month >= 10) ? String(month) : "0" + String(month); | |
const yearStr = String(dateObj.getFullYear()); | |
return yearStr + monthStr + dateStr; | |
} | |
function nowMinusDate(num) { | |
const date = new Date(); | |
date.setDate(date.getDate() - num); | |
return date; | |
} | |
function nowMinusMonth(num) { | |
const date = new Date(); | |
date.setMonth(date.getMonth() - num); | |
return date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1ヶ月前だと月末処理が面倒なので30日前にした。わざと曜日をずらしている。