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]++;
}
}
@nikhilweee
Copy link

Thank you so much for this!

@leodevbro
Copy link

I created a video tutorial about NodeJS method to find frequency of senders, receivers and more. The NodeJS method is much easier, much faster and more reliable than Apps Script method. NodeJS method can analyze 200,000 mails in about 30 minutes.

https://www.youtube.com/watch?v=KKU84ogffeM

gmail-info-thumb_jpg_720

@paulirish
Copy link
Author

@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.

@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