Skip to content

swinton/gmail-repl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔁 gmail-repl

A REPL for GMail

Setup

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.

Usage

./repl.js

Examples

Get profile

users.getProfile

await profile()

List messages

users.messages.list

// 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')

Read a message

users.messages.get

await message('1883a5111e8ef47c')

Decode a message

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 threads

users.threads.list

// 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')

Read a thread

users.threads.get

await thread('1883b361aaef86b6')

Batch delete

users.messages.batchDelete

Batch delete unimportant promotional messages

await batchDeleteMessages('category:promotions -is:important -is:starred')

Batch delete messages from before 2021

await batchDeleteMessages('before:2021/01/01')

About

A REPL for GMail

Topics

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Contributors