Had to activate the following modules in SquirrelMail:

  • server_settings_backend
  • server_side_filters
  • server_side_filters_maildrop

In the sqmail/config/config.php file we must have the following settings:

$default_folder_prefix = 'INBOX';
$trash_folder = '.Trash';
$sent_folder = '.Sent';
$draft_folder = '.Drafts';

Especially important is the $default_folder_prefix, which is removed from the maildir path in individual rules in


Since we need all the mail sent to a deliverquota script we had to edit the following file:

// This variable was added
$external_program = "|deliverquota -c -w \${WARNSIZE} ";

// build this filter's action
if ($rule['ACTION'] == 'DELETE') {
  $action = 'to /dev/null';
  $parsed_filter_rules[$index]['COPY_TO_FOLDER'] = 'OFF';
  $parsed_filter_rules[$index]['SEND_TO_ADDRESS'] = 'OFF';
else if ($rule['COPY_TO_FOLDER'] == 'ON' && $rule['SEND_TO_ADDRESS'] == 'ON')
  $action = 'cc "' . $external_program . str_replace(" ", "\ ", $rule['TARGET_FOLDER'])
  . "\"\n $deliver_action \"!" . $rule['EMAIL_ADDRESS'] . '"';
else if ($rule['COPY_TO_FOLDER'] == 'ON')
  $action = "$deliver_action \"" . $external_program . str_replace(" ", "\ ", $rule['TARGET_FOLDER']) . "\"";
else if ($rule['SEND_TO_ADDRESS'] == 'ON')
  $action = "$deliver_action \"!" . $rule['EMAIL_ADDRESS'] . '"';
  $action = '';

The bold parts were added to the code. str_replace deals with folder names with spaces.

And here is a configuration for the SQL backend:

$filter_rules_storage_info = array(
  'BACKEND' => 'sql',
  'DSN' => array('VALUE' => 'mysql://postfix:*****@localhost/postfix'),
  'QUERY' => array('VALUE' => "SELECT `rule` FROM `maildrop` WHERE `user` = '%1'"),
  'SAVE_QUERY' => array('VALUE' => "REPLACE INTO `maildrop` SET `rule` = '%3', `user` = '%1'"),
$custom_mail_location = array('VALUE' => '${MAILDIR}');

Note, that we are using REPLACE instead of UPDATE, since there is always a single entry in the database for a specific user. Discussion about SQL command options are discussed here:


Also we set $custom_mail_location, which is a complete path to user’s maildir. Here is a database structure we are using:

CREATE TABLE `maildrop` (
  `user` varchar(128) collate utf8_generic_ci NOT NULL,
  `rule` text collate utf8_generic_ci NOT NULL,
  `updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `generated` timestamp NOT NULL default '0000-00-00 00:00:00',
  UNIQUE KEY `user` (`user`)

We can have a script which generates filter files for individual users from this database. These filters can then be included by the main script

`test -f ${USER_FILTER}`
if( $RETURNCODE == 0)
  include "${USER_FILTER}"

Problems to deal with are encoding of rules (using national characters for example in Subject:) since maildrop and SquirellMail uses different encoding. Also forwarding of messages in maildrop to other external e-mail addresses.

Install maildrop filters on SquirrelMail webmail client
Tagged on:     

Leave a Reply