This project provides a tool to generate XML files for configuring Gmail filters based on a YAML input file. It allows for easy management and customization of mail filters while adhering to a specified structure.
- Accepts a YAML input file containing author details, default values, and filter configurations.
- Supports a broad set of Gmail filter criteria (from, to, subject, query, attachments, etc.) and actions (archive, mark as read, star, forward, trash, labels and more).
- Automatically applies default values to boolean actions when optional parameters are omitted.
- Validates required author and filter fields before generating the XML.
- Outputs a formatted XML file compatible with Gmail's filter configuration.
project/
├── resources/
│ └── example.yaml # Example YAML file for testing
├── main.go # Main source code file
├── Makefile # Build and execution commands
├── .gitignore # Ignored files and directories
└── README.md # Project documentation
Each filter entry may include any combination of the following criteria:
from
,to
,subject
,hasTheWord
,doesNotHaveTheWord
,list
,query
,hasAttachment
Actions that can be applied:
label
,smartLabel
,forwardTo
- Boolean flags:
shouldArchive
,shouldMarkAsRead
,shouldStar
,shouldNeverSpam
,shouldAlwaysMarkAsImportant
,shouldNeverMarkAsImportant
,shouldTrash
All boolean flags inherit their defaults from the default
section when omitted. Every filter must declare at least one condition and one action.
- Go (Golang) 1.20 or later
git clone <repository-url>
cd project
Ensure that a YAML file with the required structure exists in the resources/
directory. You can use the provided example.yaml
as a reference:
author:
name: "John Doe"
email: "[email protected]"
default:
shouldArchive: true
shouldMarkAsRead: false
shouldStar: false
shouldNeverSpam: true
shouldAlwaysMarkAsImportant: false
shouldNeverMarkAsImportant: false
shouldTrash: false
filters:
- from: "[email protected]"
label: "Work"
- to: "[email protected]"
subject: "[Ticket]"
hasAttachment: true
label: "Support"
shouldMarkAsRead: true
shouldStar: true
- query: "list:announcements.example.com"
label: "Announcements"
forwardTo: "[email protected]"
shouldArchive: false
shouldAlwaysMarkAsImportant: true
Run the following command to compile the binary:
make build
Use the provided generate-sample
Makefile target to create the XML file for the bundled example:
make generate-sample
This command compiles the program (when needed) and generates an XML file next to the YAML input (for the example it will be resources/example.xml
).
To remove generated files, use:
make clean
Run the compiled binary directly with a specified YAML file as input:
./build/grc resources/example.yaml
The output XML file will be saved in the same directory as the input YAML file, with the .xml
extension. Override the name with the -output
flag when you need a different location.
This project is licensed under the MIT License. See the LICENSE file for more details.