My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
#!/usr/bin/env bash

# Author: Zhang Huangbin (michaelbibby <at> gmail.com)

#---------------------------------------------------------------------
# This file is part of iRedMail, which is an open source mail server
# solution for Red Hat(R) Enterprise Linux, CentOS, Debian and Ubuntu.
#
# iRedMail is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iRedMail is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with iRedMail. If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------

# -------------------------------------------------------
# Dovecot & dovecot-sieve.
# -------------------------------------------------------

# For dovecot SSL support.
dovecot_ssl_config()
{
ECHO_INFO "Enable TLS support."

if [ X"${ENABLE_DOVECOT_SSL}" == X"YES" ]; then
# Enable ssl. Different setting in v1.1, v1.2.
if [ X"${DOVECOT_VERSION}" == X"1.1" ]; then
cat >> ${DOVECOT_CONF} <<EOF
# SSL support.
ssl_disable = no
EOF
elif [ X"${DOVECOT_VERSION}" == X"1.2" ]; then
cat >> ${DOVECOT_CONF} <<EOF
# SSL support.
ssl = yes
EOF
fi

cat >> ${DOVECOT_CONF} <<EOF
verbose_ssl = no
ssl_key_file = ${SSL_KEY_FILE}
ssl_cert_file = ${SSL_CERT_FILE}
EOF
fi

echo 'export status_dovecot_ssl_config="DONE"' >> ${STATUS_FILE}
}

dovecot_config()
{
ECHO_INFO "==================== Dovecot ===================="

[ X"${ENABLE_DOVECOT}" == X"YES" ] && \
backup_file ${DOVECOT_CONF} && \
chmod 0755 ${DOVECOT_CONF} && \
ECHO_INFO "Configure dovecot: ${DOVECOT_CONF}."

cat > ${DOVECOT_CONF} <<EOF
${CONF_MSG}
EOF

if [ X"${DOVECOT_VERSION}" == X"1.1" ]; then
cat >> ${DOVECOT_CONF} <<EOF
umask = 0077
EOF
fi

cat >> ${DOVECOT_CONF} <<EOF
# Provided services.
protocols = ${DOVECOT_PROTOCOLS}

# Listen addresses. for Dovecot-1.1.x.
# ipv4: *
# ipv6: [::]
#listen = *, [::]
listen = *

# mail uid/gid.
mail_uid = ${VMAIL_USER_UID}
mail_gid = ${VMAIL_USER_GID}

#
# Debug options.
#
#mail_debug = yes
#auth_verbose = yes
#auth_debug = yes
#auth_debug_passwords = yes

#
# Log file.
#
#log_timestamp = "%Y-%m-%d %H:%M:%S "
log_path = ${DOVECOT_LOG_FILE}

#login_processes_count = 3
#login_max_processes_count = 128
#login_max_connections = 256
#max_mail_processes = 512

disable_plaintext_auth = no

# Performance Tuning. Reference:
# http://wiki.dovecot.org/LoginProcess
#
# High-Security mode. Dovecot default setting.
#
# It works by using a new imap-login or pop3-login process for each
# incoming connection. Since the processes run in a highly restricted
# chroot, running each connection in a separate process means that in
# case there is a security hole in Dovecot's pre-authentication code
# or in the SSL library, the attacker can't see other users'
# connections and can't really do anything destructive.
login_process_per_connection=yes

#
# High-Performance mode.
#
# It works by using a number of long running login processes,
# each handling a number of connections. This loses much of
# the security benefits of the login process design, because
# in case of a security hole the attacker is now able to see
# other users logging in and steal their passwords.
#login_process_per_connection = no

# Default realm/domain to use if none was specified.
# This is used for both SASL realms and appending '@domain.ltd' to username in plaintext logins.
auth_default_realm = ${FIRST_DOMAIN}

# ---- NFS storage ----
# Set to 'no' For NFSv2. Default is 'yes'.
#dotlock_use_excl = yes

#mail_nfs_storage = yes # v1.1+ only

# If indexes are on NFS.
#mail_nfs_index = yes # v1.1+ only
# ----

plugin {
# Quota warning.
#
# You can find sample script from Dovecot wiki:
# http://wiki.dovecot.org/Quota/1.1#head-03d8c4f6fb28e2e2f1cb63ec623810b45bec1734
#
# If user suddenly receives a huge mail and the quota jumps from
# 85% to 95%, only the 95% script is executed.
#
quota_warning = storage=85%% ${DOVECOT_QUOTA_WARNING_BIN} 85
quota_warning2 = storage=90%% ${DOVECOT_QUOTA_WARNING_BIN} 90
quota_warning3 = storage=95%% ${DOVECOT_QUOTA_WARNING_BIN} 95
}

EOF

# Generate dovecot quota warning script.
mkdir -p $(dirname ${DOVECOT_QUOTA_WARNING_BIN}) 2>/dev/null

backup_file ${DOVECOT_QUOTA_WARNING_BIN}
rm -rf ${DOVECOT_QUOTA_WARNING_BIN} 2>/dev/null

cat > ${DOVECOT_QUOTA_WARNING_BIN} <<FOE
#!/usr/bin/env bash
${CONF_MSG}

PERCENT=\${1}

cat << EOF | ${DOVECOT_DELIVER} -d \${USER} -c ${DOVECOT_CONF}
From: no-reply@${HOSTNAME}
Subject: Mailbox Quota Warning: \${PERCENT}% Full.

Your mailbox is now \${PERCENT}% full, please clean up some mails for
further incoming mails.

EOF
FOE

chown root ${DOVECOT_QUOTA_WARNING_BIN}
chmod 0755 ${DOVECOT_QUOTA_WARNING_BIN}

# Use '/usr/local/bin/bash' as shabang line, otherwise quota waning will be failed.
if [ X"${DISTRO}" == X"FREEBSD" ]; then
perl -pi -e 's#(.*)/usr/bin/env bash.*#${1}/usr/local/bin/bash#' ${DOVECOT_QUOTA_WARNING_BIN}
fi

# Enable SSL support.
[ X"${ENABLE_DOVECOT_SSL}" == X"YES" ] && dovecot_ssl_config

# Mailbox format.
if [ X"${MAILBOX_FORMAT}" == X"Maildir" ]; then
cat >> ${DOVECOT_CONF} <<EOF
# Maildir format and location.
# Such as: /var/mail/vmail01/iredmail.org/www/
# ----------- ================
# homeDirectory mailMessageStore
mail_location = maildir:/%Lh/Maildir/:INDEX=/%Lh/Maildir/

plugin {
quota = maildir

# Quota rules. Reference: http://wiki.dovecot.org/Quota/1.1
# The following limit names are supported:
# - storage: Quota limit in kilobytes, 0 means unlimited.
# - bytes: Quota limit in bytes, 0 means unlimited.
# - messages: Quota limit in number of messages, 0 means unlimited. This probably isn't very useful.
# - backend: Quota backend-specific limit configuration.
# - ignore: Don't include the specified mailbox in quota at all (v1.1.rc5+).
quota_rule = *:storage=100M
#quota_rule2 = *:messages=0
#quota_rule3 = Trash:storage=1G
#quota_rule4 = Junk:ignore
}

dict {
# NOTE: dict process currently runs as root, so this file will be owned as root.
expire = db:${DOVECOT_EXPIRE_DICT_BDB}
}

plugin {
# ---- Expire plugin ----
# Expire plugin. Mails are expunged from mailboxes after being there the
# configurable time. The first expiration date for each mailbox is stored in
# a dictionary so it can be quickly determined which mailboxes contain
# expired mails. The actual expunging is done in a nightly cronjob, which
# you must set up:
#
# 1 3 * * * ${DOVECOT_BIN} --exec-mail ext /usr/libexec/dovecot/expire-tool
#
# Trash: 7 days
# Trash's children directories: 7 days
# Junk: 30 days
expire = Trash 7 Trash/* 7 Junk 30
expire_dict = proxy::expire

# If you have a non-default path to auth-master, set also:
auth_socket_path = ${DOVECOT_SOCKET_MASTER}
}

# Per-user sieve mail filter.
plugin {
# For maildir format.
sieve = ${SIEVE_DIR}/%Ld/%Ln/${SIEVE_RULE_FILENAME}
}
EOF
elif [ X"${MAILBOX_FORMAT}" == X"mbox" ]; then
cat >> ${DOVECOT_CONF} <<EOF
# Mailbox format and location.
# Such as: /var/mail/vmail01/iredmail.org/www
# ----------- ====================
# homeDirectory mailMessageStore
mail_location = mbox:/%Lh/:INBOX=/%Lh/inbox:INDEX=/%Lh/indexes

# mbox performance optimizations.
mbox_lazy_writes=yes
mbox_min_index_size=10240
mbox_very_dirty_syncs = yes
mbox_read_locks = fcntl
mbox_write_locks = dotlock fcntl

plugin {
quota = dirsize

# Quota rules.
quota_rule = *:storage=10M
#quota_rule2 = Trash:storage=100M
#quota_rule3 = Junk:ignore
}

# Per-user sieve mail filter.
plugin {
# For mbox format.
sieve = ${SIEVE_DIR}/%Ld/.%Ln${SIEVE_RULE_FILENAME}
}
EOF
else
:
fi

cat >> ${DOVECOT_CONF} <<EOF
# LDA: Local Deliver Agent
protocol lda {
postmaster_address = root
auth_socket_path = ${DOVECOT_SOCKET_MASTER}
#mail_plugins = ${DOVECOT_LDA_SIEVE_PLUGIN_NAME} quota expire
mail_plugins = ${DOVECOT_LDA_SIEVE_PLUGIN_NAME} quota
sieve_global_path = ${GLOBAL_SIEVE_FILE}
log_path = ${SIEVE_LOG_FILE}
}

# IMAP configuration
protocol imap {
#mail_plugins = quota imap_quota zlib expire
mail_plugins = quota imap_quota zlib

# number of connections per-user per-IP
#mail_max_userip_connections = 10
}

# POP3 configuration
protocol pop3 {
#mail_plugins = quota zlib expire
mail_plugins = quota zlib
pop3_uidl_format = %08Xu%08Xv
pop3_client_workarounds = outlook-no-nuls oe-ns-eoh
}

auth default {
mechanisms = plain login
user = ${VMAIL_USER_NAME}
EOF

if [ X"${BACKEND}" == X"OpenLDAP" ]; then
cat >> ${DOVECOT_CONF} <<EOF
passdb ldap {
args = ${DOVECOT_LDAP_CONF}
}
userdb ldap {
args = ${DOVECOT_LDAP_CONF}
}
EOF

backup_file ${DOVECOT_LDAP_CONF}
cat > ${DOVECOT_LDAP_CONF} <<EOF
${CONF_MSG}
hosts = ${LDAP_SERVER_HOST}:${LDAP_SERVER_PORT}
ldap_version = 3
auth_bind = yes
dn = ${LDAP_BINDDN}
dnpass = ${LDAP_BINDPW}
base = ${LDAP_BASEDN}
scope = subtree
deref = never
user_filter = (&(objectClass=${LDAP_OBJECTCLASS_MAILUSER})(${LDAP_ATTR_ACCOUNT_STATUS}=${LDAP_STATUS_ACTIVE})(${LDAP_ENABLED_SERVICE}=${LDAP_SERVICE_MAIL})(${LDAP_ENABLED_SERVICE}=%Ls%Lc)(${LDAP_ATTR_USER_RDN}=%u))
pass_filter = (&(objectClass=${LDAP_OBJECTCLASS_MAILUSER})(${LDAP_ATTR_ACCOUNT_STATUS}=${LDAP_STATUS_ACTIVE})(${LDAP_ENABLED_SERVICE}=${LDAP_SERVICE_MAIL})(${LDAP_ENABLED_SERVICE}=%Ls%Lc)(${LDAP_ATTR_USER_RDN}=%u))
pass_attrs = ${LDAP_ATTR_USER_PASSWD}=password
default_pass_scheme = CRYPT
EOF
# Maildir format.
[ X"${MAILBOX_FORMAT}" == X"Maildir" ] && cat >> ${DOVECOT_LDAP_CONF} <<EOF
user_attrs = ${LDAP_ATTR_USER_STORAGE_BASE_DIRECTORY}=home,mailMessageStore=mail=maildir:~/%\$/Maildir/,${LDAP_ATTR_USER_QUOTA}=quota_rule=*:bytes=%\$
EOF
[ X"${MAILBOX_FORMAT}" == X"mbox" ] && cat >> ${DOVECOT_LDAP_CONF} <<EOF
# sieve = /%Lh/%Ld/.%Ln${SIEVE_RULE_FILENAME}
user_attrs = ${LDAP_ATTR_USER_STORAGE_BASE_DIRECTORY}=home,mailMessageStore=mail=dirsize:~/%\$,${LDAP_ATTR_USER_QUOTA}=quota_rule=*:bytes=%\$
EOF
else
cat >> ${DOVECOT_CONF} <<EOF
passdb sql {
args = ${DOVECOT_MYSQL_CONF}
}
userdb sql {
args = ${DOVECOT_MYSQL_CONF}
}
EOF

backup_file ${DOVECOT_MYSQL_CONF}
cat > ${DOVECOT_MYSQL_CONF} <<EOF
driver = mysql
default_pass_scheme = CRYPT
connect = host=${MYSQL_SERVER} dbname=${VMAIL_DB} user=${MYSQL_BIND_USER} password=${MYSQL_BIND_PW}
password_query = SELECT password FROM mailbox WHERE username='%u' AND active='1'
EOF
# Maildir format.
[ X"${MAILBOX_FORMAT}" == X"Maildir" ] && cat >> ${DOVECOT_MYSQL_CONF} <<EOF
user_query = SELECT CONCAT(storagebasedirectory, '/', storagenode, '/', maildir) AS home, \
CONCAT('*:bytes=', quota*1048576) AS quota_rule \
FROM mailbox WHERE username='%u' \
AND active='1' AND enable%Ls%Lc='1'
EOF
[ X"${MAILBOX_FORMAT}" == X"mbox" ] && cat >> ${DOVECOT_MYSQL_CONF} <<EOF
user_query = SELECT CONCAT('mbox:', storagebasedirectory, '/', storagenode, '/', maildir, '/Maildir/') AS home, \
CONCAT('*:bytes=', quota*1048576) AS quota_rule, \
maildir FROM mailbox \
WHERE username='%u' \
AND active='1' \
AND enable%Ls='1'
EOF
fi

cat >> ${DOVECOT_CONF} <<EOF
socket listen {
master {
path = ${DOVECOT_SOCKET_MASTER}
mode = 0666
user = ${VMAIL_USER_NAME}
group = ${VMAIL_GROUP_NAME}
}
client {
path = ${DOVECOT_SOCKET_MUX}
mode = 0666
user = postfix
group = postfix
}
}
}
EOF

ECHO_INFO "Copy sample sieve global filter rule file: ${GLOBAL_SIEVE_FILE}.sample."
cp -f ${SAMPLE_DIR}/dovecot.sieve ${GLOBAL_SIEVE_FILE}.sample
chown ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME} ${GLOBAL_SIEVE_FILE}.sample
chmod 0500 ${GLOBAL_SIEVE_FILE}.sample

ECHO_INFO "Create dovecot log file: ${DOVECOT_LOG_FILE}, ${SIEVE_LOG_FILE}."
touch ${DOVECOT_LOG_FILE} ${SIEVE_LOG_FILE}
chown ${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME} ${DOVECOT_LOG_FILE} ${SIEVE_LOG_FILE}
chmod 0600 ${DOVECOT_LOG_FILE}

# Sieve log file must be world-writable.
chmod 0666 ${SIEVE_LOG_FILE}

ECHO_INFO "Enable dovecot SASL support in postfix: ${POSTFIX_FILE_MAIN_CF}."
postconf -e mailbox_command="${DOVECOT_DELIVER}"
postconf -e virtual_transport="${TRANSPORT}"
postconf -e dovecot_destination_recipient_limit='1'

postconf -e smtpd_sasl_type='dovecot'
# if postfix does *NOT* runs under in chroot env, smtpd_sasl_path
# should be '/var/spool/postfix/dovecot-auth'.
postconf -e smtpd_sasl_path='dovecot-auth'

ECHO_INFO "Create directory for Dovecot plugin: Expire."
dovecot_expire_dict_dir="$(dirname ${DOVECOT_EXPIRE_DICT_BDB})"
mkdir -p ${dovecot_expire_dict_dir} && \
chown -R ${DOVECOT_USER}:${DOVECOT_GROUP} ${dovecot_expire_dict_dir} && \
chmod -R 0750 ${dovecot_expire_dict_dir}

if [ X"${DISTRO}" == X"RHEL" ]; then
ECHO_INFO "Setting cronjob for Dovecot plugin: Expire."
cat >> ${CRON_SPOOL_DIR}/root <<EOF
${CONF_MSG}
#1 5 * * * ${DOVECOT_BIN} --exec-mail ext $(eval ${LIST_FILES_IN_PKG} dovecot | grep 'expire-tool$')
EOF
elif [ X"${DISTRO}" == X"UBUNTU" -o X"${DISTRO}" == X"DEBIAN" ]; then
:
else
:
fi

cat >> ${POSTFIX_FILE_MASTER_CF} <<EOF
# Use dovecot deliver program as LDA.
dovecot unix - n n - - pipe
flags=DRhu user=${VMAIL_USER_NAME}:${VMAIL_GROUP_NAME} argv=${DOVECOT_DELIVER} -f \${sender} -d \${user}@\${domain}
EOF

if [ X"${KERNEL_NAME}" == X"Linux" ]; then
ECHO_INFO "Setting logrotate for dovecot log file."
cat > ${DOVECOT_LOGROTATE_FILE} <<EOF
${CONF_MSG}
${DOVECOT_LOG_FILE} {
compress
weekly
rotate 10
create 0600 ${VMAIL_USER_NAME} ${VMAIL_GROUP_NAME}
missingok

# Use bzip2 for compress.
compresscmd $(which bzip2)
uncompresscmd $(which bunzip2)
compressoptions -9
compressext .bz2

postrotate
${SYSLOG_POSTROTATE_CMD}
endscript
}
EOF

cat > ${SIEVE_LOGROTATE_FILE} <<EOF
${CONF_MSG}
${SIEVE_LOG_FILE} {
compress
weekly
rotate 10
create 0666 ${VMAIL_USER_NAME} ${VMAIL_GROUP_NAME}
missingok
postrotate
${SYSLOG_POSTROTATE_CMD}
endscript
}
EOF
else
:
fi

cat >> ${TIP_FILE} <<EOF
Dovecot:
* Configuration files:
- ${DOVECOT_CONF}
* LDAP:
- ${DOVECOT_LDAP_CONF}
* MySQL:
- ${DOVECOT_MYSQL_CONF}
* RC script:
- ${DIR_RC_SCRIPTS}/dovecot
* Log files:
- ${DOVECOT_LOGROTATE_FILE}
- ${DOVECOT_LOG_FILE}
- ${SIEVE_LOG_FILE}
* See also:
- ${GLOBAL_SIEVE_FILE}

EOF

echo 'export status_enable_dovecot="DONE"' >> ${STATUS_FILE}
}

enable_dovecot()
{
if [ X"${ENABLE_DOVECOT}" == X"YES" ]; then
check_status_before_run dovecot_config
fi

# FreeBSD.
if [ X"${DISTRO}" == X"FREEBSD" ]; then
# It seems there's a bug in Dovecot port, it will try to invoke '/usr/lib/sendmail'
# to send vacation response which should be '/usr/sbin/mailwrapper'.
[ ! -e /usr/lib/sendmail ] && ln -s /usr/sbin/mailwrapper /usr/lib/sendmail 2>/dev/null

# Start dovecot when system start up.
cat >> /etc/rc.conf <<EOF
# Start dovecot IMAP/POP3 server.
dovecot_enable="YES"
EOF
fi

echo 'export status_enable_dovecot="DONE"' >> ${STATUS_FILE}
}

Change log

1d74136be2e6 by Zhang Huangbin on May 25, 2010   Diff
Fix dovecot transport to handle
recipient_delimiter in postfix.
Go to: 

Older revisions

9ce43efb25f7 by Zhang Huangbin on May 11, 2010   Diff
    * Don't allow to login with shadow
address. It may cause login failed due
      to duplicate ldap query result
(normal user, another normal user with
      shadow address).
aa066299a959 by Zhang Huangbin on May 11, 2010   Diff
Fix shabang line of dovecot quota
warning script. Thanks Alex Stanciu.
Fix mod_auth_mysql_another issue with
awstats. Thanks dbetts22@forum.
Fix incorrect php.ini sample file on
...
d76b35be66c0 by Zhang Huangbin on May 11, 2010   Diff
Remove 'expired >= NOW()' from SQL
query for performance.
All revisions of this file

File info

Size: 16318 bytes, 534 lines
Powered by Google Project Hosting