A REPL for GMail
Follow the Node.js quickstart from the Gmail for Developers guide, and make sure your desktop application credentials are stored in a credentials.json file -- see credentials-example.json for an example.
./repl.jsawait profile()// List all messages
await messages()
// List all from <email>
await messages('from:me@example.com')
// List unread from <email> sent after <date>
await messages('from:me@example.com is:unread after:2023/05/19')await message('1883a5111e8ef47c')The raw API response contains base64-encoded MIME parts and headers buried in arrays. decode extracts the key headers and body into a readable object.
// Decode a raw message
decode(await message('1883a5111e8ef47c'))
// → { id, from, to, subject, date, body }
// Decode all messages in a thread
const t = await thread('1883b361aaef86b6')
t.messages.map(decode)decode prefers text/plain body parts and falls back to tag-stripped HTML if no plain text is available.
// List all threads
await threads()
// List all from <email>
await threads('from:me@example.com')
// List unread from <email> sent after <date>
await threads('from:me@example.com is:unread after:2023/05/19')await thread('1883b361aaef86b6')await batchDeleteMessages('category:promotions -is:important -is:starred')await batchDeleteMessages('before:2021/01/01')