Dovecot Plugin - zlib

最後更新: 2018-02-15

 


Zlib plugin

 

Zlib plugin can be used to read compressed mbox, maildir or dbox files.

It can be also used to write (via IMAP, LDA and/or LMTP) compressed messages to dbox or Maildir mailboxes.

Zlib plugin supports gzip, bzip2, xz and lz4

Config:

# Enable zlib plugin globally for reading/writing:

mail_plugins = $mail_plugins zlib

# Setting

plugin {
  zlib_save_level = 6 # 1..9; default is 6
  zlib_save = gz      # or bz2, xz or lz4
}

mbox

Compressed mbox files can be accessed only as read-only.

Maildir

The compression is detected by reading the first few bytes from the file.
The file name doesn't matter.

Dovecot not allowing clients to save mails that are detected as compressed.
(IMAP's APPEND command)

All mails must have ,S=<size> in their filename, where <size> contains the original uncompressed mail size

dsync to convert to a compressed Maildir:

-o maildir_copy_with_hardlinks=no (this is set to yes by default and will prevent compression)

Doc:

https://wiki2.dovecot.org/Plugins/Zlib

 


imap_zlib

 

imap_zlib adds support for COMPRESS=DEFLATE IMAP extension, reduce the bandwidth usage of IMAP

Config

mail_plugins = $mail_plugins zlib

protocol imap {
  mail_plugins = $mail_plugins imap_zlib
}

 * The zlib has to be enabled for imap_zlib to work

 


imap_quota

 

quota backends that Dovecot can use:

fs: Filesystem quota.
dirsize: The simplest and slowest quota backend
dict: Store quota usage in a dictionary (e.g. SQL).
maildir: Store quota usage in Maildir++ maildirsize files.

protocol imap {
  mail_plugins = $mail_plugins imap_quota
}

Quota recalculation

    doveadm quota recalc
    
Standard way to expunge messages with IMAP works by:

Marking message with \Deleted flag
Actually expunging the message using EXPUNGE command

=> move-to-Trash 用唔到

COPY the message to Trash mailbox
Mark the message with \Deleted
Expunge the message from the original mailbox.

Normally you'll have only one quota root, but in theory there could be e.g. "user quota" and "domain quota" roots. It's unspecified how the quota roots interact with each others (if at all)

quota = <backend>[:<quota root name>[:<backend args>]]

"*" as the mailbox name configures the default limit, which is applied on top of a mailbox-specific limit if found.

quota_rule = *:storage=1G
quota_rule2 = Trash:storage=+100M
quota_rule3 = SPAM:ignore

This means that the user has 1GB quota, but when saving messages to Trash mailbox it's possible to use up to 1.1GB of quota.(allow the clients' move-to-Trash feature work)
Additionally, any messages in the SPAM folder are ignored per the ignore directive and would not count against the quota.

"?" as the mailbox name works almost like "*". The difference is that "?" is used only if quota backend doesn't override the limit.

storage: Quota limit in kilobytes, 0 means unlimited.
messages: Quota limit in number of messages, 0 means unlimited.

http://wiki2.dovecot.org/Quota

MySQL

user_query = SELECT uid, gid, home, \
  concat('*:bytes=', quota_limit_bytes) AS quota_rule \
  FROM users WHERE userid = '%u'

# MySQL with userdb prefetch: Remember to prefix quota_rule with userdb_
# (just like all other userdb extra fields):
password_query = SELECT userid AS user, password, \
  uid AS userdb_uid, gid AS userdb_gid, \
  concat('*:bytes=', quota_limit_bytes) AS userdb_quota_rule \
  FROM users WHERE userid = '%u'

Custom Quota Exceeded Message

plugin {
   quota_exceeded_message = Quota exceeded, please go to http://www.example.com/over_quota_help for instructions on how to fix this.
}

OR

plugin {
   quota_exceeded_message = </path/to/quota_exceeded_message.txt
}

Quota warnings

quota_warning = <limit configuration> <quota-warning socket name> <parameters>

 * warning is ONLY executed at the exact time when the limit is being crossed

An example configuration:

plugin {
  quota_warning = storage=95%% quota-warning 95 %u
  quota_warning2 = storage=80%% quota-warning 80 %u
  quota_warning3 = -storage=100%% quota-warning below %u # user is no longer over quota
}

service quota-warning {
  executable = script /usr/local/bin/quota-warning.sh
  # use some unprivileged user for executing the quota warnings
  user = vmail
  unix_listener quota-warning {
  }
}

quota-warning.sh

#!/bin/sh
PERCENT=$1
USER=$2
cat << EOF | /usr/local/libexec/dovecot/dovecot-lda -d $USER -o "plugin/quota=maildir:User quota:noenforcing"
From: [email protected]
Subject: quota warning

Your mailbox is now $PERCENT% full.
EOF

Quota grace

plugin {
  #  default in v2.2+ this limit is 10%
  quota_grace = 10%%
}

 


fts - Full text search indexing

 

By default the FTS indexes are updated only while searching,
(so neither the LDA nor an IMAP APPEND command updates the indexes immediately.)

Dovecot sends periodic "* OK Indexed n% of the mailbox"

Manually

# Scan v2.1:

doveadm index -u user@domain -q INBOX

# Rescan

doveadm fts rescan -u user@domain

 


 

 

Creative Commons license icon Creative Commons license icon