Package: gmail-filter-manager
gmail_filter_managerGmail filer manager using YAML format.InstallationBy pip:$ pip install gmail_filter_managerBy Homebrew:$ brew install rcmdnk/rcmdnkpac/gmail_filter_managerBy script:$ curl -fsSL https://raw.github.com/rcmdnk/gmail_filter_manager/install/install.sh| shThis will install scripts to/usr/binand 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/ shOr, 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.yamlScriptsgfm_extractA script to convert mailFilters.xml, which can be exported from Gmail,
to YAML format.Default input name ismailFilters.xml.
Default ouput name ismailFilters.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 forgfm_make.gfm_makeA script to make XML of filters to be imported in Gmail.Input is YAML format.Default input name ismailFilters.yaml.
Default ouput name ismailFilters.yaml.filters:-from:"foo@example.com"lable:"foo"-subject:"[test]"lable:"test"shouldMarkAsRead:"true"namespaces:apps:http://schemas.google.com/apps/2006atom:http://www.w3.org/2005/Atomnamespacescan be omitted.
It is included if you usegfm_extract,
but it will be automatically added bygfm_makeeven if is omitted.Filter propertiesFilter Criteria PropertiesNameXML attributeDescriptionFromname="from"The email comes from this address.Toname="to"The email is sent to this address.Subjectname="subject"The email's title includes this value.Has the wordsname="hasTheWord"The email has this value (search operators).Doesn't havename="doesNotHaveTheWord"The email doesn't have this value (search operators).Has attachmentname="hasAttachment"true or false for if the email has attachments.Don't include chatsname="excludeChats"true or false for if the email includes chats.Sizename="size"The email size. If it is specified, the mail size is compared to this value with sizeOperator and sizeUnit.Size operatorname="sizeOperator"s_sl (greater than) or s_ss (smaller than).Size unitname="sizeUnit"Unit of email size: s_sb (B), s_skb (kB) or s_smb (MB).hasTheWordanddoesNotHaveTheWordare search operators.
Such a label can be specified here.Please check following help for more details:Search operators you can use with Gmail - Gmail HelpFilter Action PropertiesNameXML attributeDescriptionSkip the Inbox (Archive it)name="shouldArchive"Mark as readname="shouldMarkAsRead"Star itname="shouldStar"Apply the labelname="label"Forward it toname="forwrdTo"Delete itname="shouldTrash"Never send it to Spamname="shouldNeverSpam"Always mark it as importantname="shouldAlwaysMarkAsImportant"Never mark it as importantname="shouldCategorize asname="smartLabelToApply"Add smart label. value can be "^smartlabel_personal", "^smartlabel_social", "^smartlabel_promo", "^smartlabel_group" or "^smartlabel_notification".Tips:You can use array forlabelto set several labels on the same criteria.How to export/import filtersCheckExport or import filtersin the official help:Create rules to filter your emails - Gmail HelpFilter TipsNumbering labelsGmail's labels are sorted automatically.But you may want to put some labels suchWork, which is always at the bottom,
on the top.To do it, you can set prefix numbers on labels.01_Work02_Private03_OthersThen, these labels are listed in this order.Use labels like folderGmail has onlylabel, but some other mail clients havefolder.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 asfolder,has:nouserlabelskeyword is useful.IfhasTheWordincludes 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 labelfoofor mails fromfoo@example.com,
and put a labelexamplefor mails fromexample.comdomain other thanfoo@example.com.
In addition, if it is not fromfoo, the mail is archived.And the last filter send other mails tootherslabel,
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 InboxYou may have more labels with which mails must skip the Inbox.In this case,DummyInboxmethod label can be used instead of
settingshouldArchive: "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 additional99_DummyInboxlabel
to which you want to remain in the Inbox.And the final filter archives mails without99_DummyInboxlabel.In the above setting,has:nouserlabelsis not used forfrom:example.com.
Therefore the mail fromfoo@example.comhas two labels.The main difference fromUse labels like foldermethod
is that you can put two different labels between them archive policies are different.IfshouldArchiveis 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 inHas the wordsand save, and remove the space and save again...)Referencesgmail_filter_manager: GmailのフィルタをYAMLで簡単に管理する