Skip to main content

Locally archive Gmail emails.

Project description

gmail-archiver

Python versions PyPI - Version GitHub tag (with filter) License GitHub commits since latest release (by SemVer including pre-releases) CodeQL QA Tests Coverage Status Dependabot Documentation Status mypy pre-commit Poetry pydocstyle pytest Ruff Downloads Stargazers Prettier

@Tatsh Buy Me A Coffee Libera.Chat Mastodon Follow Patreon

Locally archive Gmail emails.

Installation

Pip

pip install gmail-archiver

Configuration

Create a file at ${CONFIG_DIR}/gmail-archiver/config.toml. On Linux this is typically ~/.config/gmail-archiver/config.toml. The application will print the configuration file path on every run.

The file must contain the following:

[tool.gmail-archiver]
client_id = 'client-id.apps.googleusercontent.com'
client_secret = 'client-secret'

You must set up a project on Google Cloud and it must have the Gmail API enabled.

Then in APIs and services, choose Credentials, + Create credentials and OAuth client ID.

  • Application type: Web application
  • Name: any name

Copy and paste the client ID and secret into the above file.

You should protect the above file. Set it to as limited of a permission set as possible. Example: chmod 0400 ~/.config/gmail-archiver/config.toml.

Why not use Keyring? Keyring is inappropriate for automated scenarios, unless it is purposely made insecure.

Authorisation

When run, if anything is invalid about the OAuth data, you will be prompted to create it.

$ gmail-archiver email@gmail.com
Using authorisation database: /home/user/.cache/gmail-archiver/oauth.json
Using authorisation file: /home/user/.config/gmail-archiver/config.toml

https://accounts.google.com/o/oauth2/v2/auth?client_id=....

Visit displayed URL to authorize this application. Waiting...

In your browser, click Continue and then in the browser you will see the text: Authorisation redirect completed. You may close this window. At that point the archiving will begin.

Visit displayed URL to authorize this application. Waiting...
127.0.0.5 - - [17/May/2025 00:50:21] "GET /?code=...&scope=https://mail.google.com/ HTTP/1.1" 200 -
INFO: Logging in.
INFO: Deleting emails: False
INFO: Archiving 200 messages.

Due to the method of authorisation for OAuth, if you need to run this on a server that does not have a fully-featured browser (such as a headless machine), you must run this tool on a machine with one (and the ability to run a localhost server) to get the first access token. Once this is done, transfer configuration and the OAuth authorisation data to the server. From that point, the access token will be refreshed when necessary. You must do this for every email you plan to archive.

The OAuth authorisation file is also printed at startup. Example on Linux: ~/.config/cache/gmail-archiver/oauth.json. It will be stored with mode 0600.

Usage

Usage: gmail-archiver [OPTIONS] EMAIL [OUT_DIR]

  Archive Gmail emails and move them to the trash.

Options:
  --no-delete          Do not move emails to trash.
  -a, --auth-only      Only authorise the user.
  -d, --debug          Enable debug level logging.
  -D, --days INTEGER   Archive emails older than this many days. Set to 0 to
                       archive everything.
  --debug-imap         Enable debug level logging for IMAP.
  -r, --force-refresh  Force refresh the token.
  -h, --help           Show this message and exit.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gmail_archiver-0.0.5.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gmail_archiver-0.0.5-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file gmail_archiver-0.0.5.tar.gz.

File metadata

  • Download URL: gmail_archiver-0.0.5.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gmail_archiver-0.0.5.tar.gz
Algorithm Hash digest
SHA256 47db9f0fe1cdb41ad298ea3b259c4933238f235e9308b80b36abf63e25f339d7
MD5 738dfa53b20d0c914a4c5863a3e7affa
BLAKE2b-256 0d6a6fb9dd4cc91da371ce4e608a1933d9db4d13d7a7e569b27febeb30a3969c

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmail_archiver-0.0.5.tar.gz:

Publisher: publish.yml on Tatsh/gmail-archiver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gmail_archiver-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: gmail_archiver-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gmail_archiver-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e62cfc9dd4fcbd7910da04cfc070b163fe220d3ba821455a5fbde75b6bd2696a
MD5 3505599de7275c18883f014809f9985d
BLAKE2b-256 784a9362dd3995285f57e64b4c837767ad11047b7a19e92c30d4c8c61132c80b

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmail_archiver-0.0.5-py3-none-any.whl:

Publisher: publish.yml on Tatsh/gmail-archiver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page