Created
March 4, 2022 21:33
-
-
Save paulirish/93199e6b6cf7b648a3150ad397077e28 to your computer and use it in GitHub Desktop.
finding most common senders in gmail - apps script
This file contains 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
{ | |
"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 file contains 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
// 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]++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much for this!