Skip to content

Instantly share code, notes, and snippets.

@paulirish
Created March 4, 2022 21:33
Show Gist options
  • Save paulirish/93199e6b6cf7b648a3150ad397077e28 to your computer and use it in GitHub Desktop.
Save paulirish/93199e6b6cf7b648a3150ad397077e28 to your computer and use it in GitHub Desktop.
finding most common senders in gmail - apps script
{
"timeZone": "America/New_York",
"oauthScopes": [
"https://www.googleapis.com/auth/gmail.addons.execute",
"https://www.googleapis.com/auth/gmail.readonly"
],
"gmail": {
"name": "find common gmail senders",
"logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/receipt_black_24dp.png",
"primaryColor": "#41f470",
"secondaryColor": "#94f441"
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
// this is pretty quick and rough.. but it works
// script.google.com
// settings to allow editing the appscript.json
// set these two files
// then hit Run with function 'run'
const all = {};
function run() {
collect();
const commonsenders = Object.entries(all).sort((a, b) => b[1] - a[1]).filter(ent => ent[1] > 1);
commonsenders.forEach(sender => {
console.log(sender.join(':'));
});
}
function collect() {
for (const start of [0, 500, 1000, 1500, 2000])
for (const thread of threads = GmailApp.getInboxThreads(start, 500)) {
const msgs = thread.getMessages();
const msg = msgs[0];
const from = msg.getFrom();
all[from] = all[from] || 0;
all[from]++;
}
}
@leodevbro
Copy link

Yeah, Apps Script is more comfortable than NodeJS terminal, but Apps Script is very limited by Google, it runs too slowly in Google system, it has daily data limit, execution time limit and so on. So, I guess MBOX file and NodeJS seems optimal solution to analyze large mailbox.

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