- Outlook-like retention policies for Gmail
- Trigger Google API jobs for threads, messages, and labels
Install using clasp 🔗
git clone --recurse-submodules https://github.com/skeletony007/UnofficialGmailPolicy.git
cd GmailPolicy
clasp create --type standalone
sed -i '' 's#}#,"filePushOrder":["'"$PWD"'/BatchRequest/BatchRequests.js","'"$PWD"'/GoogleApi.js","'"$PWD"'/GmailApi.js","'"$PWD"'/GmailUtil.js","'"$PWD"'/GmailPolicy.js","'"$PWD"'/GmailPolicyUI.js"]}#' .clasp.json
clasp push -f
Configure using Apps Script online 📜
Place the Config.gs
as the final execution order file.
We define a function with time-based triggers to run the GmailPolicyUI instance. Visit https://script.google.com/home/triggers to set triggers. Since policies effect emails in day units, it is recommended to a the trigger to run daily.
Example config: using an anonymous function to speed up the policy execution
// the initialQuery parameter is optional and we will use it to only fetch
// threads from the last 28 days.
ui = new GmailPolicyUI({
initialQuery: (() => {
const dateWithinDays = new Date();
dateWithinDays.setDate(dateWithinDays.getDate() - 28);
// format dd/mm/yyyy
return `after:${dateWithinDays.getDate()}/${dateWithinDays.getMonth() + 1}/${dateWithinDays.getFullYear()}`
})()
});
Q: Why use tanaikech/BatchRequest over Google JavaScript client library batching?
A: The Google Apps Script compiler does not seem to support the setup
Q: Why map users.threads.get
over users.threads.list
?
A: users.threads.get
does not return message.internalDate
, users.threads.get
does. See message resource