Created
December 5, 2021 00:58
-
-
Save tallcoleman/4f6836212c85bfcf860a218988cac4f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* | |
| Sorry Counter | |
| ============= | |
| Instructions: | |
| - go to script.google.com | |
| - new project | |
| - paste this in, save, select "run" | |
| - give the script permissions to search your email | |
| - enjoy learning how apologetic you are | |
| */ | |
| const sorryCounter = function () { | |
| // get your email | |
| const yourEmail = Session.getActiveUser().getEmail(); | |
| // get threads with 'sorry' | |
| let lastArray = ['start']; | |
| let threadList = []; | |
| let startNumber = 0; | |
| const searchIncrement = 100; | |
| while (lastArray.length !== 0) { | |
| let currentArray = GmailApp.search('sorry from:me', startNumber, searchIncrement); | |
| threadList = threadList.concat(currentArray); | |
| startNumber += searchIncrement; | |
| lastArray = currentArray; | |
| Logger.log("Found " + threadList.length + " threads ... searching"); | |
| } | |
| Logger.log("Finished search. Now counting..."); | |
| // get all emails in threads | |
| let messageList = []; | |
| for (thread of threadList) { | |
| messageList = messageList.concat(thread.getMessages()); | |
| } | |
| // count individual emails with 'sorry' from you | |
| let sorryCount = 0; | |
| for (message of messageList) { | |
| let author = message.getFrom().match(/<(.+)>/) ? message.getFrom().match(/<(.+)>/)[1] : message.getFrom(); | |
| let subject = message.getSubject(); | |
| let content = message.getPlainBody(); | |
| if (author === yourEmail && (subject.match(/sorry/i) || content.match(/sorry/i))) { | |
| sorryCount += 1; | |
| } | |
| } | |
| Logger.log("Found " + sorryCount + " emails from you containing 'sorry'"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment