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]++; | |
} | |
} |
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
@leodevbro sweet! Appreciate the comment. I will be returning to this at some point, and your mbox popularity script will probably be very useful. :)
I'm envisioning something that allows me to clean up my inbox.. Clustering messages from similar senders, and letting me archive them all with one button click. The second part will almost definitely be apps script, but using output from the mbox package seems fine.