Skip to main content

gmail_filter_manager

Gmail filer manager using YAML format.

Installation

By pip:

$ pip install gmail_filter_manager

By Homebrew:

$ brew install rcmdnk/rcmdnkpac/gmail_filter_manager

By script:

$ curl -fsSL https://raw.github.com/rcmdnk/gmail_filter_manager/install/install.sh| sh

This will install scripts to /usr/bin and you may be asked root password.

If you want to install other directory, do like:

$ curl -fsSL https://raw.github.com/rcmdnk/gmail_filter_manager/install/install.sh|  prefix=~/usr/local/ sh

Or, simply download scripts in bin/ and place where you like.

If you use the script directly, you need to install ruaml.yaml:

$ pip install ruamel.yaml

Scripts

gfm_extract

A script to convert mailFilters.xml, which can be exported from Gmail, to YAML format.

Default input name is mailFilters.xml. Default ouput name is mailFilters.yaml.

They can be changed by arguments:

$ gfm_extract [input name [output name]]

Once you have YAML file, you can edit it and use it as an input for gfm_make.

gfm_make

A script to make XML of filters to be imported in Gmail.

Input is YAML format.

Default input name is mailFilters.yaml. Default ouput name is mailFilters.yaml.

filters:
- from: "foo@example.com"
  lable: "foo"
- subject: "[test]"
  lable: "test"
  shouldMarkAsRead: "true"
namespaces:
  apps: http://schemas.google.com/apps/2006
  atom: http://www.w3.org/2005/Atom

namespaces can be omitted. It is included if you use gfm_extract, but it will be automatically added by gfm_make even if is omitted.

Filter properties

Filter Criteria Properties

Name XML attribute Description
From name="from" The email comes from this address.
To name="to" The email is sent to this address.
Subject name="subject" The email's title includes this value.
Has the words name="hasTheWord" The email has this value (search operators).
Doesn't have name="doesNotHaveTheWord" The email doesn't have this value (search operators).
Has attachment name="hasAttachment" true or false for if the email has attachments.
Don't include chats name="excludeChats" true or false for if the email includes chats.
Size name="size" The email size. If it is specified, the mail size is compared to this value with sizeOperator and sizeUnit.
Size operator name="sizeOperator" s_sl (greater than) or s_ss (smaller than).
Size unit name="sizeUnit" Unit of email size: s_sb (B), s_skb (kB) or s_smb (MB).

hasTheWord and doesNotHaveTheWord are search operators. Such a label can be specified here.

Please check following help for more details:

Search operators you can use with Gmail - Gmail Help

Filter Action Properties

Name XML attribute Description
Skip the Inbox (Archive it) name="shouldArchive"
Mark as read name="shouldMarkAsRead"
Star it name="shouldStar"
Apply the label name="label"
Forward it to name="forwrdTo"
Delete it name="shouldTrash"
Never send it to Spam name="shouldNeverSpam"
Always mark it as important name="shouldAlwaysMarkAsImportant"
Never mark it as important name="should
Categorize as name="smartLabelToApply" Add smart label. value can be "^smartlabel_personal", "^smartlabel_social", "^smartlabel_promo", "^smartlabel_group" or "^smartlabel_notification".

Tips:

You can use array for label to set several labels on the same criteria.

How to export/import filters

Check Export or import filters in the official help:

Create rules to filter your emails - Gmail Help

Filter Tips

Numbering labels

Gmail's labels are sorted automatically.

But you may want to put some labels such Work, which is always at the bottom, on the top.

To do it, you can set prefix numbers on labels.

  • 01_Work
  • 02_Private
  • 03_Others

Then, these labels are listed in this order.

Use labels like folder

Gmail has only label, but some other mail clients have folder.

  • Label: User can set several labels on the same message.
  • Folder: A message is included only in one folder.

And all filters are always applied to the new mail.

In this case, if the mail is caught by several filters for labels, several labels are set.

To avoid several labels to use it as folder, has:nouserlabels keyword is useful.

If hasTheWord includes this keyword, only the mail which still does not have the label can be caught.

e.g.)

filters:
- hasTheWord: "from:foo@example.com"
  label: "00_foo"
- hasTheWord: "has:nouserlabels from:example.com"
  label: "01_example"
  shouldArchive: "true"
- hasTheWord: "has:nouserlabels"
  label: "09_others"
  shouldArchive: "true"

These filters put a label foo for mails from foo@example.com, and put a label example for mails from example.com domain other than foo@example.com. In addition, if it is not from foo, the mail is archived.

And the last filter send other mails to others label, and skip the Inbox. Such a filter make you free from notification bombs in the Gmail app of a cell phone.

To use such filters, the order is important.

Note: If you modify filters in the Gmail web interface, the order is changed: the modified one goes to the bottom.

This is one of the reasons why I wanted these scripts.

Use DummyInbox to leave only specific mails in the Inbox

You may have more labels with which mails must skip the Inbox.

In this case, DummyInbox method label can be used instead of setting shouldArchive: "true" for filters.

The setting is like this:

filters:
- hasTheWord: "from:foo@example.com"
  label:
  - "00_foo"
  - "99_DummyInbox"
- hasTheWord: "from:example.com"
  label:
  - "01_example"
  - "99_DummyInbox"
- hasTheWord: "from:example2.com"
  label: "02_example2"
- hasTheWord: "from:example3.com"
  label: "03_example3"
- hasTheWord: "from:example4.com"
  label: "04_example4"
- hasTheWord: "from:example5.com"
  label: "05_example5"
- hasTheWord: "has:nouserlabels"
  label: "09_others"
- hasTheWord: "-label:99_DummyInbox"
  shouldArchive: "true"

This setting put additional 99_DummyInbox label to which you want to remain in the Inbox.

And the final filter archives mails without 99_DummyInbox label.

In the above setting, has:nouserlabels is not used for from:example.com. Therefore the mail from foo@example.com has two labels.

The main difference from Use labels like folder method is that you can put two different labels between them archive policies are different.

If shouldArchive is in the each label, all mails associated to the label are archived. But this method can remain what you want easily.

In addition, only the order of the filters can be free other than the last label, so that it makes easy to modify with the web interface. Although you still need to "modify" hasTheWord: "-label:99_DummyInbox" filter after any other filter changes... (such adding one space in Has the words and save, and remove the space and save again...)

References

Metadata

Release files for gmail-filter-manager 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gmail-filter-manager 0.1.3
File Size Uploaded Provenance
gmail_filter_manager-0.1.3.tar.gz 6.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gmail-filter-manager 0.1.3
File Interpreter ABI Platform
gmail_filter_manager-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / gmail_filter_manager-0.1.3.tar.gz

Download URL gmail_filter_manager-0.1.3.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9d781a562b9f8f223b4863ecea4beaca6d43896e292bd81639b7c0357d1a0638
BLAKE2b-256 checksum
How to use checksums
357e72997a440b40e76ab023f614ff374e426be8ca2d707da390e441e8ac5cff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / gmail_filter_manager-0.1.3-py3-none-any.whl

Download URL gmail_filter_manager-0.1.3-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6226094a98b88c1e59a28fd8d6ee814542ad31c7001a2e7e9cd445ac5cadf34
BLAKE2b-256 checksum
How to use checksums
eced6b26dc5773bc368b2c02ef11b0fcae1beaf28d569797fd69b38b861f2543
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for gmail-filter-manager 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page