Coder Social home page Coder Social logo

mcv21 / ruler-of-exchange Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tvdw/ruler-of-exchange

0.0 2.0 0.0 16 KB

Sieve for Exchange but really just Perl doing HTTP requests

License: Do What The F*ck You Want To Public License

Perl 100.00%

ruler-of-exchange's Introduction

Ruler of Exchange

Sieve for Exchange but really just Perl doing HTTP requests

So the company I work for switched from a Linux-based mail stack to Microsoft's Exchange product... We used to have Sieve filters available, but that went away with the move, and Exchange only has its stupid rule editor.

So I wrote a quick replacement for Sieve: it's not nearly as powerful, but I managed to port my rules over without too much effort, other than writing this program. Maybe it helps someone else as well?

Usage

./upload.pl -c <config file>

Config format

Example

user "myusername";
host "exchange.example.com";

folder Inbox {
    # This will automatically create the folder if it does not exist
    folder Some-Mailing-List { }
}

# Must be created through the (web-)interface
category "To me";

match header "<some-mailing-list-id.lists.example.com>" {
    action setread;
    last-action move Inbox/Some-Mailing-List;
}

match recipient "[email protected]" {
    action category "To me";
}

Format

There are three allowed top-level settings, user, host, and category.

  • user: Specify the username to upload rules for. required
  • host: Specify the hostname to upload rules to. required
  • category: Define a category name that can later be used. Can be specified multiple times. Optional, but if you use categories, they must be declared prior to using them in a rule.

There are two block types, which are both allowed to recurse, folder and match.

folder specifies your folder structure. It is recommended to start with a definition for your inbox, and create your other folders in there. Folder blocks do not currently allow specifying any settings other than the name. When specifying folders in rules, their names are recursively joined using a / (forward slash).

folder Inbox {
    folder MyFolder { } # Becomes "Inbox/MyFolder"
    folder AnotherFolder { } # Becomes "Inbox/AnotherFolder"
}

match specifies your filter structure. After the match keyword, its expression follows (see the "Expressions" section), following with a bracket ({) indicating the start of its body. Within this body more match blocks may be created, applying an effective AND to your filters.

match header "X-Spam: yes" {
    action delete;
}

Within a match block actions may be specified. For information about these, see the "Actions" section.

A note on quoting: it is optional to quote strings that do not contain whitespace, semicolons (;), or brackets ({, [, ], }). If needed, escaping operations can be done using the usual backslash (\).

Expressions

Six types of expressions are currently implemented, plus their negated versions (specified using a not after match).

# Matches mails that contain "List-Id: " in their headers
match header "List-Id: " { }
# Matches mails that contain "Tom" or "Code" in the subject
match subject ["Tom" "Code"] { }
# Others:
match body "some string" { }
match recipient "[email protected]" { 
match not from "[email protected]" { } # Note the negation
match subject-or-body [ "Hello World" "Just testing" ] { }

Actions

Actions are indicated using the action and last-action keywords. In case of last-action, rule processing will stop after the action is executed.

Five actions are currently implemented :

  • delete: deletes the message
  • move <folder>: moves the message to a folder. The folder must be configured using a folder block
  • copy <folder>: same as move, but copies instead
  • setread: marks the message as read
  • category <category>: labels the message with a category. The category must be configured using a category option.

Caveats

  • This software was implemented in a very short amount of time, bugs can happen
  • Rules are not being applied atomically; this means that while rules are being saved, some mails may get filtered in unexpected ways
  • Exchange supports a lot more types of rules and actions, I only implemented the most basic set I needed to satisfy what I need. Patches welcome
  • The config parser is dumb :-)

License

This is free open-source software. For more details, see LICENSE

ruler-of-exchange's People

Contributors

demerphq avatar dveeden avatar tkluck-booking avatar tvdw avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.