Last active
November 29, 2021 14:07
-
-
Save adminy/1c7e38f1f0e7bdeceece5107a5954604 to your computer and use it in GitHub Desktop.
Google drive Download Entire Gmail Stack
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
const getMessage = message => Utilities.newBlob(message.getRawContent(), null, `${['Id', 'Subject', 'Date'].map(action => message['get' + action]()).join('_')}.eml`) | |
const getThread = thread => Utilities.zip(thread.getMessages().map(message => getMessage(message)), thread.getId() + '_' + thread.getFirstMessageSubject() + '.zip') | |
const getInbox = label => GmailApp.search(label).map(thread => getThread(thread)) | |
const labels = GmailApp.getUserLabels().map(label => 'label:' + label.getName()) | |
const emails = ['in:sent', 'in:inbox', ...labels].map(label => Utilities.zip(getInbox(label), label + '.zip')) | |
DriveApp.createFile(Utilities.zip(emails, 'emails.zip')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a gist for sorting your mails into the right labels: