Giter VIP home page Giter VIP logo

php-mail-filters's Introduction

PHP Mail Filters Library

Build Status Latest Stable Version Latest Unstable Version License

This is a PHP package that enables you to create handy filtering features on E-mail messages (similar to that of Gmail filters feature) utilizing the PHP IMAP extension. The library makes it easy to hook up your own IMAP connection to it, all you need to do is implement few adapter methods for your library needed for the filtering and actions functionality.

Currently the adapter is implemented for the following IMAP libraries:

Features:

  • Apply filters your E-mail messages by setting criteria over the following fields:

    • To
    • All Recipients (To, Cc, Bcc)
    • Subject
    • From
    • Body Text
    • Attachments
  • Take one of the following actions based on matched filters:

    • Delete message from your mailbox.
    • Move the message to a different mail folder.
    • Copy the message to another mail folder.
    • Return user specified variables.
    • Mark message status (Read, Unread and Important)

Requirements:

  • PHP 7.2+
  • PHP IMAP extension must be installed and activated
  • A PHP IMAP library to read messages (preferably use one of the 2 listed above if you have none, or write an adapter to the one you are using)

Example:

//Step 1: Build the filter(s) with Criteria and Actions 
$mailFilter = new Filter();
$mailFilter
   ->setName('Move mails that contains "RID" in its subject to Tagged folder')
   ->addCriterion(new SubjectCriterion('*RID*'))
   ->addAction(new MoveMailAction('Tagged'));

$mailFilters = new MailFilter();
$mailFilters->addFilter($mailFilter);

// Step 2: Read the message
$mailbox = new PhpImap\Mailbox(
   '{imap.example.org:993/imap/ssl}INBOX',
   '[email protected]',
   'SecretPassword'
);

$mailMessageAdapter = new MailFilters\Adapters\BarbushinImap\MessageAdapter($mailbox);
$messageIds = $mailbox->searchMailbox('ALL');
$firstMessage = $mailbox->getMail();


// Step 3: Apply filters to message
$mailMessageAdapter->setMessage($firstMessage)
$mailFilters->applyFilters($mailMessageAdapter);

The above example will check if the given email contains "RID" in its subject and move the message to a new MailBox "Tagged" directory.

In Progress (Unfinished work):
  • Adding unit and functional tests to the library

php-mail-filters's People

Contributors

aymanrb avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.