PHP library for generating importable Gmail filters in XML
Find a file
2018-06-01 19:44:58 +01:00
bin Fix CS issues 2018-03-20 20:34:32 +00:00
config Dump file, add output 2018-01-11 00:48:02 +00:00
src Add the toArray method on Filter 2018-06-01 19:33:57 +01:00
tests/Unit Remove blank line 2018-06-01 19:44:58 +01:00
.gitignore Ignore filters.php 2018-01-04 23:22:02 +00:00
.php_cs.dist Use travis 2018-03-20 20:29:21 +00:00
.travis.yml Use travis 2018-03-20 20:29:21 +00:00
composer.json Use travis 2018-03-20 20:29:21 +00:00
LICENSE Create LICENSE 2017-12-30 11:11:40 +00:00
phpunit.xml.dist Initial setup 2017-11-03 11:18:08 +00:00
README.md Replace Circle CI badge with Travis 2018-05-31 21:31:32 +01:00

Gmail Filter Builder

Build Status

This library allows you to define Gmail filters in PHP, and then generate XML that you can import into Gmail's filter settings

Inspired by https://github.com/antifuchs/gmail-britta.

Installation and Basic Usage

Step 1: Require the Library

composer require opdavies/gmail-filter-builder

Step 2: Create Your Filters File

Create a filters.php file that returns an array of Filter objects.

For example:

<?php

require_once __DIR__.'/vendor/autoload.php';

$filters = [];

// Add your filters.

return $filters;

Step 3: Generate the XML

Run ./vendor/bin/generate-filters to generate the XML for the filters and export it into a file.

Options

  • --input-file - specify the name of the file containing the filters (defaults to filters.php).
  • --output-file - specify the name of the output file (defaults to filters.xml).

Step 4: Import the Filters

Log in to your Gmail account and import your filters using the generated XML file.

Available Methods

Conditions

Conditions that a message must satisfy for the filter to be applied:

  • has - can be used to check for various properties, such as attachments, stars or labels. Can also be used as an alternative to some of the following methods previously - e.g. from:john@example.com - and can be useful for more advanced queries.
  • hasNot - the opposite of the above.
  • from - if the message is from a certain name or email address.
  • to - if the message is to a certain name or email address.
  • subject - if the message has a certain subject.
  • hasAttachment - if the message has an attachment.
  • excludeChats - exclude chats from the results (false by default).

Actions

Actions you can apply to messages that match the conditions:

  • label - add a label to the message.
  • archive - archive the message (skip the inbox).
  • labelAndArchive - both add a label and archive the message.
  • spam - mark the message as spam.
  • neverSpam - never mark the message as spam.
  • trash - delete the message.
  • read - mark the message as read.
  • star - star the message.
  • forward - forward the message to another email address.
  • important - mark the message as important.
  • notImportant - mark the message as not important.
  • categorise - apply a smart label to the message.

Filter Examples

// If an email is from a certain address, add a label.
Filter::create()
    ->from('john@example.com')
    ->label('Something');

References