Skip to content

Instantly share code, notes, and snippets.

@ikemo3
Last active June 16, 2019 22:43
Show Gist options
  • Save ikemo3/144dde762453e7a1d03f8101a6585acf to your computer and use it in GitHub Desktop.
Save ikemo3/144dde762453e7a1d03f8101a6585acf to your computer and use it in GitHub Desktop.
たすくまの過去のメールを引っ張り出すGoogle Apps Script
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;
}
@ikemo3
Copy link
Author

ikemo3 commented Jun 16, 2019

1ヶ月前だと月末処理が面倒なので30日前にした。わざと曜日をずらしている。

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