Created
March 13, 2023 12:05
-
-
Save theol0403/ed40738b9cae106306c297b34899fbda to your computer and use it in GitHub Desktop.
outlook autoarchive
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
let axios = await require("@pipedreamhq/platform").axios; | |
function count(length) { | |
return Array.from({ length }, (_, i) => i + 1); | |
} | |
let days = count(7); | |
let hours = count(12); | |
let minutes = count(30); | |
async function getMail(suffix, date) { | |
let mail = await axios(this, { | |
url: `https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$search="category:AutoArchive_${suffix} received<${date.toISOString()}"`, | |
headers: { | |
Authorization: `Bearer ${auths.microsoft_outlook.oauth_access_token}`, | |
}, | |
}); | |
for (const m of mail.value) { | |
console.log(`Moving ${m.subject}`); | |
await axios(this, { | |
method: "POST", | |
url: `https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages/${m.id}/move`, | |
headers: { | |
Authorization: `Bearer ${auths.microsoft_outlook.oauth_access_token}`, | |
}, | |
data: { | |
destinationId: "archive" | |
} | |
}); | |
} | |
} | |
for (const d of days) { | |
let date = new Date(); | |
date.setDate(date.getDate() - d); | |
await getMail(`${d}d`, date); | |
} | |
for (const h of hours) { | |
let date = new Date(); | |
date.setHours(date.getHours() - h); | |
await getMail(`${h}h`, date); | |
} | |
for (const m of minutes) { | |
let date = new Date(); | |
date.setMinutes(date.getMinutes() - m); | |
await getMail(`${m}m`, date); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment