PHPackages                             altzone/sievefilter-apply - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. altzone/sievefilter-apply

ActiveRoundcube-plugin[Mail &amp; Notifications](/categories/mail)

altzone/sievefilter-apply
=========================

Retroactively apply Sieve filter rules to existing messages in a folder

v1.0.1(1w ago)021GPL-3.0-or-laterPHPPHP &gt;=7.4

Since Mar 8Pushed 1w ago1 watchersCompare

[ Source](https://github.com/altzone/roundcube-sievefilter-apply)[ Packagist](https://packagist.org/packages/altzone/sievefilter-apply)[ Docs](https://github.com/altzone/roundcube-sievefilter-apply)[ RSS](/packages/altzone-sievefilter-apply/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

sievefilter\_apply - Apply Sieve Filters to Existing Messages
=============================================================

[](#sievefilter_apply---apply-sieve-filters-to-existing-messages)

A Roundcube plugin that retroactively applies Sieve filter rules to existing messages in a mailbox folder.

Sieve filters only apply to **new incoming messages**. This plugin bridges the gap by letting users run their existing Sieve rules against messages already in their mailbox, similar to Thunderbird's "Run Filters on Folder" or Zimbra's "Apply Filter" feature.

Features
--------

[](#features)

### Mail View

[](#mail-view)

- **Toolbar button** to apply filters to the current folder
- **Filter selection** dialog with checkboxes to choose which rules to apply
- **Preview mode** showing a summary of planned actions before execution
- **Detailed view** listing each affected message with its action
- **Result summary** with per-folder breakdown (moved, flagged, deleted)

### ManageSieve Settings Integration

[](#managesieve-settings-integration)

- **"Apply to folder" button** in the Sieve filter management toolbar
- Apply a single selected filter to any folder via a folder picker dialog

### Apply Now After Save (v1.0.1)

[](#apply-now-after-save-v101)

- **Automatic prompt** after saving a filter: "Apply it to existing messages?"
- Works from both **Settings &gt; Filters** and **Mail view** (right-click &gt; Create filter)
- Opens a **folder picker** to choose which folder to apply the filter to
- Zero modification to the ManageSieve plugin — 100% client-side JS interception

### Safety &amp; Security

[](#safety--security)

- **Preview before execute** workflow prevents accidental bulk operations
- **Server-side re-evaluation** on execute: the server re-evaluates all Sieve rules against message headers before applying actions, preventing any client-side tampering
- **Mailbox validation**: the target folder is validated against the user's subscribed folder list before any operation
- **Redirect actions are skipped** by default to prevent email storms
- **Reject actions are skipped** by default (meaningless for received messages)
- **Configurable message limit** to avoid runaway operations on large folders
- **ReDoS protection**: regex patterns from Sieve rules are executed with backtracking limits
- **No information leakage**: internal server errors are logged but never exposed to the browser
- **XSS prevention**: all user-supplied content is escaped before DOM insertion
- **CSRF protection**: all requests use Roundcube's built-in request token mechanism

Requirements
------------

[](#requirements)

ComponentVersionRoundcube&gt;= 1.6PHP&gt;= 7.4`managesieve` pluginEnabled and configuredDovecot ManageSieveAccessible (port 4190)This plugin is a **companion** to the built-in `managesieve` plugin. It reuses its libraries (`rcube_sieve`, `rcube_sieve_script`) and connection settings without any code duplication.

Installation
------------

[](#installation)

### Manual

[](#manual)

1. Copy the `sievefilter_apply` directory to your Roundcube `plugins/` folder:

```
cp -r sievefilter_apply /path/to/roundcube/plugins/
```

2. Add the plugin to your Roundcube configuration (`config/config.inc.php`):

```
$config['plugins'] = [
    // ...
    'managesieve',       // Required dependency
    'sievefilter_apply',
];
```

3. Optionally copy and edit the configuration file:

```
cp plugins/sievefilter_apply/config.inc.php.dist plugins/sievefilter_apply/config.inc.php
```

### Composer

[](#composer)

```
composer require altzone/sievefilter-apply
```

Then enable the plugin in your Roundcube configuration as shown above.

Configuration
-------------

[](#configuration)

All settings are optional. Defaults are designed for safe operation.

```
// Maximum number of messages to process per operation (default: 500)
$config['sievefilter_apply_max_messages'] = 500;

// IMAP header fetch batch size (default: 50)
$config['sievefilter_apply_batch_size'] = 50;

// Skip redirect actions in retroactive mode (default: true)
// Prevents email storms when applying filters to existing messages
$config['sievefilter_apply_skip_redirect'] = true;

// Skip reject/ereject actions in retroactive mode (default: true)
// Reject is meaningless for already-received messages
$config['sievefilter_apply_skip_reject'] = true;
```

Supported Sieve Features
------------------------

[](#supported-sieve-features)

### Test Types

[](#test-types)

TestSupportNotes`header`FullAll standard headers, multi-value tested individually per RFC 5228`address`FullSupports `:all`, `:localpart`, `:domain` parts; uses RFC 5321-compliant address parser`envelope`PartialFalls back to address test on From/To headers (see Limitations)`size`Full`:over` and `:under` comparators with K/M/G suffixes`exists`FullTests header presence (not emptiness)`allof`FullNested AND logic with short-circuit evaluation`anyof`FullNested OR logic with short-circuit evaluation`not`FullNegation`true` / `false`Full`body`Not supportedRequires message body download`date`Not supported### Match Types

[](#match-types)

TypeSupportNotes`is`FullExact case-insensitive match`contains`FullSubstring search, case-insensitive`matches`FullSieve wildcards (`*` and `?`) with proper escape handling (`\*`, `\?`)`regex`FullPCRE matching with ReDoS backtracking protection### Actions

[](#actions)

ActionSupportNotes`fileinto`FullCreates target folder if it does not exist`discard`FullDeletes the message`addflag`FullAdds IMAP flag (RFC 5232)`setflag`FullSets IMAP flag (RFC 5232, distinct from addflag)`removeflag`FullRemoves IMAP flag`keep`FullNo action (message stays)`stop`FullStops rule evaluation`redirect`SkippedDisabled by default to prevent email storms`reject` / `ereject`SkippedDisabled by default (message already received)### Rule Evaluation

[](#rule-evaluation)

Per RFC 5228, **all matching rules fire** and their actions accumulate, unless an explicit `stop` command halts evaluation. This matches the behavior of standard Sieve implementations.

### Flag Mapping (Sieve to IMAP)

[](#flag-mapping-sieve-to-imap)

Sieve FlagIMAP Flag`\Seen`SEEN`\Answered`ANSWERED`\Flagged`FLAGGED`\Deleted`DELETED`\Draft`DRAFT`$Forwarded`FORWARDED`$MDNSent`MDNSENTArchitecture
------------

[](#architecture)

```
sievefilter_apply (companion plugin)
        |
        |--- reuses ---> managesieve/lib/rcube_sieve.php        (connection)
        |--- reuses ---> managesieve/lib/rcube_sieve_script.php (parsing)
        |
        |--- Phase 1: Connect to Sieve, fetch & parse active script
        |--- Phase 2: Fetch IMAP headers in batches, evaluate rules
        |--- Phase 3: Preview results to user for confirmation
        |--- Phase 4: Re-evaluate rules server-side, execute IMAP actions

```

The plugin uses the same connection parameters as `managesieve` (`managesieve_host`, `managesieve_port`, `managesieve_usetls`, `managesieve_conn_options`, etc.). No additional server configuration is required.

### Security Model

[](#security-model)

- **No client trust**: the execute phase re-evaluates Sieve rules server-side against each message's actual headers. The client-supplied action list is only used to identify which UIDs to process.
- **Mailbox validation**: every mailbox parameter is validated against the user's subscribed folder list before any IMAP operation.
- **Credentials**: uses Roundcube's session API (`get_user_name()`, `get_user_password()`) - no direct `$_SESSION` access.
- **Input sanitization**: all user input goes through `rcube_utils::get_input_value()`.
- **CSRF**: inherits Roundcube's request token protection via `rcmail.http_post()`.

Known Limitations
-----------------

[](#known-limitations)

1. **Envelope tests** fall back to address tests on From/To headers since SMTP envelope data is not available retroactively. This may produce false positives for forwarded mail or mailing lists.
2. **Body and date tests** are not supported as they require downloading full message content.
3. **Maximum 500 messages** per operation by default. Increase `sievefilter_apply_max_messages` for larger folders, at the cost of longer processing time.
4. **No background processing**. Analysis and execution happen synchronously; the UI is blocked during the operation.
5. **No incremental processing**. If execution fails mid-batch, successfully processed messages are not rolled back.
6. **MIME header decoding** is applied before rule evaluation. This matches the behavior of Dovecot's Sieve implementation but may differ from other implementations.
7. **Headers are fetched individually** per message. Bulk IMAP FETCH is not used, which may be slow on very large folders over high-latency connections.

Localization
------------

[](#localization)

The plugin ships with English (`en_US`) and French (`fr_FR`) translations. Additional translations can be added by creating files in the `localization/` directory following the same format.

License
-------

[](#license)

GNU General Public License v3.0 (GPLv3) - compatible with Roundcube and the managesieve plugin.

Credits
-------

[](#credits)

Developed as a companion plugin to Roundcube's built-in [managesieve](https://plugins.roundcube.net/packages/roundcube/managesieve) plugin.

###  Health Score

38

—

LowBetter than 86% of packages

Maintenance98

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

13d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b5914a4cff0100e33b130f2381ed2c648026b5c2ddb84d691a8bf19bce412b12?d=identicon)[altzone](/maintainers/altzone)

---

Top Contributors

[![altzone](https://avatars.githubusercontent.com/u/3207650?v=4)](https://github.com/altzone "altzone (8 commits)")

---

Tags

dovecotemailimapmail-filtersmanagesievephproundcuberoundcube-pluginsievepluginroundcubefiltersievemanagesieve

### Embed Badge

![Health badge](/badges/altzone-sievefilter-apply/health.svg)

```
[![Health](https://phpackages.com/badges/altzone-sievefilter-apply/health.svg)](https://phpackages.com/packages/altzone-sievefilter-apply)
```

###  Alternatives

[jason-munro/cypht

Lightweight Open Source webmail written in PHP and JavaScript

1.4k142.4k](/packages/jason-munro-cypht)[kartik-v/yii2-widget-growl

A widget to generate growl based notifications using bootstrap-growl plugin (sub repo split from yii2-widgets)

384.1M14](/packages/kartik-v-yii2-widget-growl)[henrique-borba/php-sieve-manager

A modern (started in 2022) PHP library for the ManageSieve protocol (RFC5804) to create/edit Sieve scripts (RFC5228). Used by Cypht Webmail.

23120.5k1](/packages/henrique-borba-php-sieve-manager)[kartik-v/yii2-widget-alert

A widget to generate alert based notifications using bootstrap-alert plugin (sub repo split from yii2-widgets)

284.0M22](/packages/kartik-v-yii2-widget-alert)[railsware/mailtrap-php

The Mailtrap SDK provides methods for all API functions.

54710.5k](/packages/railsware-mailtrap-php)[protonlabs/libsieve-php

libsieve-php is a library to manage and modify sieve (RFC5228) scripts.

2374.0k](/packages/protonlabs-libsieve-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
